From owner-svn-src-all@FreeBSD.ORG Wed Sep 26 09:29:49 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 54AB51065672; Wed, 26 Sep 2012 09:29:49 +0000 (UTC) (envelope-from kevlo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 403A98FC12; Wed, 26 Sep 2012 09:29:49 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q8Q9Tn8J099781; Wed, 26 Sep 2012 09:29:49 GMT (envelope-from kevlo@svn.freebsd.org) Received: (from kevlo@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q8Q9Tn2m099779; Wed, 26 Sep 2012 09:29:49 GMT (envelope-from kevlo@svn.freebsd.org) Message-Id: <201209260929.q8Q9Tn2m099779@svn.freebsd.org> From: Kevin Lo Date: Wed, 26 Sep 2012 09:29:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r240954 - head/usr.bin/getent X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Sep 2012 09:29:49 -0000 Author: kevlo Date: Wed Sep 26 09:29:48 2012 New Revision: 240954 URL: http://svn.freebsd.org/changeset/base/240954 Log: Teach getent(1) to look up a hostname and find IPv6 addresses. PR: bin/161548 Submitted by: matthew Modified: head/usr.bin/getent/getent.c Modified: head/usr.bin/getent/getent.c ============================================================================== --- head/usr.bin/getent/getent.c Wed Sep 26 09:27:38 2012 (r240953) +++ head/usr.bin/getent/getent.c Wed Sep 26 09:29:48 2012 (r240954) @@ -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; }