On Sun, Oct 06, 2013 at 01:30:09PM -0500, Derek Martin wrote: > > My system has several IP addresses and several > > hostnames (depending on interface/network). > > Wrong, it has exactly one hostname, as does > every TCP/IP-networked host. It may have > several domain names corresponding to the > multiple IPs on your machine... those are not > hostnames, they are domain names.
You have several hostnames or A records or domain names or whatever. Then you have `hostname`, which is configured in kernel, at least in Linux (cat /proc/sys/kernel/hostname), which may match some A record, or not. Or match partially. Your method does not even do that. It simply resolves kernel's notion of hostname in configured domains, and can still return A record the host doesn't actually own. Just imagine that there was no such thing as `hostname` in kernel. How would you do your patch? You could get all IP addresses of all interfaces and try to resolve them via NSS/DNS, then take the result you like the most (1st one for example, or the longest one). Or you could try to find the 1st/cheapest default route and take source IP address corresponding to this route (if there's such a notion in your UNIX), and resolve it. P.S. I do not propose to implement anything of the mentioned above, it's JFYI. -- With best regards, xrgtn