从休眠状态恢复后,gethostbyname 获取本地主机名失败(Vista+7?)

发布于 2024-08-19 06:55:19 字数 759 浏览 4 评论 0原文

只是想知道其他人是否发现了这一点:

在某些运行我们软件的用户计算机上,有时对 Win32 Winsock gethostbyname 的调用会失败,错误代码为 11004。

对于 gethostbyname 的参数,我传入结果来自gethostname

现在文档说 11004 是 WSANO_DATA。所有描述似乎都不相关(如果您传入 IP6 地址,则会发生这种情况,但正如我所说,我传入的是主机名)。

更有趣的是,MSDN 建议这种组合(gethostname 后跟 gethostbyname)永远不会失败,即使没有 IP 地址(在这种情况下,它只会失败)返回空的 IP 列表)。以下是来自 gethostname MSDN 条目的引用:

...保证返回的名称能够被gethostbyname和WSAAsyncGetHostByName成功解析。

它只发生在从休眠状态恢复后,在网络重新启动的短时间内,并且仅在 Vista/7 上(好吧,我只在 Vista 和 7 上看到过它)。

我的一种理论是它与 IP6 有关。也许在短时间内网络会报告 IP6 地址,但不会报告相应的 IP4 地址(我很确定所有客户端计算机都是双 IP 堆栈,但我可能是错的)。

我尝试通过关闭网卡(强制没有 IP 地址)来重现,但无法重现。

有人以前见过这个吗?

有什么想法吗?

约翰

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦过后 2024-08-26 06:55:19

我认为你已经被边缘案例所困扰了。

归根结底,执行诸如休眠之类的操作是高级操作 - 将 PC 恢复到其确切状态并继续运行,就好像什么也没发生一样。这一切都很好,但有些东西将无法幸存,例如任何需要回复的网络连接,以及任何严重低级的“你不能设置我只读我”寄存器中央处理器。

我建议你联系微软并询问他们是否知道这件事。如果它适用于其他操作系统,他们很可能有兴趣修复 7/Vista。只需准备好交出二进制文件,以便他们可以无限地测试它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文