#475949 net-tools: fix FQDN handling of AAAA records in hostname

Package:
net-tools
Source:
net-tools
Description:
NET-3 networking toolkit
Submitter:
Mike Frysinger
Date:
2023-04-03 17:18:04 UTC
Severity:
wishlist
Tags:
#475949#5
Date:
2008-04-14 05:00:48 UTC
From:
To:
This fix is from pasi.valminen@hut.fi.  However, I think it needs work
before it can be merged with the latest cvs.
--- a/hostname.c
+++ b/hostname.c
@@ -36,6 +36,10 @@
 #include <getopt.h>
 #include <string.h>
 #include <netdb.h>
+#ifdef IPV6
+#include <sys/socket.h> /* for PF_INET6 */
+#include <sys/types.h>  /* for inet_ntop */
+#endif /* IPV6 */
 #include <errno.h>
 #include <sys/param.h>
 #include <netinet/in.h>
@@ -125,15 +129,23 @@ static void setdname(char *dname)
 static void showhname(char *hname, int c)
 {
     struct hostent *hp;
+#ifdef IPV6
+    struct in6_addr **ip6;
+#endif /* IPV6 */
     register char *p, **alias;
     struct in_addr **ip;

     if (opt_v)
 	fprintf(stderr, _("Resolving `%s' ...\n"), hname);
-    if (!(hp = gethostbyname(hname))) {
+    if (
+#ifdef IPV6
+        !(hp = gethostbyname2(hname, PF_INET6)) &&
+#endif /* IPV6 */
+        !(hp = gethostbyname(hname))) {
 	herror(program_name);
 	exit(1);
     }
+
     if (opt_v) {
 	fprintf(stderr, _("Result: h_name=`%s'\n"),
 		hp->h_name);
@@ -142,11 +154,28 @@ static void showhname(char *hname, int c)
 	while (alias[0])
 	    fprintf(stderr, _("Result: h_aliases=`%s'\n"),
 		    *alias++);
-
-	ip = (struct in_addr **) hp->h_addr_list;
-	while (ip[0])
-	    fprintf(stderr, _("Result: h_addr_list=`%s'\n"),
-		    inet_ntoa(**ip++));
+#ifdef IPV6
+        if(hp->h_addrtype == PF_INET6) {
+            char addr[INET6_ADDRSTRLEN + 1];
+	    addr[INET6_ADDRSTRLEN] = '\0';
+            ip6 = (struct in6_addr **) hp->h_addr_list;
+            while(ip6[0]) {
+                if(inet_ntop(PF_INET6, *ip6++, addr, INET6_ADDRSTRLEN))
+                    fprintf(stderr, _("Result: h_addr_list=`%s'\n"), addr);
+                else if(errno == EAFNOSUPPORT)
+                    fprintf(stderr, _("%s: protocol family not supported\n"),
+                            program_name);
+                else if(errno == ENOSPC)
+                    fprintf(stderr, _("%s: name too long\n"), program_name);
+            }
+        } else
+#endif /* IPV6 */
+	{
+	    ip = (struct in_addr **) hp->h_addr_list;
+	    while (ip[0])
+	        fprintf(stderr, _("Result: h_addr_list=`%s'\n"),
+		        inet_ntoa(**ip++));
+        }
     }
     if (!(p = strchr(hp->h_name, '.')) && (c == 'd'))
 	return;
@@ -158,10 +187,32 @@ static void showhname(char *hname, int c)
 	printf("\n");
 	break;
     case 'i':
-	while (hp->h_addr_list[0])
-	    printf("%s ", inet_ntoa(*(struct in_addr *) *hp->h_addr_list++));
-	printf("\n");
-	break;
+#ifdef IPV6
+        if(hp->h_addrtype == PF_INET6) {
+            char addr[INET6_ADDRSTRLEN + 1];
+            addr[INET6_ADDRSTRLEN] = '\0';
+            while(hp->h_addr_list[0]) {
+                if(inet_ntop(PF_INET6, (struct in6_addr *)*hp->h_addr_list++,
+                             addr, INET6_ADDRSTRLEN))
+                    printf("%s ", addr);
+                else if(errno == EAFNOSUPPORT) {
+                    fprintf(stderr, _("\n%s: protocol family not supported\n"),
+                            program_name);
+                    exit(1);
+                } else if(errno == ENOSPC) {
+                    fprintf(stderr, _("\n%s: name too long\n"), program_name);
+                    exit(1);
+                }
+                printf("\n");
+            }
+        } else
+#endif /* IPV6 */
+        {
+	    while (hp->h_addr_list[0])
+	        printf("%s ", inet_ntoa(*(struct in_addr *)*hp->h_addr_list++));
+            printf("\n");
+        }
+        break;
     case 'd':
 	printf("%s\n", ++p);
 	break;
-- 
1.5.5

#475949#8
Date:
2023-04-03 17:15:38 UTC
From:
To:
Version 1.60-19 is not in the archive any longer and all net-tools binary packages
that are currently contained in the archive do not include a hostname binary.