On Thu, Apr 07, 2005 at 05:30:26PM +0200, I wrote:
> Here is a patch which makes hostname try an IPv6 lookup in case the IPv4
> one fails. This is needed to make hostname work on IPv6-only hosts.

It seems defining 'option inet6' (which I just discovered) in
/etc/resolv.conf fixes part of the problem, and allows hostname to find
the FQDN and aliases using IPv6 lookups. However, IPv6 are mistakenly
displayed as IPv4 ones.

This new patch fixes this, and relies on the resolver configuration to
choose the address family used by gethostbyname, which is better imho,
and doesn't make use of the gethostbyname2, which is a GNU extension.

A note is also added to the manual page in the hope that it will point
people configuring IPv6-only hosts and wondering why hostname -f fails
in the right direction.

Hope this helps,

-- 
Jeremie Koenig <[EMAIL PROTECTED]>
diff -ru hostname-2.13.orig/hostname.c hostname-2.13/hostname.c
--- hostname-2.13.orig/hostname.c       2003-12-18 03:11:33.000000000 +0100
+++ hostname-2.13/hostname.c    2005-04-16 01:08:58.000000000 +0200
@@ -123,6 +123,8 @@
        register char *p,**alias;
        struct in_addr **ip;
        int flag = 0;   
+       char abuf[INET6_ADDRSTRLEN];
+
        if (opt_v)
                fprintf(stderr,NLS_CATGETS(catfd, hostnameSet, 
hostname_verb_res, "Resolving `%s' ...\n"),hname);
        if (!(hp = gethostbyname(hname))) {
@@ -143,7 +145,7 @@
                ip=(struct in_addr **)hp->h_addr_list;
                while(ip[0])
                        fprintf(stderr,NLS_CATGETS(catfd, hostnameSet, 
hostname_verb_ipn, "Result: h_addr_list=`%s'\n"),
-                               inet_ntoa(**ip++));
+                               inet_ntop(hp->h_addrtype, *ip++, abuf, 
sizeof(abuf)));
        }
 
        if (!(p = strchr(hp->h_name, '.')) && (c == 'd')) return;
@@ -162,7 +164,8 @@
                        while (hp->h_addr_list[0]) {
                                if(flag)
                                        printf(" ");
-                               printf("%s ", inet_ntoa(*(struct in_addr *) * 
hp->h_addr_list++));
+                               printf("%s", inet_ntop(hp->h_addrtype,
+                                       *hp->h_addr_list++, abuf,sizeof(abuf)));
                                flag = 1;
                        }
                        printf("\n");
diff -ru hostname-2.13.orig/man/en_US.88591/hostname.1 
hostname-2.13/man/en_US.88591/hostname.1
--- hostname-2.13.orig/man/en_US.88591/hostname.1       2003-12-18 
03:11:33.000000000 +0100
+++ hostname-2.13/man/en_US.88591/hostname.1    2005-04-16 01:52:09.906995408 
+0200
@@ -130,7 +130,7 @@
 Print a usage message and exit.
 .TP
 .I "\-i, \-\-ip-address"
-Display the IP address(es) of the host.
+Display the network address(es) of the host.
 .TP
 .I "\-s, \-\-short"
 Display the short host name. This is the host name cut at the first dot.
@@ -145,6 +145,16 @@
 Display the NIS domain name. If a parameter is given (or 
 .B \-\-file name
 ) then root can also set a new NIS domain.
+.SH NOTES
+The address families
+.B hostname
+tries when looking up the FQDN, aliases and network addresses of the
+host are determined by the configuration of your resolver.
+For instance, on GNU Libc systems, the resolver can be instructed to
+try IPv6 lookups first by using the
+.B inet6
+option in
+.BR /etc/resolv.conf .
 .SH FILES
 .B /etc/hosts
 .SH AUTHORS

Reply via email to