Henrik Nordstrom wrote:
[...]What I have seen in portabe code is two paths:
1. Local IP known
gethostbyaddr(ip)
2. Local IP not known (or above failed)
hostname() to get the local hostname gethostbyname() to resolve it into a fqdn.
The above works in all OS:es I have heard of.
Only that it doesn't work in the general case.
I have seen enough machines where the hostname is not related to the names for its IP address(es) at all -- and those may be a number of quite different ones, even in different top-level domains. In this case it is even likely that no default search domain is configured, causing the abovementioned method to fail anyway.
In the general case, there is no such thing as *the* FQDN of a host.
Regards, Juergen.
-- Juergen Nickelsen <juergen.nickelsen@Netzwert.AG> Netzwert AG * An den Treptowers 1, D-12435 Berlin Fon +49.30.5900.80-1112 * Fax +49.30.5900.800-700 - : send the line "unsubscribe linux-net" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html