在 IPv6 中使用 resolv.h 的名称解析器 [英] Using the name resolver of resolv.h with IPv6

查看:12
本文介绍了在 IPv6 中使用 resolv.h 的名称解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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).

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

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.)

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

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

显然,很久以前,在 FreeBSD 中有一个带有这个的 _res_ext能力,但我在最近的 FreeBSD 7 (grep_res_ext/usr/include/resolv.h 什么也没找到).你仍然可以找到使用它的代码(自己试试使用 Google Codesearch).

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).

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

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.

推荐答案

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

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 - 支持 BIND 9 库,它有一个 res_setservers() 函数,它可以获取 IPv6 地址,没有 _res._ext 扩展名.

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

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().

编辑 - 还有 CVS 存储库对于 FreeBSD,FreeBSD 7.0(参见标签 FREEBSD_7_0_0_RELEASE)也支持来自 Bind 9 的 res_setservers().

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.

这篇关于在 IPv6 中使用 resolv.h 的名称解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆