Revision 6f26b958 ml.c

View differences:

ml.c
651 651
		debug(" new @ id:%d\n",recv_id);
652 652
	} else {
653 653
		debug(" found @ id:%d\n",recv_id);
654
		memset(recvdatabuf[recv_id]->recvbuf, 0, recvdatabuf[recv_id]->bufsize); //msg_h->msg_length
654 655
	}
655 656

  
656 657
	if (msg_h->offset == 0)
......
1163 1164
	}
1164 1165
}
1165 1166

  
1166
/**************************** END OF INTERNALS ***********************/
1167
/**************************** END OF INTERNAL ***********************/
1168

  
1169
/**************************** MONL functions *************************/
1167 1170

  
1168 1171
void mlInit(bool recv_data_cb,struct timeval timeout_value,const int port,const char *ipaddr,const int stun_port,const char *stun_ipaddr,receive_localsocketID_cb local_socketID_cb,void *arg){
1169 1172

  
......
1236 1239

  
1237 1240
}
1238 1241

  
1242
void mlSetRecvTimeout(struct timeval timeout_value){
1243

  
1244
	recv_timeout = timeout_value;
1245

  
1246
}
1247

  
1248
int mlGetStandardTTL(socketID_handle socketID,uint8_t *ttl){
1249

  
1250
	return getTTL(socketfd, ttl);
1251

  
1252
}
1253

  
1254
socketID_handle mlGetLocalSocketID(int *errorstatus){
1255

  
1256
	if (NAT_traversal == false) {
1257
		*errorstatus = 2;
1258
		return NULL;
1259
	}
1260

  
1261
	*errorstatus = 0;
1262
	return &local_socketID;
1263

  
1264
}
1265

  
1266

  
1267
/**************************** END of MONL functions *************************/
1268

  
1269
/**************************** GENERAL functions *************************/
1270

  
1239 1271
void mlRegisterRecvConnectionCb(receive_connection_cb recv_conn_cb){
1240 1272

  
1241 1273
	if (recv_conn_cb == NULL)
......
1346 1378
		if (newKeepalive) setupKeepalive(con_id);
1347 1379
		// if so check if it is ready to use
1348 1380
		if (connectbuf[con_id]->status == READY) {
1349
				// if so use the callback immediateley
1381
				// if so use the callback immediately
1350 1382
				(connection_cb) (con_id, arg);
1351 1383

  
1352 1384
		// otherwise just write the connection cb and the arg pointer
......
1715 1747

  
1716 1748
}
1717 1749

  
1718
/* setter  */
1719
void mlSetStunServer(const int port,const char *ipaddr){
1720

  
1721
	stun_server.sin_family = AF_INET;
1722
	if (ipaddr == NULL)
1723
		stun_server.sin_addr.s_addr = htonl(INADDR_ANY);
1724
	else
1725
		stun_server.sin_addr.s_addr = resolve(ipaddr);
1726
	stun_server.sin_port = htons(port);
1727

  
1728
}
1729

  
1730
void mlSetRecvTimeout(struct timeval timeout_value){
1731

  
1732
	recv_timeout = timeout_value;
1733

  
1734
}
1735

  
1736
int mlGetStandardTTL(socketID_handle socketID,uint8_t *ttl){
1737

  
1738
	return getTTL(socketfd, ttl);
1739

  
1740
}
1741

  
1742
socketID_handle mlGetLocalSocketID(int *errorstatus){
1743

  
1744
	if (NAT_traversal == false) {
1745
		*errorstatus = 2;
1746
		return NULL;
1747
	}
1748

  
1749
	*errorstatus = 0;
1750
	return &local_socketID;
1751

  
1752
}
1753

  
1754
int mlGetExternalIP(char* external_addr){
1755

  
1756
	socketaddrgen udpgen;
1757
	struct sockaddr_in udpaddr;
1758

  
1759
	udpgen = local_socketID.external_addr;
1760
	udpaddr = udpgen.udpaddr;
1761

  
1762
	inet_ntop(AF_INET, &(udpaddr.sin_addr), external_addr,
1763
			INET_ADDRSTRLEN);
1764

  
1765
	if (external_addr == NULL) {
1766

  
1767
	return -1;
1768

  
1769
	} else {
1770

  
1771
	return 0;
1772

  
1773
	}
1774

  
1775
}
1776

  
1777 1750
int mlSocketIDToString(socketID_handle socketID,char* socketID_string, size_t len){
1778 1751

  
1779 1752
	char internal_addr[INET_ADDRSTRLEN];
......
1915 1888
		return connectbuf[ConnectionId]->pmtusize;
1916 1889
	return -1;
1917 1890
}
1891

  
1892
/**************************** END of GENERAL functions *************************/
1893

  
1894
/**************************** NAT functions *************************/
1895

  
1896
/* setter  */
1897
void mlSetStunServer(const int port,const char *ipaddr){
1898

  
1899
	stun_server.sin_family = AF_INET;
1900
	if (ipaddr == NULL)
1901
		stun_server.sin_addr.s_addr = htonl(INADDR_ANY);
1902
	else
1903
		stun_server.sin_addr.s_addr = resolve(ipaddr);
1904
	stun_server.sin_port = htons(port);
1905

  
1906
}
1907

  
1908
int mlGetExternalIP(char* external_addr){
1909

  
1910
	socketaddrgen udpgen;
1911
	struct sockaddr_in udpaddr;
1912

  
1913
	udpgen = local_socketID.external_addr;
1914
	udpaddr = udpgen.udpaddr;
1915

  
1916
	inet_ntop(AF_INET, &(udpaddr.sin_addr), external_addr,
1917
			INET_ADDRSTRLEN);
1918

  
1919
	if (external_addr == NULL) {
1920

  
1921
	return -1;
1922

  
1923
	} else {
1924

  
1925
	return 0;
1926

  
1927
	}
1928

  
1929
}
1930

  
1931
/**************************** END of NAT functions *************************/

Also available in: Unified diff