summaryrefslogtreecommitdiff
path: root/toxcore/network.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/network.c')
-rw-r--r--toxcore/network.c24
1 files changed, 12 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 }