# libc resolver not stripping trailing dot for lookup in /etc/hosts



## mb2015 (Nov 28, 2015)

I want to make sure my expectation is correct before reporting this as a bug.

hostname(7) describes the libc resolver's operation (well, just the file-based / non-DNS part).

It begins by defining a hostname as a domain, i.e. "a dot-separated list of subdomains", an example for which is given on FreeBSD's version of this page with the explicit note "with no trailing dot".

The manpage goes on to say: "If the input name ends with a trailing dot, the trailing dot is removed, and the remaining name is looked up with no further processing."

In other words, conforming to RFC 1123 section 6.1.4.3, the trailing dot is OK as input to the resolver, in order to designate the domain as absolute; the name is just looked up in the /etc/hosts table as a literal string without the dot, without trying variations with appended search domains.

Thus, /etc/hosts entries should not have the trailing dot, and a lookup of a name with the dot should match an /etc/hosts entry without the dot. But on FreeBSD, that's not actually what happens; to get a match, the /etc/hosts entry must have the dot!

Below is a demonstration on FreeBSD (tested on 8.4 and 10.2) which assumes /etc/nsswitch.conf has its normal "host: files dns" line, and /etc/hosts has an entry for "localhost.my.domain" without the trailing dot.


```
# fetch http://beej.us/guide/bgnet/examples/showip.c
# cc -o showip showip.c

# ./showip localhost.my.domain.
getaddrinfo: hostname nor servname provided, or not known

# ./showip localhost.my.domain
IP addresses for localhost.my.domain:

  IPv4: 127.0.0.1
  IPv6: ::1
```

(showip.c is from _Beej's Guide to Network Programming Using Internet Sockets_. It just does a `getaddrinfo()` call on the given name.)

In contrast, if you run this same test on Debian 3.2, it works as expected, resolving with and without the dot. So I propose that FreeBSD match this behavior and work as documented in hostname(7).


----------



## junovitch@ (Nov 29, 2015)

I'm on vacation and don't have a variety of systems to look at how they comply with standards but your description sounds worthy of a bug report.  (https://bugs.FreeBSD.org/bugzilla/)


----------



## mb2015 (Dec 1, 2015)

OK, thanks. I posted it: PR 204927


----------

