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
This commit is contained in:
Coren[m] 2013-09-15 08:33:09 +02:00
parent 2092b5d936
commit 1e1782a952

View File

@ -480,11 +480,24 @@ int ip_equal(IP *a, IP *b)
return 0;
#ifdef TOX_ENABLE_IPV6
if (a->family == AF_INET)
return (a->ip4.in_addr.s_addr == b->ip4.in_addr.s_addr);
/* same family */
if (a->family == b->family) {
if (a->family == AF_INET)
return (a->ip4.in_addr.s_addr == b->ip4.in_addr.s_addr);
else if (a->family == AF_INET6)
return IN6_ARE_ADDR_EQUAL(&a->ip6, &b->ip6);
else
return 0;
}
if (a->family == AF_INET6)
return IN6_ARE_ADDR_EQUAL(&a->ip6, &b->ip6);
/* different family: check on the IPv6 one if it is the IPv4 one embedded */
if ((a->family == AF_INET) && (b->family == AF_INET6)) {
if (IN6_IS_ADDR_V4COMPAT(&b->ip6))
return (a->ip4.in_addr.s_addr == b->ip6.s6_addr32[3]);
} else if ((a->family == AF_INET6) && (b->family == AF_INET)) {
if (IN6_IS_ADDR_V4COMPAT(&a->ip6))
return (a->ip6.s6_addr32[3] == b->ip4.in_addr.s_addr);
}
return 0;
#else