diff options
Diffstat (limited to 'toxcore/network.c')
-rw-r--r-- | toxcore/network.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/toxcore/network.c b/toxcore/network.c index 53511df6..640311b3 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -20,10 +20,10 @@ | |||
20 | * along with Tox. If not, see <http://www.gnu.org/licenses/>. | 20 | * along with Tox. If not, see <http://www.gnu.org/licenses/>. |
21 | * | 21 | * |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #if (_WIN32_WINNT >= _WIN32_WINNT_WINXP) | 24 | #if (_WIN32_WINNT >= _WIN32_WINNT_WINXP) |
25 | #define _WIN32_WINNT 0x501 | 25 | #define _WIN32_WINNT 0x501 |
26 | #endif | 26 | #endif |
27 | 27 | ||
28 | #ifdef HAVE_CONFIG_H | 28 | #ifdef HAVE_CONFIG_H |
29 | #include "config.h" | 29 | #include "config.h" |
@@ -371,13 +371,15 @@ int networking_wait_execute(uint8_t *data, uint16_t len, uint16_t milliseconds) | |||
371 | /* returns -1 on error, 0 on timeout, the socket on activity */ | 371 | /* returns -1 on error, 0 on timeout, the socket on activity */ |
372 | int res = select(nfds, &readfds, &writefds, &exceptfds, &timeout); | 372 | int res = select(nfds, &readfds, &writefds, &exceptfds, &timeout); |
373 | #ifdef LOGGING | 373 | #ifdef LOGGING |
374 | |||
374 | /* only dump if not timeout */ | 375 | /* only dump if not timeout */ |
375 | if (res) { | 376 | if (res) { |
376 | sprintf(logbuffer, "select(%d): %d (%d, %s) - %d %d %d\n", milliseconds, res, errno, | 377 | sprintf(logbuffer, "select(%d): %d (%d, %s) - %d %d %d\n", milliseconds, res, errno, |
377 | strerror(errno), FD_ISSET(s->sock, &readfds), FD_ISSET(s->sock, &writefds), | 378 | strerror(errno), FD_ISSET(s->sock, &readfds), FD_ISSET(s->sock, &writefds), |
378 | FD_ISSET(s->sock, &exceptfds)); | 379 | FD_ISSET(s->sock, &exceptfds)); |
379 | loglog(logbuffer); | 380 | loglog(logbuffer); |
380 | } | 381 | } |
382 | |||
381 | #endif | 383 | #endif |
382 | 384 | ||
383 | if (FD_ISSET(s->sock, &writefds)) | 385 | if (FD_ISSET(s->sock, &writefds)) |
@@ -525,14 +527,14 @@ Networking_Core *new_networking(IP ip, uint16_t port) | |||
525 | } else | 527 | } else |
526 | return NULL; | 528 | return NULL; |
527 | 529 | ||
528 | if (ip.family == AF_INET6) | 530 | if (ip.family == AF_INET6) { |
529 | { | ||
530 | char ipv6only = 0; | 531 | char ipv6only = 0; |
531 | socklen_t optsize = sizeof(ipv6only); | 532 | socklen_t optsize = sizeof(ipv6only); |
532 | #ifdef LOGGING | 533 | #ifdef LOGGING |
533 | errno = 0; | 534 | errno = 0; |
534 | #endif | 535 | #endif |
535 | int res = getsockopt(temp->sock, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6only, &optsize); | 536 | int res = getsockopt(temp->sock, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6only, &optsize); |
537 | |||
536 | if ((res == 0) && (ipv6only == 0)) { | 538 | if ((res == 0) && (ipv6only == 0)) { |
537 | #ifdef LOGGING | 539 | #ifdef LOGGING |
538 | loglog("Dual-stack socket: enabled per default.\n"); | 540 | loglog("Dual-stack socket: enabled per default.\n"); |
@@ -540,6 +542,7 @@ Networking_Core *new_networking(IP ip, uint16_t port) | |||
540 | } else { | 542 | } else { |
541 | ipv6only = 0; | 543 | ipv6only = 0; |
542 | #ifdef LOGGING | 544 | #ifdef LOGGING |
545 | |||
543 | if (res < 0) { | 546 | if (res < 0) { |
544 | sprintf(logbuffer, "Dual-stack socket: Failed to query default. (%d, %s)\n", | 547 | sprintf(logbuffer, "Dual-stack socket: Failed to query default. (%d, %s)\n", |
545 | errno, strerror(errno)); | 548 | errno, strerror(errno)); |
@@ -549,8 +552,9 @@ Networking_Core *new_networking(IP ip, uint16_t port) | |||
549 | errno = 0; | 552 | errno = 0; |
550 | res = | 553 | res = |
551 | #endif | 554 | #endif |
552 | setsockopt(temp->sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&ipv6only, sizeof(ipv6only)); | 555 | setsockopt(temp->sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&ipv6only, sizeof(ipv6only)); |
553 | #ifdef LOGGING | 556 | #ifdef LOGGING |
557 | |||
554 | if (res < 0) { | 558 | if (res < 0) { |
555 | sprintf(logbuffer, | 559 | sprintf(logbuffer, |
556 | "Dual-stack socket: Failed to enable, won't be able to receive from/send to IPv4 addresses. (%u, %s)\n", | 560 | "Dual-stack socket: Failed to enable, won't be able to receive from/send to IPv4 addresses. (%u, %s)\n", |
@@ -558,6 +562,7 @@ Networking_Core *new_networking(IP ip, uint16_t port) | |||
558 | loglog(logbuffer); | 562 | loglog(logbuffer); |
559 | } else | 563 | } else |
560 | loglog("Dual-stack socket: Enabled successfully.\n"); | 564 | loglog("Dual-stack socket: Enabled successfully.\n"); |
565 | |||
561 | #endif | 566 | #endif |
562 | } | 567 | } |
563 | 568 | ||
@@ -605,8 +610,7 @@ Networking_Core *new_networking(IP ip, uint16_t port) | |||
605 | *portptr = htons(port_to_try); | 610 | *portptr = htons(port_to_try); |
606 | int tries, res; | 611 | int tries, res; |
607 | 612 | ||
608 | for (tries = TOX_PORTRANGE_FROM; tries <= TOX_PORTRANGE_TO; tries++) | 613 | for (tries = TOX_PORTRANGE_FROM; tries <= TOX_PORTRANGE_TO; tries++) { |
609 | { | ||
610 | res = bind(temp->sock, (struct sockaddr *)&addr, addrsize); | 614 | res = bind(temp->sock, (struct sockaddr *)&addr, addrsize); |
611 | 615 | ||
612 | if (!res) { | 616 | if (!res) { |
@@ -674,6 +678,7 @@ int ip_equal(IP *a, IP *b) | |||
674 | else if (a->family == AF_INET6) | 678 | else if (a->family == AF_INET6) |
675 | #ifdef WIN32 | 679 | #ifdef WIN32 |
676 | return IN6_ADDR_EQUAL(&a->ip6.in6_addr, &b->ip6.in6_addr); | 680 | return IN6_ADDR_EQUAL(&a->ip6.in6_addr, &b->ip6.in6_addr); |
681 | |||
677 | #else | 682 | #else |
678 | return IN6_ARE_ADDR_EQUAL(&a->ip6.in6_addr, &b->ip6.in6_addr); | 683 | return IN6_ARE_ADDR_EQUAL(&a->ip6.in6_addr, &b->ip6.in6_addr); |
679 | #endif | 684 | #endif |