Networking Forums

Networking Forums > Computer Networking > Linux Networking > call gethostbyname() after device reacquires IP address

Reply
Thread Tools Display Modes

call gethostbyname() after device reacquires IP address

 
 
Marco Wang
Guest
Posts: n/a

 
      03-14-2007, 02:23 PM
Hello,

I am working on writing code for a networking device. The device is
linux based. Now I encounter a problem:

1. The device is powered on and application started, but network cable
is unplugged;
2. Application on device calls gethostbyname() or something like that
to get IP address;
3. As network cable is unplugged, the device failed to acquire DHCP IP
address (including DNS info);
4. So gethostbyname() failed to resolve remote host name;
5. Plug network cable into device, the device will get IP/DNS info
sooner or later;
6. But gethostbyname() still won't work unless the process is
restarted;

I know gethostbyname() retrieves host/network info only once when it
is invoked the first time, so I use res_init() to solve this issue,
then gethostbyname() will return correct information, but it takes too
long: around 30 seconds. Anyone has any idea why such 30 seconds
occurs? TIA.

Thanks,
Marco Wang

 
Reply With Quote
 
 
 
 
Rick Jones
Guest
Posts: n/a

 
      03-14-2007, 05:38 PM
It isn't really an answer to your question, but new code really should
be using getaddrinfo() rather than gethostbyname().

As for the rest of it, perhaps some system call tracing would help -
run your application under strace and look at the system calls being
made - that may help tell you want is going-on/wrong.

If I were to guess, it would be that gethostbyname() and the resolver
libraries were caching bogus DNS server information - if DHCP didn't
provide an IP address to the NIC, it likely didn't provide DNS server
information to go into /etc/resolv.conf either.

rick jones
--
a wide gulf separates "what if" from "if only"
these opinions are mine, all mine; HP might not want them anyway...
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...
 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ip address and the device Zheng Da Linux Networking 3 12-28-2006 10:56 AM
A device with only IP address? SaranJothy Linux Networking 7 11-16-2006 03:32 PM
Changing a router's IP address required a call to SBC! Why?! benn686@hotmail.com Wireless Internet 3 09-20-2005 04:48 PM
Structure of name, userid, address of whatever you call it Mike Kingston Broadband 9 11-19-2004 07:50 PM
secure (g)libc gethostbyname project2501 Linux Networking 4 08-03-2004 04:57 PM



1 2 3 4 5 6 7 8 9 10 11