diff options
author | Neel Natu <neel@FreeBSD.org> | 2012-11-11 03:26:14 +0000 |
---|---|---|
committer | Neel Natu <neel@FreeBSD.org> | 2012-11-11 03:26:14 +0000 |
commit | 01ab895199c23cf7553b32bc0aaa0f7286c42e1c (patch) | |
tree | 1842e06348541f18126f1111e8c1cf0c51aa80da | |
parent | 55cf6f7582d30baeae169ec51540f883072b620d (diff) | |
parent | d0e0051c36c8eca2c7ad440a853da2c6e40bd45c (diff) | |
download | getent-darwin-01ab895199c23cf7553b32bc0aaa0f7286c42e1c.tar.gz getent-darwin-01ab895199c23cf7553b32bc0aaa0f7286c42e1c.tar.zst getent-darwin-01ab895199c23cf7553b32bc0aaa0f7286c42e1c.zip |
IFC @ r242684
-rw-r--r-- | getent.c | 34 |
1 files changed, 22 insertions, 12 deletions
@@ -277,7 +277,7 @@ hostsprint(const struct hostent *he) static int hosts(int argc, char *argv[]) { - struct hostent *he; + struct hostent *he4, *he6; char addr[IN6ADDRSZ]; int i, rv; @@ -285,21 +285,31 @@ hosts(int argc, char *argv[]) assert(argv != NULL); sethostent(1); + he4 = he6 = NULL; rv = RV_OK; if (argc == 2) { - while ((he = gethostent()) != NULL) - hostsprint(he); + while ((he4 = gethostent()) != NULL) + hostsprint(he4); } else { for (i = 2; i < argc; i++) { - if (inet_pton(AF_INET6, argv[i], (void *)addr) > 0) - he = gethostbyaddr(addr, IN6ADDRSZ, AF_INET6); - else if (inet_pton(AF_INET, argv[i], (void *)addr) > 0) - he = gethostbyaddr(addr, INADDRSZ, AF_INET); - else - he = gethostbyname(argv[i]); - if (he != NULL) - hostsprint(he); - else { + if (inet_pton(AF_INET6, argv[i], (void *)addr) > 0) { + he6 = gethostbyaddr(addr, IN6ADDRSZ, AF_INET6); + if (he6 != NULL) + hostsprint(he6); + } else if (inet_pton(AF_INET, argv[i], + (void *)addr) > 0) { + he4 = gethostbyaddr(addr, INADDRSZ, AF_INET); + if (he4 != NULL) + hostsprint(he4); + } else { + he6 = gethostbyname2(argv[i], AF_INET6); + if (he6 != NULL) + hostsprint(he6); + he4 = gethostbyname(argv[i]); + if (he4 != NULL) + hostsprint(he4); + } + if ( he4 == NULL && he6 == NULL ) { rv = RV_NOTFOUND; break; } |