From: Mark Andrews Date: Tue, 26 Feb 2002 03:15:00 +0000 (+0000) Subject: pullup: X-Git-Tag: v9.0.1^2~8497 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=84ef147b1fa0aed15cade55478ed647d15f7b094;p=thirdparty%2Fbind9.git pullup: 1210. [bug] libbind: getnameinfo() failed to lookup IPv4 mapped / compatible addresses. [RT #2461] --- diff --git a/CHANGES b/CHANGES index 303d892ce22..48bcdab2a14 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +1210. [bug] libbind: getnameinfo() failed to lookup IPv4 mapped / + compatible addresses. [RT #2461] + 1209. [bug] Dig, host, nslookup were not checking the message ids on the responses. [RT #2454] diff --git a/lib/bind/irs/getnameinfo.c b/lib/bind/irs/getnameinfo.c index 0e86cc15230..9b26c641ff6 100644 --- a/lib/bind/irs/getnameinfo.c +++ b/lib/bind/irs/getnameinfo.c @@ -105,9 +105,9 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) int family, i; const char *addr; char *p; - u_char pfx; char numserv[512]; char numaddr[512]; + const struct sockaddr_in6 *sin6; if (sa == NULL) return EAI_FAIL; @@ -157,9 +157,23 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) flags |= NI_NUMERICHOST; break; case AF_INET6: - pfx = *addr; - if (pfx == 0 || pfx == 0xfe || pfx == 0xff) - flags |= NI_NUMERICHOST; + sin6 = (const struct sockaddr_in6 *)sa; + switch (sin6->sin6_addr.s6_addr[0]) { + case 0x00: + if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) + ; + else if (IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr)) + ; + else + flags |= NI_NUMERICHOST; + break; + default: + if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) + flags |= NI_NUMERICHOST; + else if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) + flags |= NI_NUMERICHOST; + break; + } break; } if (host == NULL || hostlen == 0) { diff --git a/lib/bind/port_after.h.in b/lib/bind/port_after.h.in index f120779e59f..fcbc99c9d37 100644 --- a/lib/bind/port_after.h.in +++ b/lib/bind/port_after.h.in @@ -156,11 +156,32 @@ extern const struct in6_addr in6addr_any; IN6_ARE_ADDR_EQUAL(a, &in6addr_any) #endif +#ifndef IN6_IS_ADDR_LOOPBACK +extern const struct in6_addr isc_in6addr_loopback; +#define IN6_IS_ADDR_LOOPBACK(a) \ + IN6_ARE_ADDR_EQUAL(a, &isc_in6addr_loopback) +#endif + +#ifndef IN6_IS_ADDR_V4MAPPED +#define IN6_IS_ADDR_V4MAPPED(a) \ + ((a)->s6_addr[0] == 0x00 && (a)->s6_addr[1] == 0x00 && \ + (a)->s6_addr[2] == 0x00 && (a)->s6_addr[3] == 0x00 && \ + (a)->s6_addr[4] == 0x00 && (a)->s6_addr[5] == 0x00 && \ + (a)->s6_addr[6] == 0x00 && (a)->s6_addr[9] == 0x00 && \ + (a)->s6_addr[8] == 0x00 && (a)->s6_addr[9] == 0x00 && \ + (a)->s6_addr[10] == 0xff && (a)->s6_addr[11] == 0xff) +#endif + #ifndef IN6_IS_ADDR_SITELOCAL #define IN6_IS_ADDR_SITELOCAL(a) \ (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0)) #endif +#ifndef IN6_IS_ADDR_LINKLOCAL +#define IN6_IS_ADDR_LINKLOCAL(a) \ + (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80)) +#endif + #ifndef IN6_IS_ADDR_MULTICAST #define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) #endif