Revision fa36520f ml/ml.c

View differences:

ml/ml.c
288 288

  
289 289
#endif
290 290

  
291
/*
292
 * compare the external IP address of two socketIDs
293
 */
294
bool compare_address(struct sockaddr_in *sock1, struct sockaddr_in *sock2, int netmaskbits, bool port)
295
{
296
	int i;
297
	uint32_t mask = 0;
291 298

  
299
	for (i = 0; i < netmaskbits; i ++) {
300
		mask += 1<<i;
301
	}
302
	mask = htonl(mask);
303

  
304
	return ((sock1->sin_addr.s_addr | mask )  == (sock2->sin_addr.s_addr | mask)) &&
305
	       (!port || (sock1->sin_port == sock2->sin_port) );
306
}
307

  
308
/*
309
 * decide whether it is worth trying to connect with internal connect
310
 */
311
bool internal_connect_plausible(socketID_handle sock1, socketID_handle sock2)
312
{
313
	return compare_address (&sock1->external_addr.udpaddr, &sock2->external_addr.udpaddr, 0, false);
314
}
292 315

  
293 316
/*
294 317
 * convert a socketID to a string. It uses a static buffer, so either strdup is needed, or the string will get lost!
......
642 665
				connectbuf[free_con_id]->timeout_event = NULL;
643 666
				connectbuf[free_con_id]->external_connectionID = msg_h->local_con_id;
644 667
				connectbuf[free_con_id]->internal_connect =
645
					!compare_external_address_socketIDs(&(con_msg->sock_id), loc_socketID);
668
					internal_connect_plausible(&(con_msg->sock_id), loc_socketID);
646 669
				con_id = free_con_id;
647 670
			}
648 671

  
......
1431 1454
	}
1432 1455
}
1433 1456

  
1434
/*
1435
 * compare the external IP address of two socketIDs
1436
 */
1437
int
1438
compare_external_address_socketIDs(socketID_handle sock1, socketID_handle sock2)
1439
{
1440
	if( sock1->external_addr.udpaddr.sin_addr.s_addr == sock2->external_addr.udpaddr.sin_addr.s_addr)
1441
		return 0;
1442
	return 1;
1443
}
1444 1457

  
1445 1458
void try_stun();
1446 1459

  
......
1809 1822
			connectbuf[con_id]->timeout_event = NULL;
1810 1823
			connectbuf[con_id]->status = INVITE;
1811 1824
			connectbuf[con_id]->seqnr = 0;
1812
			connectbuf[con_id]->internal_connect = !compare_external_address_socketIDs(external_socketID, &local_socketID);
1825
			connectbuf[con_id]->internal_connect = internal_connect_plausible(external_socketID, &local_socketID);
1813 1826
			connectbuf[con_id]->connectionID = con_id;
1814 1827

  
1815 1828
			connectbuf[con_id]->connection_head = connectbuf[con_id]->connection_last = malloc(sizeof(struct receive_connection_cb_list));

Also available in: Unified diff