It looks to me (based on "strace" output, after noticing some odd slowness trying to lookup "localhost") that getaddrinfo() is ignoring the search orders specified in either "/etc/host.conf" or "/etc/nsswitch.conf", and instead is always trying a DNS lookup first, and a local "/etc/hosts" lookup last (which is just an utterly bass-ackwards way of doing things, even as a hard-coded default, IMHO)... It should further be noted that gethostbyname() does NOT exhibit this same flaw; it correctly uses the defined search orders, and so a lookup of "localhost" via it never tries a DNS query at all... But, for some reason getaddrinfo() is behaving differently, and ALWAYS wants to do the DNS query (and, FIRST)... Which, of course, can be a pain, for looking up simple local stuff like that... (And, no, I can't just switch to using gethostbyname() instead... I need a thread-safe function for one thing, and gethostbyname() is NOT... And, I want to code for future IPv6 compatibility, so getaddrinfo() is the best choice...)
Created attachment 152 [details] Test program to illustrate getaddrinfo()'s misbehavior...
assign to jakub
This bug still exists in 8.0 (glibc 2.2.93-5). Thanks much to Mr. Seace for the test program. This causes, among other things, a problem with the default sendmail config where it only listens to 127.0.0.1. Even though I have both the FQDN and short hostname assigned to 127.0.0.1 in /etc/hosts, and "hosts: files dns" in /etc/nsswitch.conf, glibc is always using DNS. Therefore, when sendmail, running on the local box, tries to connect to the FQDN of the local box, it pulls the eth0 IP from DNS instead of the 127.0.0.1 from /etc/hosts, and it can't connect. Interestingly enough, if I change /etc/nsswitch.conf to: hosts: files [NOTFOUND=return] dns then getaddrinfo() actually returns the correct IP from /etc/hosts (which seems contrary to the meaning of "NOTFOUND"). Of course, if I do this, then I cannot resolve any names from DNS whatsoever... Please fix! I pay cash bribes under the table as necessary. ;-)
Try it with RHL9. Running the test program on an RHL9 system with an nsswitch.conf entry like hosts: files dns does not show any DNS activity in the strace log.