diff options
author | Jared Yanovich <jaredy@cvs.openbsd.org> | 2005-07-23 04:15:50 +0000 |
---|---|---|
committer | Jared Yanovich <jaredy@cvs.openbsd.org> | 2005-07-23 04:15:50 +0000 |
commit | df574f6a450bd3128a5f4aad797ac3fd7e1d71d5 (patch) | |
tree | 3e55e48b9796fb31e842fbd3c33a37cc3a4980f1 | |
parent | 1d9f20887ce7a1e18ce1a5fb41ceef941e1dd627 (diff) |
*hostent() fixes:
- Make _gethtent() static
- _gethtbyname() is dead code (succeeded by _gethtbyname2), kill it
- _gethtent() requires setting the address family field of the
file-scope variable `host' to that of the desired type of the entry
being searched for. Change the behavior to enforce this if it is not
AF_UNSPEC, which will now allow stepping through entries, and set it
to specific values everywhere else.
help & ok millert
-rw-r--r-- | lib/libc/net/gethostnamadr.c | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/lib/libc/net/gethostnamadr.c b/lib/libc/net/gethostnamadr.c index b036efe2d1d..626f9a6e65b 100644 --- a/lib/libc/net/gethostnamadr.c +++ b/lib/libc/net/gethostnamadr.c @@ -48,7 +48,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.63 2005/06/08 18:32:34 millert Exp $"; +static const char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.64 2005/07/23 04:15:49 jaredy Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -786,7 +786,7 @@ _endhtent(void) } } -struct hostent * +static struct hostent * _gethtent(void) { struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); @@ -832,10 +832,12 @@ _gethtent(void) goto again; } /* if this is not something we're looking for, skip it. */ - if (host.h_addrtype != af) - goto again; - if (host.h_length != len) - goto again; + if (host.h_addrtype != AF_UNSPEC) { + if (host.h_addrtype != af) + goto again; + if (host.h_length != len) + goto again; + } h_addr_ptrs[0] = (char *)host_addr; h_addr_ptrs[1] = NULL; host.h_addr_list = h_addr_ptrs; @@ -869,26 +871,13 @@ _gethtent(void) } 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; + _sethtent(0); while ((p = _gethtent())) { if (p->h_addrtype != af) @@ -914,7 +903,8 @@ _gethtbyaddr(const void *addr, socklen_t len, int af) _sethtent(0); while ((p = _gethtent())) - if (p->h_addrtype == af && !bcmp(p->h_addr, addr, len)) + if (p->h_addrtype == af && p->h_length == len && + !bcmp(p->h_addr, addr, len)) break; _endhtent(); return (p); @@ -1093,6 +1083,7 @@ map_v4v6_hostent(struct hostent *hp, char **bpp, char *ep) struct hostent * gethostent(void) { + host.h_addrtype = AF_UNSPEC; return (_gethtent()); } |