This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

getaddrinfo with PF_UNSPEC and /etc/hosts

Hello all,

It was pointed out by Rafal Wojtczuk on Owl development list that telnet
that ships with Red Hat Linux 7.2 does not behave the way one would expect
when resolving names using /etc/hosts.  That is, if you have:

hosts:      files nisplus nis dns

order hosts,bind

[snip]	netcore.home

and you 'telnet netcore.home', there will be a DNS lookup for AAAA address 
of netcore.home.

On BSD's, this will not be done, and the IPv4 address is taken even though 
there might be IPv6 capability in the system.

If you change /etc/hosts to be like:
[snip]   netcore.home
3ffe:ffff::1	netcore.home
the lookup can be avoided.

This appears to be due to getaddrinfo implementation.

A code fragment from RHL72 telnet that brings up this issue (code is from 
OpenBSD telnet client):
        hostname = hostp;
  	memset(&hints, 0, sizeof(hints));
        hints.ai_family = PF_UNSPEC;
        hints.ai_socktype = SOCK_STREAM;
  	  hints.ai_flags = 0;
  	if (portp == NULL) {
                portp = "telnet";
                telnetport = 1;
  	  } else if (*portp == '-') {
  		telnetport = 1;
        h_errno = 0;
        error = getaddrinfo(hostp, portp, &hints, &res0);
        if (error) {
            if (error == EAI_SERVICE)
                warnx("%s: bad port", portp);
                warnx("%s: %s", hostp, gai_strerror(error));
           if (h_errno)		 
           return 0;		 

A few items that may be interesting:

 - with ai.hints = AF_INET this works without lookups (natural)
 - whether IPv6 is enabled (ie. module loaded in kernel) makes no difference
 - BSD getaddrinfo avoids lookups

One could argue both ways whether this would have to fixed and at what 

 - if you add hosts to /etc/hosts, one would expect you'd only want to 
reach them via the addresses you entered them with, unless otherwise 
specified (ie: e.g. accept IPv4 if in /etc/hosts, don't loop up for IPv6)
This is what BSD does.

 - even though you add hosts /etc/hosts, you might still want to try other 
protocols, e.g. IPv6.  This is very problematic if /etc/hosts doesn't have 
both IPv4 and IPv6 entry for every name.  E.g. if connectivity is down adn 
there is no loopback-ip6 entry, there would be DNS AAAA queries for 

IMO, this is a rather important issue as getddrinfo and friends are 
getting more and more used due to their AF-independent nature.

Hope this helps.

Pekka Savola                 "Tell me of difficulties surmounted,
Netcore Oy                   not those you stumble over and fall"
Systems. Networks. Security.  -- Robert Jordan: A Crown of Swords

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