This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

glibc 2.1/2.2 patch



Hi,

here is a patch for glibc 2.1 and 2.2. "getent hosts" now understands
IPv6 addresses.

  Thorsten
-- 
Thorsten Kukuk       http://www.suse.de/~kukuk/       kukuk@suse.de
SuSE GmbH            Schanzaeckerstr. 10            90443 Nuernberg
Linux is like a Vorlon.  It is incredibly powerful, gives terse,
cryptic answers and has a lot of things going on in the background.
2000-01-10  Thorsten Kukuk  <kukuk@suse.de>

	* nss/getent.c: Add ipv6 support for hosts

--- nss/getent.c
+++ nss/getent.c	2000/01/10 13:39:30
@@ -1,6 +1,6 @@
-/* Copyright (c) 1998, 1999 Free Software Foundation, Inc.
+/* Copyright (c) 1998, 1999, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1998.
+   Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public License as
@@ -35,6 +35,7 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <arpa/nameser.h>
 
 /* Get libc version number.  */
 #include <version.h>
@@ -251,7 +252,9 @@
 print_hosts (struct hostent *host)
 {
   unsigned int i;
-  char *ip = inet_ntoa(* (struct in_addr *) host->h_addr_list[0]);
+  char buf[INET6_ADDRSTRLEN];
+  const char *ip = inet_ntop (host->h_addrtype, host->h_addr_list[0],
+			      buf, sizeof (buf));
 
   fputs (ip, stdout);
   for (i = strlen (ip); i < 16; ++i)
@@ -276,18 +279,22 @@
 
   for (i = 0; i < number; ++i)
     {
-      struct hostent *host;
+      struct hostent *host = NULL;
 
-      if (isdigit (key[i][0]))
+      if (strchr (key[i], ':') != NULL)
 	{
-	  struct in_addr addr;
-	  addr.s_addr = inet_addr (key[i]);
-
-	  host = gethostbyaddr ((char *)&addr, sizeof (struct in_addr),
-				AF_INET);
+	  char addr[IN6ADDRSZ];
+	  if (inet_pton (AF_INET6, key[i], &addr))
+	    host = gethostbyaddr (addr, sizeof (addr), AF_INET6);
 	}
-      else
-	host = gethostbyname (key[i]);
+      else if (isdigit (key[i][0]))
+	{
+	  char addr[INADDRSZ];
+	  if (inet_pton (AF_INET, key[i], &addr))
+	    host = gethostbyaddr (addr, sizeof (addr), AF_INET);
+	}
+      else if ((host = gethostbyname2 (key[i], AF_INET6)) == NULL)
+	host = gethostbyname2 (key[i], AF_INET);
 
       if (host == NULL)
 	result = 2;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]