From 40ca152d152be86531280469b1e70a99f8b29d1b Mon Sep 17 00:00:00 2001 From: Hajimu UMEMOTO Date: Sat, 30 Apr 2005 17:01:18 +0000 Subject: [PATCH] _ht_gethostbyname didn't handle RES_USE_INET6 correctly. --- lib/libc/net/gethostbyht.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/libc/net/gethostbyht.c b/lib/libc/net/gethostbyht.c index 7024ef22a95e..20cc97e8dbef 100644 --- a/lib/libc/net/gethostbyht.c +++ b/lib/libc/net/gethostbyht.c @@ -90,8 +90,8 @@ _endhosthtent(struct hostent_data *hed) } } -int -gethostent_r(struct hostent *he, struct hostent_data *hed) +static int +gethostent_p(struct hostent *he, struct hostent_data *hed, int mapped) { char *p, *bp, *ep; char *cp, **q; @@ -119,7 +119,7 @@ gethostent_r(struct hostent *he, struct hostent_data *hed) af = AF_INET6; len = IN6ADDRSZ; } else if (inet_pton(AF_INET, p, hed->host_addr) > 0) { - if (_res.options & RES_USE_INET6) { + if (mapped) { _map_v4v6_address((char *)hed->host_addr, (char *)hed->host_addr); af = AF_INET6; @@ -174,6 +174,12 @@ gethostent_r(struct hostent *he, struct hostent_data *hed) return 0; } +int +gethostent_r(struct hostent *he, struct hostent_data *hed) +{ + return gethostent_p(he, hed, _res.options & RES_USE_INET6); +} + struct hostent * gethostent(void) { @@ -187,7 +193,7 @@ gethostent(void) } int -_ht_gethostbyname(void *rval, void *cb_data, va_list ap) +_ht_gethostbyname(void *rval, void *cb_data, va_list ap) { const char *name; int af; @@ -202,9 +208,15 @@ _ht_gethostbyname(void *rval, void *cb_data, va_list ap) hed = va_arg(ap, struct hostent_data *); sethostent_r(0, hed); - while ((error = gethostent_r(he, hed)) == 0) { + while ((error = gethostent_p(he, hed, 0)) == 0) { if (he->h_addrtype != af) continue; + 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; + } if (strcasecmp(he->h_name, name) == 0) break; for (cp = he->h_aliases; *cp != 0; cp++) @@ -217,7 +229,7 @@ found: return (error == 0) ? NS_SUCCESS : NS_NOTFOUND; } -int +int _ht_gethostbyaddr(void *rval, void *cb_data, va_list ap) { const char *addr;