Mark H Weaver <m...@netris.org> skribis: > l...@gnu.org (Ludovic Courtès) writes: > >> So /etc/hosts is not enough for reverse lookups to work. >> >> With nscd turned off, I tried this: >> >> guile -c '(pk (gethostbyaddr (inet-pton AF_INET "127.0.0.1")))' >> >> If nsswitch.conf is removed, then that resolves to “localhost” (instead >> of the actual host name.) > > As John said, it should resolve to "localhost". It certainly should > _not_ resolve to the actual host name.
Right, but my /etc/hosts has “localhost” plus another name for 127.0.0.1. >> If, in addition, resolv.conf is removed, then that fails as seen above. >> >> With nsswitch.conf alone, it resolves correctly (Mark was right.) >> And this works with only “hosts: files” in nsswitch.conf. > > When you say "it resolves correctly", which name does it resolve to? Whatever /etc/hosts suggests. >> It’s surprising that there’s this discrepancy between how NSS works for >> getaddrinfo and for gethostbyaddr. At any rate, we may be able to solve >> this at the libc level. > > Solve what? What are you thinking of changing in libc? The issue is that the default config for the ‘hosts’ database when resolv.conf is missing is (see nss/hosts-lookup.c): dns [!UNAVAIL=return] files When doing a host name lookup, ‘dns’ is unavailable, so we go on with ‘files’ and /etc/hosts is honored as expected. However, when doing a reverse lookup, the DNS resolver (__libc_res_nquery) returns ‘notfound’, and so ‘gethostbyaddr’ returns immediately. Changing the ‘hosts’ config to “dns files” solves this particular. I’ll ask for advice on libc-help. Thanks, Ludo’.