>Number:         161548
>Category:       bin
>Synopsis:       [patch] getent(1) inconsistent treatment of IPv6 host data
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Oct 13 16:40:03 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Matthew Seaman
>Release:        FreeBSD 8.2-STABLE amd64
>Organization:
Infracaninophile
>Environment:
System: FreeBSD lucid-nonsense.infracaninophile.co.uk 8.2-STABLE FreeBSD 
8.2-STABLE #3 r226035: Wed Oct 5 14:26:52 BST 2011 
r...@lucid-nonsense.infracaninophile.co.uk:/usr/obj/usr/src/sys/LUCID-NONSENSE 
amd64


        
>Description:

getent(1) can be used to resolve an IPv6 address into a hostname, but
you can't look up a hostname and find IPv6 addresses.  This is annoyingly
inconsistent.

>How-To-Repeat:
        
>Fix:

        

--- getent.c.diff begins here ---
Index: usr.bin/getent/getent.c
===================================================================
--- usr.bin/getent/getent.c     (revision 226035)
+++ usr.bin/getent/getent.c     (working copy)
@@ -280,7 +280,7 @@
 static int
 hosts(int argc, char *argv[])
 {
-       struct hostent  *he;
+       struct hostent  *he4, *he6;
        char            addr[IN6ADDRSZ];
        int             i, rv;
 
@@ -290,19 +290,27 @@
        sethostent(1);
        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;
                        }
--- getent.c.diff ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:
_______________________________________________
freebsd-bugs@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "freebsd-bugs-unsubscr...@freebsd.org"

Reply via email to