From 83e5ea9ca26f62ac2a097f1b81ac7843caa2c864 Mon Sep 17 00:00:00 2001 From: jaredy <> Date: Wed, 27 Jul 2005 13:40:28 +0000 Subject: backout gethostent changes for now -- there is fallout, discovered by otto --- src/lib/libc/net/gethostnamadr.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libc/net/gethostnamadr.c b/src/lib/libc/net/gethostnamadr.c index 70bff68fd6..4450652167 100644 --- a/src/lib/libc/net/gethostnamadr.c +++ b/src/lib/libc/net/gethostnamadr.c @@ -48,7 +48,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.65 2005/07/24 18:47:59 millert Exp $"; +static const char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.66 2005/07/27 13:40:28 jaredy Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -786,7 +786,7 @@ _endhtent(void) } } -static struct hostent * +struct hostent * _gethtent(void) { struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); @@ -832,9 +832,9 @@ _gethtent(void) goto again; } /* if this is not something we're looking for, skip it. */ - if (host.h_addrtype != AF_UNSPEC && host.h_addrtype != af) + if (host.h_addrtype != af) goto again; - if (host.h_length != 0 && host.h_length != len) + if (host.h_length != len) goto again; h_addr_ptrs[0] = (char *)host_addr; h_addr_ptrs[1] = NULL; @@ -868,16 +868,31 @@ _gethtent(void) return (&host); } +struct hostent * +_gethtbyname(const char *name) +{ + struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); + struct hostent *hp; + extern struct hostent *_gethtbyname2(const char *, int); + + if (_resp->options & RES_USE_INET6) { + hp = _gethtbyname2(name, AF_INET6); + if (hp) + return (hp); + } + return (_gethtbyname2(name, AF_INET)); +} + struct hostent * _gethtbyname2(const char *name, int af) { struct hostent *p; char **cp; - host.h_addrtype = af; - host.h_length = 0; _sethtent(0); while ((p = _gethtent())) { + if (p->h_addrtype != af) + continue; if (strcasecmp(p->h_name, name) == 0) break; for (cp = p->h_aliases; *cp != 0; cp++) @@ -899,8 +914,7 @@ _gethtbyaddr(const void *addr, socklen_t len, int af) _sethtent(0); while ((p = _gethtent())) - if (p->h_addrtype == af && p->h_length == len && - !bcmp(p->h_addr, addr, len)) + if (p->h_addrtype == af && !bcmp(p->h_addr, addr, len)) break; _endhtent(); return (p); @@ -1079,8 +1093,6 @@ map_v4v6_hostent(struct hostent *hp, char **bpp, char *ep) struct hostent * gethostent(void) { - host.h_addrtype = AF_UNSPEC; - host.h_length = 0; return (_gethtent()); } -- cgit v1.2.3-55-g6feb