AF_INET6 lookups breaks AF_INET lookups

Thorsten Kukuk kukuk@suse.de
Fri Dec 20 12:36:00 GMT 2002


Hi,

glibc 2.3 has a servery bug in the resolver code. It seems, that
a AF_INET6 lookup for a hostname will change some internal data, so
that AF_INET lookups are not longer possible for all hostnames.

I append my test program, the hostname I can reproduce it with is
www.lufthansa.com. I do 3 gethostbyname2 lookups: One with AF_INET,
this works, one with AF_INET6, this does not work as expected. Now
I do again an AF_INET lookup and now this also fails. With glibc 2.2.5
it works fine.

The output of the testprogram:

Using gethostbyname2 (www.lufthansa.com, AF_INET): 53.122.207.1    www.lufthansa.com
Using gethostbyname2 (www.lufthansa.com, AF_INET6): www.lufthansa.com not found
Using gethostbyname2 (www.lufthansa.com, AF_INET): www.lufthansa.com not found


Any ideas where we break this? It must be the nss_dns code or the
libresolv code, but I haven't found it yet.

  Thorsten

-- 
Thorsten Kukuk       http://www.suse.de/~kukuk/        kukuk@suse.de
SuSE Linux AG        Deutschherrnstr. 15-19        D-90429 Nuernberg
--------------------------------------------------------------------    
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B
-------------- next part --------------

#define _GNU_SOURCE

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>
#include <err.h>
#include <alloca.h>

void
print_host (char *name, struct hostent *host)
{
   if (host == NULL)
     printf ("%s not found\n", name);
   else
     {
       unsigned int i;
       char buf[INET6_ADDRSTRLEN];
       const char *ip = inet_ntop (host->h_addrtype,
				   host->h_addr_list[0],
				   buf, sizeof (buf));

       printf ("%-15s %s", ip, host->h_name);

       i = 0;
       while (host->h_aliases[i] != NULL)
	 {
	   putchar_unlocked (' ');
	   fputs_unlocked (host->h_aliases[i], stdout);
	   ++i;
	 }
       putchar_unlocked ('\n');
     }
}

int
main (int argc, char *argv[])
{
   struct hostent *host;

   printf ("Using gethostbyname2 (%s, AF_INET): ", argv[1]);
   host = gethostbyname2 (argv[1], AF_INET);
   print_host (argv[1], host);
   printf ("Using gethostbyname2 (%s, AF_INET6): ", argv[1]);
   host = gethostbyname2 (argv[1], AF_INET6);
   print_host (argv[1], host);
   printf ("Using gethostbyname2 (%s, AF_INET): ", argv[1]);
   host = gethostbyname2 (argv[1], AF_INET);
   print_host (argv[1], host);

   return 0;
}



More information about the Libc-alpha mailing list