summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toxcore/DHT.c4
-rw-r--r--toxcore/LAN_discovery.c4
-rw-r--r--toxcore/network.c8
-rw-r--r--toxcore/network.h2
4 files changed, 9 insertions, 9 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 102abe06..fed12861 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -830,7 +830,7 @@ int addto_lists(DHT *dht, IP_Port ip_port, uint8_t *client_id)
830 uint32_t i, used = 0; 830 uint32_t i, used = 0;
831 831
832 /* convert IPv4-in-IPv6 to IPv4 */ 832 /* convert IPv4-in-IPv6 to IPv4 */
833 if ((ip_port.ip.family == AF_INET6) && IN6_IS_ADDR_V4MAPPED(&ip_port.ip.ip6.in6_addr)) { 833 if ((ip_port.ip.family == AF_INET6) && IPV6_IPV4_IN_V6(ip_port.ip.ip6)) {
834 ip_port.ip.family = AF_INET; 834 ip_port.ip.family = AF_INET;
835 ip_port.ip.ip4.uint32 = ip_port.ip.ip6.uint32[3]; 835 ip_port.ip.ip4.uint32 = ip_port.ip.ip6.uint32[3];
836 } 836 }
@@ -900,7 +900,7 @@ static int returnedip_ports(DHT *dht, IP_Port ip_port, uint8_t *client_id, uint8
900 uint32_t used = 0; 900 uint32_t used = 0;
901 901
902 /* convert IPv4-in-IPv6 to IPv4 */ 902 /* convert IPv4-in-IPv6 to IPv4 */
903 if ((ip_port.ip.family == AF_INET6) && IN6_IS_ADDR_V4MAPPED(&ip_port.ip.ip6.in6_addr)) { 903 if ((ip_port.ip.family == AF_INET6) && IPV6_IPV4_IN_V6(ip_port.ip.ip6)) {
904 ip_port.ip.family = AF_INET; 904 ip_port.ip.family = AF_INET;
905 ip_port.ip.ip4.uint32 = ip_port.ip.ip6.uint32[3]; 905 ip_port.ip.ip4.uint32 = ip_port.ip.ip6.uint32[3];
906 } 906 }
diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c
index 9d1f055e..2deeadfd 100644
--- a/toxcore/LAN_discovery.c
+++ b/toxcore/LAN_discovery.c
@@ -192,7 +192,7 @@ int LAN_ip(IP ip)
192 return 0; 192 return 0;
193 193
194 /* embedded IPv4-in-IPv6 */ 194 /* embedded IPv4-in-IPv6 */
195 if (IN6_IS_ADDR_V4MAPPED(&ip.ip6.in6_addr)) { 195 if (IPV6_IPV4_IN_V6(ip.ip6)) {
196 IP ip4; 196 IP ip4;
197 ip4.family = AF_INET; 197 ip4.family = AF_INET;
198 ip4.ip4.uint32 = ip.ip6.uint32[3]; 198 ip4.ip4.uint32 = ip.ip6.uint32[3];
@@ -200,7 +200,7 @@ int LAN_ip(IP ip)
200 } 200 }
201 201
202 /* localhost in IPv6 (::1) */ 202 /* localhost in IPv6 (::1) */
203 if (IN6_IS_ADDR_LOOPBACK(&ip.ip6.in6_addr)) 203 if (ip.ip6.uint64[0] == 0 && ip.ip6.uint32[2] == 0 && ip.ip6.uint32[3] == htonl(1))
204 return 0; 204 return 0;
205 } 205 }
206 206
diff --git a/toxcore/network.c b/toxcore/network.c
index 647940c3..b71c6ba9 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -386,7 +386,7 @@ static int receivepacket(sock_t sock, IP_Port *ip_port, uint8_t *data, uint32_t
386 ip_port->ip.ip6.in6_addr = addr_in6->sin6_addr; 386 ip_port->ip.ip6.in6_addr = addr_in6->sin6_addr;
387 ip_port->port = addr_in6->sin6_port; 387 ip_port->port = addr_in6->sin6_port;
388 388
389 if (IN6_IS_ADDR_V4MAPPED(&ip_port->ip.ip6.in6_addr)) { 389 if (IPV6_IPV4_IN_V6(ip_port->ip.ip6)) {
390 ip_port->ip.family = AF_INET; 390 ip_port->ip.family = AF_INET;
391 ip_port->ip.ip4.uint32 = ip_port->ip.ip6.uint32[3]; 391 ip_port->ip.ip4.uint32 = ip_port->ip.ip6.uint32[3];
392 } 392 }
@@ -451,8 +451,6 @@ int networking_at_startup(void)
451 if (WSAStartup(MAKEWORD(2, 2), &wsaData) != NO_ERROR) 451 if (WSAStartup(MAKEWORD(2, 2), &wsaData) != NO_ERROR)
452 return -1; 452 return -1;
453 453
454#else
455 srandom((uint32_t)current_time_actual());
456#endif 454#endif
457 srand((uint32_t)current_time_actual()); 455 srand((uint32_t)current_time_actual());
458 at_startup_ran = 1; 456 at_startup_ran = 1;
@@ -665,10 +663,10 @@ int ip_equal(IP *a, IP *b)
665 663
666 /* different family: check on the IPv6 one if it is the IPv4 one embedded */ 664 /* different family: check on the IPv6 one if it is the IPv4 one embedded */
667 if ((a->family == AF_INET) && (b->family == AF_INET6)) { 665 if ((a->family == AF_INET) && (b->family == AF_INET6)) {
668 if (IN6_IS_ADDR_V4MAPPED(&b->ip6.in6_addr)) 666 if (IPV6_IPV4_IN_V6(b->ip6))
669 return (a->ip4.in_addr.s_addr == b->ip6.uint32[3]); 667 return (a->ip4.in_addr.s_addr == b->ip6.uint32[3]);
670 } else if ((a->family == AF_INET6) && (b->family == AF_INET)) { 668 } else if ((a->family == AF_INET6) && (b->family == AF_INET)) {
671 if (IN6_IS_ADDR_V4MAPPED(&a->ip6.in6_addr)) 669 if (IPV6_IPV4_IN_V6(a->ip6))
672 return (a->ip6.uint32[3] == b->ip4.in_addr.s_addr); 670 return (a->ip6.uint32[3] == b->ip4.in_addr.s_addr);
673 } 671 }
674 672
diff --git a/toxcore/network.h b/toxcore/network.h
index bf14f319..e33e111f 100644
--- a/toxcore/network.h
+++ b/toxcore/network.h
@@ -174,6 +174,8 @@ typedef struct __attribute__ ((__packed__)) __attribute__((gcc_struct))
174} 174}
175IP_Port; 175IP_Port;
176 176
177/* Does the IP6 struct a contain an IPv4 address in an IPv6 one? */
178#define IPV6_IPV4_IN_V6(a) ((a.uint64[0] == 0) && (a.uint32[2] == htonl (0xffff)))
177 179
178#define SIZE_IP4 4 180#define SIZE_IP4 4
179#define SIZE_IP6 16 181#define SIZE_IP6 16