summaryrefslogtreecommitdiff
path: root/toxcore/network.c
diff options
context:
space:
mode:
authorCoren[m] <Break@Ocean>2013-09-09 13:56:03 +0200
committerCoren[m] <Break@Ocean>2013-09-09 13:56:03 +0200
commita128e3ff8f09250757ed4ed73fcc088cb5fd15ee (patch)
treecfbf03fa229ad21445a050b3041d208d5cb30196 /toxcore/network.c
parent0d41d7f9c05a753c54cc7a3f2535d20ae3f5aaf4 (diff)
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
Diffstat (limited to 'toxcore/network.c')
-rw-r--r--toxcore/network.c17
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 67int sendpacket(Networking_Core *net, IP_Port ip_port, uint8_t *data, uint32_t length)
68int sendpacket(unsigned int sock, IP_Port ip_port, uint8_t *data, uint32_t length)
69#else
70int 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