Date: Sun, 30 Sep 2012 16:17:55 +0000 (UTC) From: Kevin Lo <kevlo@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r241075 - stable/9/usr.bin/getent Message-ID: <201209301617.q8UGHtmg063831@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kevlo Date: Sun Sep 30 16:17:54 2012 New Revision: 241075 URL: http://svn.freebsd.org/changeset/base/241075 Log: MFC r240954: Teach getent(1) to look up a hostname and find IPv6 addresses. PR: bin/161548 Submitted by: matthew Modified: stable/9/usr.bin/getent/getent.c Directory Properties: stable/9/usr.bin/ (props changed) Modified: stable/9/usr.bin/getent/getent.c ============================================================================== --- stable/9/usr.bin/getent/getent.c Sun Sep 30 16:11:50 2012 (r241074) +++ stable/9/usr.bin/getent/getent.c Sun Sep 30 16:17:54 2012 (r241075) @@ -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; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201209301617.q8UGHtmg063831>