summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-11-16 21:21:32 -0500
committerirungentoo <irungentoo@gmail.com>2013-11-16 21:21:32 -0500
commita82ad576a286e2908c366d5de07f2d82e364d2c8 (patch)
tree216375bb84aba1af00b9f54bbf6175244e7e7057 /toxcore
parentd83abccf0ed7cb09b2070b7a68bca5b011f4d333 (diff)
Fixed build error on windows.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/network.c24
-rw-r--r--toxcore/network.h12
2 files changed, 24 insertions, 12 deletions
diff --git a/toxcore/network.c b/toxcore/network.c
index 0f96083c..e5a80254 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -278,7 +278,7 @@ void networking_registerhandler(Networking_Core *net, uint8_t byte, packet_handl
278void networking_poll(Networking_Core *net) 278void networking_poll(Networking_Core *net)
279{ 279{
280 unix_time_update(); 280 unix_time_update();
281 281
282 IP_Port ip_port; 282 IP_Port ip_port;
283 uint8_t data[MAX_UDP_PACKET_SIZE]; 283 uint8_t data[MAX_UDP_PACKET_SIZE];
284 uint32_t length; 284 uint32_t length;
@@ -373,13 +373,15 @@ int networking_wait_execute(uint8_t *data, uint16_t len, uint16_t milliseconds)
373 /* returns -1 on error, 0 on timeout, the socket on activity */ 373 /* returns -1 on error, 0 on timeout, the socket on activity */
374 int res = select(nfds, &readfds, &writefds, &exceptfds, &timeout); 374 int res = select(nfds, &readfds, &writefds, &exceptfds, &timeout);
375#ifdef LOGGING 375#ifdef LOGGING
376
376 /* only dump if not timeout */ 377 /* only dump if not timeout */
377 if (res) { 378 if (res) {
378 sprintf(logbuffer, "select(%d): %d (%d, %s) - %d %d %d\n", milliseconds, res, errno, 379 sprintf(logbuffer, "select(%d): %d (%d, %s) - %d %d %d\n", milliseconds, res, errno,
379 strerror(errno), FD_ISSET(s->sock, &readfds), FD_ISSET(s->sock, &writefds), 380 strerror(errno), FD_ISSET(s->sock, &readfds), FD_ISSET(s->sock, &writefds),
380 FD_ISSET(s->sock, &exceptfds)); 381 FD_ISSET(s->sock, &exceptfds));
381 loglog(logbuffer); 382 loglog(logbuffer);
382 } 383 }
384
383#endif 385#endif
384 386
385 if (FD_ISSET(s->sock, &writefds)) 387 if (FD_ISSET(s->sock, &writefds))
@@ -527,14 +529,14 @@ Networking_Core *new_networking(IP ip, uint16_t port)
527 } else 529 } else
528 return NULL; 530 return NULL;
529 531
530 if (ip.family == AF_INET6) 532 if (ip.family == AF_INET6) {
531 {
532 char ipv6only = 0; 533 char ipv6only = 0;
533 socklen_t optsize = sizeof(ipv6only); 534 socklen_t optsize = sizeof(ipv6only);
534#ifdef LOGGING 535#ifdef LOGGING
535 errno = 0; 536 errno = 0;
536#endif 537#endif
537 int res = getsockopt(temp->sock, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6only, &optsize); 538 int res = getsockopt(temp->sock, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6only, &optsize);
539
538 if ((res == 0) && (ipv6only == 0)) { 540 if ((res == 0) && (ipv6only == 0)) {
539#ifdef LOGGING 541#ifdef LOGGING
540 loglog("Dual-stack socket: enabled per default.\n"); 542 loglog("Dual-stack socket: enabled per default.\n");
@@ -542,6 +544,7 @@ Networking_Core *new_networking(IP ip, uint16_t port)
542 } else { 544 } else {
543 ipv6only = 0; 545 ipv6only = 0;
544#ifdef LOGGING 546#ifdef LOGGING
547
545 if (res < 0) { 548 if (res < 0) {
546 sprintf(logbuffer, "Dual-stack socket: Failed to query default. (%d, %s)\n", 549 sprintf(logbuffer, "Dual-stack socket: Failed to query default. (%d, %s)\n",
547 errno, strerror(errno)); 550 errno, strerror(errno));
@@ -551,8 +554,9 @@ Networking_Core *new_networking(IP ip, uint16_t port)
551 errno = 0; 554 errno = 0;
552 res = 555 res =
553#endif 556#endif
554 setsockopt(temp->sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&ipv6only, sizeof(ipv6only)); 557 setsockopt(temp->sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&ipv6only, sizeof(ipv6only));
555#ifdef LOGGING 558#ifdef LOGGING
559
556 if (res < 0) { 560 if (res < 0) {
557 sprintf(logbuffer, 561 sprintf(logbuffer,
558 "Dual-stack socket: Failed to enable, won't be able to receive from/send to IPv4 addresses. (%u, %s)\n", 562 "Dual-stack socket: Failed to enable, won't be able to receive from/send to IPv4 addresses. (%u, %s)\n",
@@ -560,6 +564,7 @@ Networking_Core *new_networking(IP ip, uint16_t port)
560 loglog(logbuffer); 564 loglog(logbuffer);
561 } else 565 } else
562 loglog("Dual-stack socket: Enabled successfully.\n"); 566 loglog("Dual-stack socket: Enabled successfully.\n");
567
563#endif 568#endif
564 } 569 }
565 570
@@ -607,8 +612,7 @@ Networking_Core *new_networking(IP ip, uint16_t port)
607 *portptr = htons(port_to_try); 612 *portptr = htons(port_to_try);
608 int tries, res; 613 int tries, res;
609 614
610 for (tries = TOX_PORTRANGE_FROM; tries <= TOX_PORTRANGE_TO; tries++) 615 for (tries = TOX_PORTRANGE_FROM; tries <= TOX_PORTRANGE_TO; tries++) {
611 {
612 res = bind(temp->sock, (struct sockaddr *)&addr, addrsize); 616 res = bind(temp->sock, (struct sockaddr *)&addr, addrsize);
613 617
614 if (!res) { 618 if (!res) {
@@ -674,11 +678,7 @@ int ip_equal(IP *a, IP *b)
674 if (a->family == AF_INET) 678 if (a->family == AF_INET)
675 return (a->ip4.in_addr.s_addr == b->ip4.in_addr.s_addr); 679 return (a->ip4.in_addr.s_addr == b->ip4.in_addr.s_addr);
676 else if (a->family == AF_INET6) 680 else if (a->family == AF_INET6)
677#ifdef WIN32
678 return IN6_ADDR_EQUAL(&a->ip6.in6_addr, &b->ip6.in6_addr);
679#else
680 return IN6_ARE_ADDR_EQUAL(&a->ip6.in6_addr, &b->ip6.in6_addr); 681 return IN6_ARE_ADDR_EQUAL(&a->ip6.in6_addr, &b->ip6.in6_addr);
681#endif
682 else 682 else
683 return 0; 683 return 0;
684 } 684 }
diff --git a/toxcore/network.h b/toxcore/network.h
index 8b9b8b2f..504a12af 100644
--- a/toxcore/network.h
+++ b/toxcore/network.h
@@ -43,6 +43,18 @@ typedef unsigned int sock_t;
43/* sa_family_t is the sockaddr_in / sockaddr_in6 family field */ 43/* sa_family_t is the sockaddr_in / sockaddr_in6 family field */
44typedef short sa_family_t; 44typedef short sa_family_t;
45 45
46#ifndef IN6_ARE_ADDR_EQUAL
47#ifdef IN6_ADDR_EQUAL
48#define IN6_ARE_ADDR_EQUAL(a,b) IN6_ADDR_EQUAL(a,b)
49#else
50#define IN6_ARE_ADDR_EQUAL(a,b) \
51 ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0]) \
52 && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1]) \
53 && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2]) \
54 && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
55#endif
56#endif
57
46#ifndef EWOULDBLOCK 58#ifndef EWOULDBLOCK
47#define EWOULDBLOCK WSAEWOULDBLOCK 59#define EWOULDBLOCK WSAEWOULDBLOCK
48#endif 60#endif