- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我们的应用程序 (RHEL 5/c++) 使用 gethostid
返回的 hostid 进行日志记录。由于某种原因,本地网络环境的主DNS服务器掉线了。这导致 gethostid
出现大量问题:函数调用挂起超过 60 秒,这导致我们的应用程序内部超时。几分钟后,在命令行上调用 hostid
也没有返回。一旦 DNS 服务器再次启动,应用程序和 hostid
命令行工具中的超时/问题都消失了。
我的问题是:如何防止 gethostid
进行 DNS 查找?答案有一些边界条件:
/etc/hostid
不能存在。sethostid
。/etc/hosts
。我很惊讶这种事情发生了。据我了解 gethostid
它的工作原理是这样的:
sethostid
的值。我认为不需要 DNS 查询。
要验证 gethostid
实际上依赖于工作中的 DNS 服务器,试试这个:
nameserver
条目。hostid
。在我的 debian/squeeze 安装中,这导致 hostid 为 00000000
而没有任何挂起。我假设 hostid
的 RedHat 版本不同/较旧,结果挂起。
最佳答案
我认为在不破坏系统或违反其中一个边界条件的情况下,阻止 gethostid
的 DNS 查找是不可能的。在 gnu.org我在 sethostid
函数上找到了这条评论:
The proper way to establish the primary IP address of a system is to configure the IP address resolver to associate that IP address with the system's host name as returned by gethostname. For example, put a record for the system in /etc/hosts.
据此我得出结论,gethostid
像这样确定 IP:
gethostname
获取主机名。gethostbyname
(或类似方法)确定 IP。在主机名未与 /etc/hosts
和 /etc/nsswitch.conf
中的 IP 地址相关联的情况下,允许 DNS 查找,一个 DNS查找将由 gethostid
进行。
关于linux - 如何防止 gethostid 在 linux 上进行 DNS 查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9258228/
我正在移植使用 的 Linux 代码,特别是 gethostid 函数,适用于 Windows 7。 我需要将在我的应用程序中使用的唯一编号的 32 位。如何以与在 Linux 上相同的方式使用 W
我们的应用程序 (RHEL 5/c++) 使用 gethostid 返回的 hostid 进行日志记录。由于某种原因,本地网络环境的主DNS服务器掉线了。这导致 gethostid 出现大量问题:函数
我是一名优秀的程序员,十分优秀!