diff options
Diffstat (limited to 'toxcore/network.c')
-rw-r--r-- | toxcore/network.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/toxcore/network.c b/toxcore/network.c index 0f96083c..d163c0eb 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -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) { |
@@ -676,6 +680,7 @@ int ip_equal(IP *a, IP *b) | |||
676 | else if (a->family == AF_INET6) | 680 | else if (a->family == AF_INET6) |
677 | #ifdef WIN32 | 681 | #ifdef WIN32 |
678 | return IN6_ADDR_EQUAL(&a->ip6.in6_addr, &b->ip6.in6_addr); | 682 | return IN6_ADDR_EQUAL(&a->ip6.in6_addr, &b->ip6.in6_addr); |
683 | |||
679 | #else | 684 | #else |
680 | return IN6_ARE_ADDR_EQUAL(&a->ip6.in6_addr, &b->ip6.in6_addr); | 685 | return IN6_ARE_ADDR_EQUAL(&a->ip6.in6_addr, &b->ip6.in6_addr); |
681 | #endif | 686 | #endif |