diff options
author | irungentoo <irungentoo@gmail.com> | 2013-09-15 09:31:46 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-09-15 09:31:46 -0400 |
commit | fca574a0e05fbaecf1ef20f3ae8d261d1fb0474d (patch) | |
tree | f387a5cf526a0cd1fef3878340f985593288b706 | |
parent | 8c41244627528ba35dc122ed166cc664fee8c4de (diff) | |
parent | f447027d9db569512ebae068e5a425dfe1905c47 (diff) |
Merge branch 'master' of https://github.com/irungentoo/ProjectTox-Core
-rw-r--r-- | toxcore/network.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/toxcore/network.c b/toxcore/network.c index e32e9a4c..da826a7f 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -502,12 +502,24 @@ int ip_equal(IP *a, IP *b) | |||
502 | return 0; | 502 | return 0; |
503 | 503 | ||
504 | #ifdef TOX_ENABLE_IPV6 | 504 | #ifdef TOX_ENABLE_IPV6 |
505 | /* same family */ | ||
506 | if (a->family == b->family) { | ||
507 | if (a->family == AF_INET) | ||
508 | return (a->ip4.in_addr.s_addr == b->ip4.in_addr.s_addr); | ||
509 | else if (a->family == AF_INET6) | ||
510 | return IN6_ARE_ADDR_EQUAL(&a->ip6, &b->ip6); | ||
511 | else | ||
512 | return 0; | ||
513 | } | ||
505 | 514 | ||
506 | if (a->family == AF_INET) | 515 | /* different family: check on the IPv6 one if it is the IPv4 one embedded */ |
507 | return (a->ip4.in_addr.s_addr == b->ip4.in_addr.s_addr); | 516 | if ((a->family == AF_INET) && (b->family == AF_INET6)) { |
508 | 517 | if (IN6_IS_ADDR_V4COMPAT(&b->ip6)) | |
509 | if (a->family == AF_INET6) | 518 | return (a->ip4.in_addr.s_addr == b->ip6.s6_addr32[3]); |
510 | return IN6_ARE_ADDR_EQUAL(&a->ip6, &b->ip6); | 519 | } else if ((a->family == AF_INET6) && (b->family == AF_INET)) { |
520 | if (IN6_IS_ADDR_V4COMPAT(&a->ip6)) | ||
521 | return (a->ip6.s6_addr32[3] == b->ip4.in_addr.s_addr); | ||
522 | } | ||
511 | 523 | ||
512 | return 0; | 524 | return 0; |
513 | #else | 525 | #else |
@@ -748,7 +760,7 @@ int addr_resolve(const char *address, IP *to, IP *extra) | |||
748 | for (walker = server; (walker != NULL) && (rc != 3); walker = walker->ai_next) { | 760 | for (walker = server; (walker != NULL) && (rc != 3); walker = walker->ai_next) { |
749 | switch (walker->ai_family) { | 761 | switch (walker->ai_family) { |
750 | case AF_INET: | 762 | case AF_INET: |
751 | if (walker->ai_family == family) { | 763 | if (walker->ai_family == family) { /* AF_INET requested, done */ |
752 | struct sockaddr_in *addr = (struct sockaddr_in *)walker->ai_addr; | 764 | struct sockaddr_in *addr = (struct sockaddr_in *)walker->ai_addr; |
753 | #ifdef TOX_ENABLE_IPV6 | 765 | #ifdef TOX_ENABLE_IPV6 |
754 | to->ip4.in_addr = addr->sin_addr; | 766 | to->ip4.in_addr = addr->sin_addr; |
@@ -759,24 +771,23 @@ int addr_resolve(const char *address, IP *to, IP *extra) | |||
759 | } | 771 | } |
760 | 772 | ||
761 | #ifdef TOX_ENABLE_IPV6 | 773 | #ifdef TOX_ENABLE_IPV6 |
762 | else if (!(rc & 1)) { | 774 | else if (!(rc & 1)) { /* AF_UNSPEC requested, store away */ |
763 | struct sockaddr_in *addr = (struct sockaddr_in *)walker->ai_addr; | 775 | struct sockaddr_in *addr = (struct sockaddr_in *)walker->ai_addr; |
764 | to->ip4.in_addr = addr->sin_addr; | 776 | ip4.in_addr = addr->sin_addr; |
765 | rc |= 1; | 777 | rc |= 1; |
766 | } | 778 | } |
767 | |||
768 | #endif | 779 | #endif |
769 | break; /* switch */ | 780 | break; /* switch */ |
770 | #ifdef TOX_ENABLE_IPV6 | 781 | #ifdef TOX_ENABLE_IPV6 |
771 | 782 | ||
772 | case AF_INET6: | 783 | case AF_INET6: |
773 | if (walker->ai_family == family) { | 784 | if (walker->ai_family == family) { /* AF_INET6 requested, done */ |
774 | if (walker->ai_addrlen == sizeof(struct sockaddr_in6)) { | 785 | if (walker->ai_addrlen == sizeof(struct sockaddr_in6)) { |
775 | struct sockaddr_in6 *addr = (struct sockaddr_in6 *)walker->ai_addr; | 786 | struct sockaddr_in6 *addr = (struct sockaddr_in6 *)walker->ai_addr; |
776 | to->ip6.in6_addr = addr->sin6_addr; | 787 | to->ip6.in6_addr = addr->sin6_addr; |
777 | rc = 3; | 788 | rc = 3; |
778 | } | 789 | } |
779 | } else if (!(rc & 2)) { | 790 | } else if (!(rc & 2)) { /* AF_UNSPEC requested, store away */ |
780 | if (walker->ai_addrlen == sizeof(struct sockaddr_in6)) { | 791 | if (walker->ai_addrlen == sizeof(struct sockaddr_in6)) { |
781 | struct sockaddr_in6 *addr = (struct sockaddr_in6 *)walker->ai_addr; | 792 | struct sockaddr_in6 *addr = (struct sockaddr_in6 *)walker->ai_addr; |
782 | ip6.in6_addr = addr->sin6_addr; | 793 | ip6.in6_addr = addr->sin6_addr; |