From a128e3ff8f09250757ed4ed73fcc088cb5fd15ee Mon Sep 17 00:00:00 2001 From: "Coren[m]" Date: Mon, 9 Sep 2013 13:56:03 +0200 Subject: network.h: - global: added sock_t - Networking_Core: added family (currently always AF_INET) and port - sendpacket(): changed signature to require (Networking_Core *) instead of sock_t *.c: - sendpacket()-calls: replaced *->net->sock with *->net --- toxcore/network.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'toxcore/network.c') diff --git a/toxcore/network.c b/toxcore/network.c index ed3dff8a..53b7e3b5 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -64,14 +64,10 @@ uint32_t random_int(void) /* Basic network functions: * Function to send packet(data) of length length to ip_port. */ -#ifdef WIN32 -int sendpacket(unsigned int sock, IP_Port ip_port, uint8_t *data, uint32_t length) -#else -int sendpacket(int sock, IP_Port ip_port, uint8_t *data, uint32_t length) -#endif +int sendpacket(Networking_Core *net, IP_Port ip_port, uint8_t *data, uint32_t length) { ADDR addr = {AF_INET, ip_port.port, ip_port.ip, {0}}; - return sendto(sock, (char *) data, length, 0, (struct sockaddr *)&addr, sizeof(addr)); + return sendto(net->sock, (char *) data, length, 0, (struct sockaddr *)&addr, sizeof(addr)); } /* Function to receive data @@ -171,7 +167,8 @@ Networking_Core *new_networking(IP ip, uint16_t port) if (temp == NULL) return NULL; - temp->sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + temp->family = AF_INET; + temp->sock = socket(temp->family, SOCK_DGRAM, IPPROTO_UDP); /* Check for socket error. */ #ifdef WIN32 @@ -219,8 +216,10 @@ Networking_Core *new_networking(IP ip, uint16_t port) #endif /* Bind our socket to port PORT and address 0.0.0.0 */ - ADDR addr = {AF_INET, htons(port), ip, {0}}; - bind(temp->sock, (struct sockaddr *)&addr, sizeof(addr)); + ADDR addr = {temp->family, htons(port), ip, {0}}; + if (!bind(temp->sock, (struct sockaddr *)&addr, sizeof(addr))) + temp->port = port; + return temp; } -- cgit v1.2.3