diff options
author | kevlo <kevlo@FreeBSD.org> | 2012-09-26 09:29:48 +0000 |
---|---|---|
committer | kevlo <kevlo@FreeBSD.org> | 2012-09-26 09:29:48 +0000 |
commit | c5b2970fc8a1ec3ef52e09770f11c01519e81a49 (patch) | |
tree | bd9c8510cb7e01f1228cc0fe37f54605dfbd28df /usr.bin/getent | |
parent | 55574dacdcd67b9b6db91eb87d7b02e8161928d4 (diff) | |
download | FreeBSD-src-c5b2970fc8a1ec3ef52e09770f11c01519e81a49.zip FreeBSD-src-c5b2970fc8a1ec3ef52e09770f11c01519e81a49.tar.gz |
Teach getent(1) to look up a hostname and find IPv6 addresses.
PR: bin/161548
Submitted by: matthew
Diffstat (limited to 'usr.bin/getent')
-rw-r--r-- | usr.bin/getent/getent.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/usr.bin/getent/getent.c b/usr.bin/getent/getent.c index 85857d8..7424577 100644 --- a/usr.bin/getent/getent.c +++ b/usr.bin/getent/getent.c @@ -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; } |