gethostbyaddr without /etc/{resolv,nsswitch}.conf

Ludovic Courtès ludo@gnu.org
Sun Jan 19 16:07:00 GMT 2014


Hello,

Guix builds packages in Linux containers where only ‘lo’ is available,
/etc/{nsswitch,resolv}.conf are missing, and /etc/hosts maps 127.0.0.1
to ‘localhost’.

In that context, looking up ‘localhost’ works fine.
However, gethostbyaddr("127.0.0.1") fails with TRY_AGAIN.


The problem stems from the fact that the default config for the ‘hosts’
database when resolv.conf is missing is (from nss/hosts-lookup.c):

  dns [!UNAVAIL=return] files

When doing a host name lookup, ‘dns’ returns NSS_STATUS_UNAVAIL, so we
go on with ‘files’ and /etc/hosts is honored as expected.

Conversely, when doing a reverse lookup, the DNS name service returns
NSS_STATUS_NOTFOUND, and so ‘gethostbyaddr’ returns the error directly.

(Of course, changing the ‘hosts’ config to “dns files” solves this
particular problem.)


Should the DNS name service always return NSS_STATUS_UNAVAIL when
resolv.conf is missing?  Or should the default config for reverse hosts
lookups be “dns files”?  Or...?

Thanks,
Ludo’.



More information about the Libc-help mailing list