Bug 9871 - getaddrinfo() isn't obeying search rules...
Summary: getaddrinfo() isn't obeying search rules...
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glibc
Version: 8.0
Hardware: i386
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 2000-02-29 21:45 UTC by Rob Seace
Modified: 2016-11-24 14:49 UTC (History)
2 users (show)

Clone Of:
Last Closed: 2003-04-21 23:54:11 UTC

Attachments (Terms of Use)
Test program to illustrate getaddrinfo()'s misbehavior... (2.35 KB, text/plain)
2000-03-13 17:16 UTC, Rob Seace
no flags Details

Description Rob Seace 2000-02-29 21:45:20 UTC
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

Comment 1 Rob Seace 2000-03-13 17:16:59 UTC
Created attachment 152 [details]
Test program to illustrate getaddrinfo()'s misbehavior...

Comment 2 Cristian Gafton 2000-05-22 14:52:59 UTC
assign to jakub

Comment 3 Ryan Koski 2002-12-26 17:41:56 UTC
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  Even though I have both the FQDN and short
hostname assigned to 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 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. ;-)

Comment 4 Ulrich Drepper 2003-04-21 23:54:11 UTC
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.

Note You need to log in before you can comment on or make changes to this bug.