diff options
Diffstat (limited to 'toxcore/network.c')
-rw-r--r-- | toxcore/network.c | 17 |
1 files changed, 8 insertions, 9 deletions
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) | |||
64 | /* Basic network functions: | 64 | /* Basic network functions: |
65 | * Function to send packet(data) of length length to ip_port. | 65 | * Function to send packet(data) of length length to ip_port. |
66 | */ | 66 | */ |
67 | #ifdef WIN32 | 67 | int sendpacket(Networking_Core *net, IP_Port ip_port, uint8_t *data, uint32_t length) |
68 | int sendpacket(unsigned int sock, IP_Port ip_port, uint8_t *data, uint32_t length) | ||
69 | #else | ||
70 | int sendpacket(int sock, IP_Port ip_port, uint8_t *data, uint32_t length) | ||
71 | #endif | ||
72 | { | 68 | { |
73 | ADDR addr = {AF_INET, ip_port.port, ip_port.ip, {0}}; | 69 | ADDR addr = {AF_INET, ip_port.port, ip_port.ip, {0}}; |
74 | return sendto(sock, (char *) data, length, 0, (struct sockaddr *)&addr, sizeof(addr)); | 70 | return sendto(net->sock, (char *) data, length, 0, (struct sockaddr *)&addr, sizeof(addr)); |
75 | } | 71 | } |
76 | 72 | ||
77 | /* Function to receive data | 73 | /* Function to receive data |
@@ -171,7 +167,8 @@ Networking_Core *new_networking(IP ip, uint16_t port) | |||
171 | if (temp == NULL) | 167 | if (temp == NULL) |
172 | return NULL; | 168 | return NULL; |
173 | 169 | ||
174 | temp->sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); | 170 | temp->family = AF_INET; |
171 | temp->sock = socket(temp->family, SOCK_DGRAM, IPPROTO_UDP); | ||
175 | 172 | ||
176 | /* Check for socket error. */ | 173 | /* Check for socket error. */ |
177 | #ifdef WIN32 | 174 | #ifdef WIN32 |
@@ -219,8 +216,10 @@ Networking_Core *new_networking(IP ip, uint16_t port) | |||
219 | #endif | 216 | #endif |
220 | 217 | ||
221 | /* Bind our socket to port PORT and address 0.0.0.0 */ | 218 | /* Bind our socket to port PORT and address 0.0.0.0 */ |
222 | ADDR addr = {AF_INET, htons(port), ip, {0}}; | 219 | ADDR addr = {temp->family, htons(port), ip, {0}}; |
223 | bind(temp->sock, (struct sockaddr *)&addr, sizeof(addr)); | 220 | if (!bind(temp->sock, (struct sockaddr *)&addr, sizeof(addr))) |
221 | temp->port = port; | ||
222 | |||
224 | return temp; | 223 | return temp; |
225 | } | 224 | } |
226 | 225 | ||