Medium: exportfs: Use canonical hostname for monitor
If the hostname specified in clientspec does not match the canonical
hostname, the monitor operation fails even though the export exists.
This is caused by the exportfs command's name resolution process. It
queries the hosts DB as configured in /etc/nsswitch.conf (usually
/etc/hosts and/or DNS) to ensure that the given hostname resolves.
If the lookup returns the FQDN and the clientspec uses the short name,
the monitor operation fails. This also occurs in reverse. If the lookup
returns the short name and the clientspec uses the FQDN, the monitor
operation fails.
This patch resolves the issue by querying the ahosts database to fetch
the canonical hostname. We use the canonical hostname as the spec. If
the clientspec is an IP address, the fetch simply returns the same IP
address. If the clientspec is of some other format, the fetch returns
nothing and we continue to use the spec as-is.
Using getent ahosts rather than getent hosts eliminates the need to
handle IP addresses specially, thanks to its output formatting. It uses
getaddrinfo rather than gethostbyname2.