将 resolv.h 的名称解析器与 IPv6 一起使用

发布于 2024-07-10 22:11:08 字数 1096 浏览 6 评论 0 原文

我编写或修改执行名称解析的程序并需要 过程控制良好。 所以我不使用getaddrinfo(),我去 更深入并在 resolv.h 中使用 res_query() / res_send() / 等,已记录 在解析器(3)中。

尽管没有记录,但设置解析器的常用方法是 更新_res.nsaddr_list。 但是这个数组,在 resolv.h 中定义,存储 struct sockaddr_in,仅是 IPv4 地址。 (IPv6 地址 是 struct sockaddr_in6 ,独立于系列的系统将使用 struct sockaddr 。)

我正在寻找一种方法(最好是可移植的,至少在 各种 Unix)告诉 _res 我也想要 IPv6 地址。

显然,很久以前,FreeBSD 中有一个 _res_ext 与此 能力,但我在最近的 FreeBSD 7 中找不到它了(grep _res_ext /usr/include/resolv.h 找不到任何内容)。 你仍然可以找到 使用它的代码(自己尝试使用 Google Codesearch )。

感谢 Alnitak,我注意到它现在显然是 _res._ext 而不是 .res_ext。 我想知道这些事情在哪里记录或宣布...我不知道 _res._ext 的可移植性如何。 我可以在 Debian 和 FreeBSD 上找到它。 似乎很少有程序使用它。

I write or modify programs which perform name resolution and need a
good control of the process. So I do not use getaddrinfo(), I go
deeper and use res_query() / res_send() / etc in resolv.h, documented
in resolver(3).

Although not documented, the common way to set the resolver used is to
update _res.nsaddr_list. But this array, defined in resolv.h, stores
struct sockaddr_in, that is IPv4 addresses only. (IPv6 addresses
are struct sockaddr_in6, a family-independant system would use struct sockaddr.)

I'm looking for a way (preferrably portable, at least among the
various Unix) to tell _res that I want also IPv6 addresses.

Apparently, a long time ago, there was in FreeBSD a _res_ext with this
ability but I cannot find it anymore in a recent FreeBSD 7 (grep
_res_ext /usr/include/resolv.h
finds nothing). You can still find
code which uses it (try yourself with Google Codesearch).

Thanks to Alnitak, I noticed it is apparently now _res._ext and not .res_ext. I wonder where these sort of things are documented or announced... I have no idea how portable _res._ext is. I can find it on Debian and FreeBSD. It seems there are few programs which use it.

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

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

发布评论

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

评论(2

壹場煙雨 2024-07-17 22:11:08

Stéphane - 如果您的 resolv.h 不包含对 sockaddr_in6 的任何支持,那么这表明在您的特定操作系统上,解析器本身不支持 IPv6 传输。

我在这里检查了我的一些系统:

  • MacOS X 10.5.6 - 支持 BIND 9 库,该库具有 res_setservers() 函数,可以采用 IPv6地址,无 _res._ext 扩展名。

  • CentOS 5.2 - 具有 _res._ext 扩展名,尽管 resolv.conf 的手册页中没有提及 IPv6,只是有一个设置告诉解析器在查找 gethostbyname() 的 A 记录之前返回 AAAA 记录。

编辑 - 另外,FreeBSD 的 CVS 存储库 建议FreeBSD 7.0(请参阅标记 FREEBSD_7_0_0_RELEASE)也支持 Bind 9 中的 res_setservers()

Stéphane - if your resolv.h doesn't include any support for sockaddr_in6 then that suggests that on your particular O/S the resolver does not itself support IPv6 transport.

I've checked some of my systems here:

  • MacOS X 10.5.6 - supports the BIND 9 library, which has a res_setservers() function which can take IPv6 addresses, no _res._ext extension.

  • CentOS 5.2 - has the _res._ext extension, although there's no mention of IPv6 in the man page for resolv.conf except that there's a setting to tell the resolver to return AAAA records before looking for A records for gethostbyname().

EDIT - also, the CVS repository for FreeBSD suggests that FreeBSD 7.0 (see tag FREEBSD_7_0_0_RELEASE) does also support res_setservers() from Bind 9.

仅冇旳回忆 2024-07-17 22:11:08

glibc:

res_setservers: no
__res_state._u._ext.nsaddrs
__res_state._u._ext.nsmap

根据以下内容将后者设置为 MAXNS+1:

http:// sourceware.org/ml/libc-hacker/2002-05/msg00035.html

BSD-libc:

res_setservers: yes
__res_state._u._ext.__res_state_ext

对我来说似乎很混乱,您可能需要 autoconf。

glibc:

res_setservers: no
__res_state._u._ext.nsaddrs
__res_state._u._ext.nsmap

set the latter to MAXNS+1 according to:

http://sourceware.org/ml/libc-hacker/2002-05/msg00035.html

BSD-libc:

res_setservers: yes
__res_state._u._ext.__res_state_ext

Seems messy to me and you'll probably need autoconf.

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