diff options
author | ume <ume@FreeBSD.org> | 2005-04-30 20:07:01 +0000 |
---|---|---|
committer | ume <ume@FreeBSD.org> | 2005-04-30 20:07:01 +0000 |
commit | eff8f31f8b0bffb36780a423c2307f514ac22269 (patch) | |
tree | 0fe67750816f865bc9fcf51ab90e59cc37f4abdf /lib | |
parent | c8fa8099674d921d50dae72e3a58ef66ac9c7fbc (diff) | |
download | FreeBSD-src-eff8f31f8b0bffb36780a423c2307f514ac22269.zip FreeBSD-src-eff8f31f8b0bffb36780a423c2307f514ac22269.tar.gz |
oops, gethostbyaddr(3) must return h_addr as an IPv4-mapped
IPv6 address when RES_USE_INET6 was set, according to RFC 2133
section 6.2.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/net/gethostbyht.c | 9 | ||||
-rw-r--r-- | lib/libc/net/gethostbynis.c | 9 | ||||
-rw-r--r-- | lib/libc/net/gethostnamadr.c | 5 |
3 files changed, 17 insertions, 6 deletions
diff --git a/lib/libc/net/gethostbyht.c b/lib/libc/net/gethostbyht.c index 452a6da..d1ef23b 100644 --- a/lib/libc/net/gethostbyht.c +++ b/lib/libc/net/gethostbyht.c @@ -246,8 +246,15 @@ _ht_gethostbyaddr(void *rval, void *cb_data, va_list ap) sethostent_r(0, hed); while ((error = gethostent_p(he, hed, 0)) == 0) - if (he->h_addrtype == af && !bcmp(he->h_addr, addr, len)) + if (he->h_addrtype == af && !bcmp(he->h_addr, addr, len)) { + if (he->h_addrtype == AF_INET && + _res.options & RES_USE_INET6) { + _map_v4v6_address(he->h_addr, he->h_addr); + he->h_length = IN6ADDRSZ; + he->h_addrtype = AF_INET6; + } break; + } endhostent_r(hed); return (error == 0) ? NS_SUCCESS : NS_NOTFOUND; diff --git a/lib/libc/net/gethostbynis.c b/lib/libc/net/gethostbynis.c index 45aed33..ca1a9a5 100644 --- a/lib/libc/net/gethostbynis.c +++ b/lib/libc/net/gethostbynis.c @@ -50,7 +50,7 @@ __FBSDID("$FreeBSD$"); #ifdef YP static int _gethostbynis(const char *name, char *map, int af, struct hostent *he, - struct hostent_data *hed, int mapped) + struct hostent_data *hed) { char *p, *bp, *ep; char *cp, **q; @@ -101,7 +101,7 @@ _gethostbynis(const char *name, char *map, int af, struct hostent *he, addrok = inet_aton(result, (struct in_addr *)hed->host_addr); if (addrok != 1) break; - if (mapped) { + if (_res.options & RES_USE_INET6) { _map_v4v6_address((char *)hed->host_addr, (char *)hed->host_addr); af = AF_INET6; @@ -172,8 +172,7 @@ _gethostbynisname_r(const char *name, int af, struct hostent *he, map = "ipnodes.byname"; break; } - return _gethostbynis(name, map, af, he, hed, - _res.options & RES_USE_INET6); + return _gethostbynis(name, map, af, he, hed); } static int @@ -193,7 +192,7 @@ _gethostbynisaddr_r(const char *addr, int len, int af, struct hostent *he, } if (inet_ntop(af, addr, numaddr, sizeof(numaddr)) == NULL) return -1; - return _gethostbynis(numaddr, map, af, he, hed, 0); + return _gethostbynis(numaddr, map, af, he, hed); } #endif /* YP */ diff --git a/lib/libc/net/gethostnamadr.c b/lib/libc/net/gethostnamadr.c index 8aae192..0646b0c 100644 --- a/lib/libc/net/gethostnamadr.c +++ b/lib/libc/net/gethostnamadr.c @@ -264,6 +264,11 @@ gethostbyaddr_r(const char *addr, int len, int af, struct hostent *he, { 0 } }; + if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + h_errno = NETDB_INTERNAL; + return -1; + } + if (af == AF_INET6 && len == IN6ADDRSZ) { addr6 = (const struct in6_addr *)(const void *)uaddr; if (IN6_IS_ADDR_LINKLOCAL(addr6)) { |