1748248 Members
3622 Online
108760 Solutions
New Discussion юеВ

gethostbyaddr call

 
Marc Bohnert
Advisor

gethostbyaddr call

I am running on HPUX-11.

I am using dns (have resolv.conf and nsswitch.conf set up)

I have a server process that accepts client connections and prior to forking a child process does a gethostbyaddr call (which retrieves host name info about the client via dns). The server goes back to waiting for more client connections. The problem is when dns is down the gethostbyaddr call hangs until until dns times out. I tried removing the resolv.conf and nsswitch.conf files but it still hangs. It appears that the gethostbyaddr remembers that dns was being used even though I removed the dns files (is it caching something). The only solution is to stop and restart the server process.

My question: Is there a way other than stopping my server process for gethostbyaddr call to know that I am no longer using dns? What is the gethostbyaddr doing?


Thanks,
Marc
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor

Re: gethostbyaddr call

Hi Marc,

gethostbyaddr() does just what its name implies. It looks up the host data by IP Address rather than hostname. If you add a signal handler to your code, you could do a second res_init() to force a re-read of /etc/resolv.conf and /etc/nsswitch.conf.
But I have to tell you that is really, really dumb; the best answer is to add at least a second DNS server and list it in resolv.conf.
In any case, you should be able to have nsswitch.conf try DNS first then go to /etc/hosts and the resolver functions should work albeit with delays if DNS is down.

P.S. I suspect that you would have gotten replies much sooner if you had a better history of assigning points.

Regards, Clay
If it ain't broke, I can fix that.
Bill Hassell
Honored Contributor

Re: gethostbyaddr call

The second DNS server won't eliminate the timeout for a dead server. That's why a DNS server is so critical for every system in the network. A better alternative is to use hosts first, then DNS. Put your critical system names and addresses into /etc/hosts and leave DNS to the occasional system connection.

Note also that using hosts first can significantly reduce network overhead for network backups as most commercial tools call gethostbyaddr for EVERY file that is backed up. Put the name(s) of remote systems involved in backups into /etc/hosts and change nsswitch.conf to hosts then DNS.


Bill Hassell, sysadmin
Magdi KAMAL
Respected Contributor

Re: gethostbyaddr call

Hi Marc,

To work arround this problem, I suggess to load hostnames and IP addresses first in a dynamic structure ( within an initializing procedure ) resolving names in DNS first and second from /etc/hosts. And replace your gethostbyaddr by gethostbyaddr_from_struct.

Bye