gethostbyname fails for local hostname after resuming from hibernate (Vista+7?)
- by John
Just wondering if anyone else has spotted this:
On some user's machines running our software, occasionally the call to Win32 winsock gethostbyname fails with error code 11004.
For the argument to gethostbyname, I'm passing in the result from gethostname.
Now the docs say 11004 is WSANO_DATA. None of the descriptions seem to be relevant (it occurs if you pass in an IP6 address, but as I say, I'm passing in a hostname).
Even more interesting is that the MSDN suggests that this combination (gethostname followed by gethostbyname) should never fail, not even if there is no IP address (in that case it would just return empty list of IPs). Here is the quote from the gethostname MSDN entry:
...it is guaranteed that the name returned will be successfully parsed by gethostbyname and WSAAsyncGetHostByName.
It only ever happens after resuming from hibernate, in that short period when the network is restarting, and only on Vista/7 (well I've only seen it on Vista and 7).
One theory I had was that it related to IP6. Maybe for a short period the network reports an IP6 address but not the corresponging IP4 address (I'm pretty sure that all the client machines are dual IP stack, but I could be wrong).
I tried to reproduce by turning off my network card (to force no IP addresses) and couldn't reproduce.
Anyone seen this before?
Any ideas?
John