diff options
author | Coren[m] <Break@Ocean> | 2013-09-15 08:33:09 +0200 |
---|---|---|
committer | Coren[m] <Break@Ocean> | 2013-09-15 08:33:09 +0200 |
commit | 1e1782a952d1476d49c63fd1a3966e85eb3a09d4 (patch) | |
tree | 1e07af19df14b67496a8ee881ee60debe105919d /toxcore | |
parent | 2092b5d936acd1b69269ace0d22e862790ad57b3 (diff) |
ip_equal(): handle embedded v4 vs. native v4 as equal
network.c:
- ip_equal(): on IPv4 vs. IPv6, check if the IPv6 is an embedded IPv4 and if true, compare that
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/network.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/toxcore/network.c b/toxcore/network.c index 83081a49..44448f38 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -480,11 +480,24 @@ int ip_equal(IP *a, IP *b) | |||
480 | return 0; | 480 | return 0; |
481 | 481 | ||
482 | #ifdef TOX_ENABLE_IPV6 | 482 | #ifdef TOX_ENABLE_IPV6 |
483 | if (a->family == AF_INET) | 483 | /* same family */ |
484 | return (a->ip4.in_addr.s_addr == b->ip4.in_addr.s_addr); | 484 | if (a->family == b->family) { |
485 | 485 | if (a->family == AF_INET) | |
486 | if (a->family == AF_INET6) | 486 | return (a->ip4.in_addr.s_addr == b->ip4.in_addr.s_addr); |
487 | return IN6_ARE_ADDR_EQUAL(&a->ip6, &b->ip6); | 487 | else if (a->family == AF_INET6) |
488 | return IN6_ARE_ADDR_EQUAL(&a->ip6, &b->ip6); | ||
489 | else | ||
490 | return 0; | ||
491 | } | ||
492 | |||
493 | /* different family: check on the IPv6 one if it is the IPv4 one embedded */ | ||
494 | if ((a->family == AF_INET) && (b->family == AF_INET6)) { | ||
495 | if (IN6_IS_ADDR_V4COMPAT(&b->ip6)) | ||
496 | return (a->ip4.in_addr.s_addr == b->ip6.s6_addr32[3]); | ||
497 | } else if ((a->family == AF_INET6) && (b->family == AF_INET)) { | ||
498 | if (IN6_IS_ADDR_V4COMPAT(&a->ip6)) | ||
499 | return (a->ip6.s6_addr32[3] == b->ip4.in_addr.s_addr); | ||
500 | } | ||
488 | 501 | ||
489 | return 0; | 502 | return 0; |
490 | #else | 503 | #else |