0

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

John
  • 1,974
  • 2
  • 25
  • 32
  • I think you're misinterpreting the documentation. 1) The `gethostname` documentation doesn't say that it will never fail, only that when it succeeds its output will be able to be *parsed* by `gethostbyname`. 2) `gethostbyname` failing does not imply that it is failing to *parse* its input (that you are sending from `gethostname`). It may be successfully *parsing* the input but failing to resolve the name to an address. – nobody Mar 31 '10 at 00:54
  • I disagree. Here is what "gethostname" says in MSDN: "Note If no local host name has been configured, gethostname must succeed and return a token host name that gethostbyname or WSAAsyncGetHostByName can resolve." To me the phrase "resolve" implies something stronger than merely "parsing" – John Mar 31 '10 at 10:50

1 Answers1

1

I think you've been bitten by an edge case.

At the end of the day doing something like hibernate is advanced stuff - restoring a PC to its exact state and continuing as if nothing had happened. Thats all well and good, but some things won't have survived, such as any network connections that expected a reply, and any seriously low-level-you-can't-set-me-only-read-me registers in the CPU.

I suggest you contact Microsoft and ask them if they know about this. If it works for other OSes they will most likely be interested in fixing it for 7/Vista. Just be prepared to hand over a binary so they can test it ad-infinitum.

Stephen Kellett
  • 3,078
  • 1
  • 22
  • 25
  • Great thanks - do you have experience of submitting bugs to MS? I've always assumed it was really painful... – John Mar 31 '10 at 10:47
  • Sorry, I don't. In my dealings with Microsoft I have found them to be an opaque organisation, very hard to deal with. Not hard as in awkward, just hard as in MS seems to reorganise teams on a regular basis and if you are a casualty of that, tough. I've had it happen to me twice. Even on the odd occasion I got the agreement from the IE team for them to provide a profiling API for IE the team was disbanded before the work could be completed. Its frustrating, I wish you all the best trying to make contact. Maybe my experience is atypical? – Stephen Kellett Mar 31 '10 at 11:45