diff options
Diffstat (limited to 'lib/libc/net/gethostbyht.c')
-rw-r--r-- | lib/libc/net/gethostbyht.c | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/lib/libc/net/gethostbyht.c b/lib/libc/net/gethostbyht.c index a4b2203..7c6fe2c 100644 --- a/lib/libc/net/gethostbyht.c +++ b/lib/libc/net/gethostbyht.c @@ -53,7 +53,7 @@ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93"; -static char rcsid[] = "$Id: gethostbyht.c,v 1.3 1996/01/13 09:03:45 peter Exp $"; +static char rcsid[] = "$Id: gethostbyht.c,v 1.4 1996/07/12 18:54:34 jkh Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -65,6 +65,8 @@ static char rcsid[] = "$Id: gethostbyht.c,v 1.3 1996/01/13 09:03:45 peter Exp $" #include <ctype.h> #include <errno.h> #include <string.h> +#include <arpa/nameser.h> /* XXX */ +#include <resolv.h> /* XXX */ #define MAXALIASES 35 @@ -72,7 +74,7 @@ static struct hostent host; static char *host_aliases[MAXALIASES]; static char hostbuf[BUFSIZ+1]; static FILE *hostf = NULL; -static struct in_addr host_addr; +static u_char host_addr[16]; /* IPv4 or IPv6 */ static char *h_addr_ptrs[2]; static int stayopen = 0; @@ -101,12 +103,13 @@ gethostent() { char *p; register char *cp, **q; + int af, len; if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) { h_errno = NETDB_INTERNAL; return (NULL); } -again: + again: if (!(p = fgets(hostbuf, sizeof hostbuf, hostf))) { h_errno = HOST_NOT_FOUND; return (NULL); @@ -119,23 +122,32 @@ again: if (!(cp = strpbrk(p, " \t"))) goto again; *cp++ = '\0'; - /* THIS STUFF IS INTERNET SPECIFIC */ - if (!inet_aton(p, &host_addr)) + if ((_res.options & RES_USE_INET6) && + inet_pton(AF_INET6, p, host_addr) > 0) { + af = AF_INET6; + len = IN6ADDRSZ; + } else if (inet_pton(AF_INET, p, host_addr) > 0) { + if (_res.options & RES_USE_INET6) { + _map_v4v6_address((char*)host_addr, (char*)host_addr); + af = AF_INET6; + len = IN6ADDRSZ; + } else { + af = AF_INET; + len = INADDRSZ; + } + } else { goto again; - h_addr_ptrs[0] = (char *)&host_addr; + } + h_addr_ptrs[0] = (char *)host_addr; h_addr_ptrs[1] = NULL; -#if BSD >= 43 || defined(h_addr) /* new-style hostent structure */ host.h_addr_list = h_addr_ptrs; -#else - host.h_addr = h_addr_ptrs[0]; -#endif - host.h_length = sizeof(u_int32_t); - host.h_addrtype = AF_INET; + host.h_length = len; + host.h_addrtype = af; while (*cp == ' ' || *cp == '\t') cp++; host.h_name = cp; q = host.h_aliases = host_aliases; - if ( (cp = strpbrk(cp, " \t")) ) + if (cp = strpbrk(cp, " \t")) *cp++ = '\0'; while (cp && *cp) { if (*cp == ' ' || *cp == '\t') { @@ -144,23 +156,32 @@ again: } if (q < &host_aliases[MAXALIASES - 1]) *q++ = cp; - if ( (cp = strpbrk(cp, " \t")) ) + if (cp = strpbrk(cp, " \t")) *cp++ = '\0'; } *q = NULL; + if (_res.options & RES_USE_INET6) { + char *bp = hostbuf; + int buflen = sizeof hostbuf; + + _map_v4v6_hostent(&host, &bp, &buflen); + } h_errno = NETDB_SUCCESS; return (&host); } struct hostent * -_gethostbyhtname(name) +_gethostbyhtname2(name, af) char *name; + int af; { register struct hostent *p; register char **cp; sethostent(0); while ( (p = gethostent()) ) { + if (p->h_addrtype != af) + continue; if (strcasecmp(p->h_name, name) == 0) break; for (cp = p->h_aliases; *cp != 0; cp++) @@ -173,15 +194,15 @@ found: } struct hostent * -_gethostbyhtaddr(addr, len, type) +_gethostbyhtaddr(addr, len, af) const char *addr; - int len, type; + int len, af; { register struct hostent *p; sethostent(0); while ( (p = gethostent()) ) - if (p->h_addrtype == type && !bcmp(p->h_addr, addr, len)) + if (p->h_addrtype == af && !bcmp(p->h_addr, addr, len)) break; endhostent(); return (p); |