Bug 215283 - gethostbyname() fails to resolve "localhost" in FC6
gethostbyname() fails to resolve "localhost" in FC6
Status: CLOSED RAWHIDE
Product: Fedora
Classification: Fedora
Component: glibc (Show other bugs)
6
All Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2006-11-13 04:01 EST by Tim
Modified: 2007-11-30 17:11 EST (History)
1 user (show)

See Also:
Fixed In Version: 2.5.90-7
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2006-11-20 11:30:50 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
C code to demonstrate problem (587 bytes, text/plain)
2006-11-13 04:01 EST, Tim
no flags Details

  None (edit)
Description Tim 2006-11-13 04:01:01 EST
Description of problem:

In FC6, calls to gethostbyname(3) with an argument of "localhost" fail to
resolve the name. Actually this seems to be a problem with the version of
/etc/hosts that is provided out-of-the-box, but I'm not sure what category
addresses such problems. The out of the box hosts file is:

# Do not remove the following line, or various programs
# that require network functionality will fail.
::1             slab    localhost.localdomain   localhost

appending a new line

127.0.0.1       slab    localhost.localdomain   localhost

fixes the problem.

Version-Release number of selected component (if applicable):

[tim@slab ~]$ uname -a
Linux slab 2.6.18-1.2849.fc6 #1 SMP Fri Nov 10 12:45:28 EST 2006 i686 i686 i386
GNU/Linux
[tim@slab ~]$ /lib/libc.so.6 
GNU C Library stable release version 2.5, by Roland McGrath et al.

How reproducible:

100% on FC6 updated as of today. The problem does not exist in current
installations of FC5, but then the /etc/hosts file for FC5 contains the IPv4
address format.

Steps to Reproduce:
1. Build the attached program
2. Run with the argument "localhost"
3.
  
Actual results:

[tim@slab src]$ ./resolve localhost
main/gethostbyname(): Unknown host

Expected results:

[tim@slab src]$ ./resolve localhost
OK: 127.0.0.1

Additional info:

The name "localhost." (with the dot) does resolve properly, so this may actually
be an issue with glibc, but I'm inclined to think it's a hosts file issue.

This problem impacts certain applications that use TCP or UDP for client/server
interaction on the local system (e.g. Kismet).
Comment 1 Tim 2006-11-13 04:01:02 EST
Created attachment 141024 [details]
C code to demonstrate problem
Comment 2 Tobias Oed 2006-11-19 19:31:06 EST
Same here and a couple other people I know have had the same problem. Tested
with the standard resoveip localhost
Tobias


Comment 3 Ulrich Drepper 2006-11-19 22:28:57 EST
This isn't really a bug.  The hosts file specifies an IPv6 address and
gethostbyname() queries for an IPv4 address.  The result is a failure by design.

However, there is no problem to change this.  It won't break anything and
prevent user mistakes like this from causing problems.  I've changed the cvs
archive upstream, the change will be in the next rawhide build.

But take this as an indication that the program which has this problem is
broken.  Every program should simply use getaddrinfo() and now of the getby* crap.
Comment 4 Jakub Jelinek 2006-11-20 11:30:50 EST
This is in glibc-2.5.90-7 in rawhide.

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