以编程方式获取主机的 DNS 服务器

发布于 2024-09-02 17:37:18 字数 778 浏览 1 评论 0原文

我想使用 C++ 获取主机在三种操作系统上使用的 DNS 服务器:OS X、FreeBSD 和 Windows。我想确认以下方法确实是最佳实践,如果不是,则是更好的选择。

预先感谢你的帮助!

Using C++, I would like to obtain the DNS servers being used by a host for three operating systems: OS X, FreeBSD, and Windows. I'd like confirmation that the approaches below are indeed best practice, and if not, a superior alternative.

Thanks in advance for your help!

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

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

发布评论

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

评论(1

月下凄凉 2024-09-09 17:37:18

在许多 UNIX 系统(linux、bsd)上,您可以使用解析器函数来获取 DNS 服务器列表: man 3 解析器

调用res_init()后,解析器结构被初始化。解析器结构存储您需要的所有信息。 DNS 服务器列表存储在结构条目 nsaddr_list 中。

解析器结构的确切规范很可能可以在 resolv.h 中找到。

使用解析器函数是获取 DNS 服务器列表的首选方法。 res_init() 很可能会使用 /etc/resolv.conf 中找到的信息填充解析器结构。

另请参阅resolv.h 的使用

On many unix systems (linux, bsd) you can use the resolver functions to obtain the list of DNS servers: man 3 resolver.

After calling res_init() the resolver structure is initialized. The resolver structure stores all the information you need. The list of DNS servers are stored in the struct entry nsaddr_list.

The exact specification of the resolver structure can most likely be found in resolv.h.

Using the resolver functions is the preferred way to obtain the list of DNS servers. res_init() will most likely fill the resolver structure with the information found in /etc/resolv.conf.

Also see Use of resolv.h

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