mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-15 10:17:20 +00:00
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.
This commit is contained in:
parent
fdc9713bf7
commit
e84892eb74
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=145728
@ -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;
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user