IPv6地址到域名

发布于 2024-11-06 21:36:50 字数 571 浏览 3 评论 0原文

我正在寻找一个以 IPv6 地址作为参数并返回域名的函数。

明确地说,2a00:1450:8006::68 返回 ipv6.google.com。

(目的是将此域名提供给 getaddrinfo 函数。)

谢谢:-)

edit1 :我尝试过 getaddrinfo("2a00:1450:8006::68", "http", NULL, &result ); ,它返回“不支持主机名的地址族”并且 getaddrinfo("ipv6.google.com", "http", NULL, &result); 返回错误“没有地址与常用名称关联”。

EDIT2:我同意你的观点,我的 IPV6 系统有问题,我尝试过 http://test-ipv6.com / 似乎我没有 IPV6 地址,但使用 ifconfig 它返回:

adr inet6: fe80::15b:fcff:fe65:d516/64 Scope:Lien

I'm searching for a function that take an IPv6 address as argument and returns the domain name.

To make it clear, 2a00:1450:8006::68 returns ipv6.google.com.

(The aim is to give this domain name to the getaddrinfo function.)

Thanks :-)

edit1 : I've tried getaddrinfo("2a00:1450:8006::68", "http", NULL, &result); , it returns "address family for hostname not supported" and getaddrinfo("ipv6.google.com", "http", NULL, &result); return an error "no address is associated with hotname".

EDIT2 : I agree with you, i've trouble with IPV6 system, I've tried http://test-ipv6.com/ and it appears that I've got no IPV6 adress but with ifconfig it returns :

adr inet6: fe80::15b:fcff:fe65:d516/64 Scope:Lien

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

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

发布评论

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

评论(2

冷弦 2024-11-13 21:36:50

我认为您没有有效的 IPv6 配置。 getaddrinfo() 只会返回可访问的 IPv6 答案,因此,如果您的系统没有具有全局范围的 IPv6 地址以及到已解析地址的路由,则结果将从结果集中删除。

基本思想是,您调用 getaddrinfo 一次并获取要连接的地址列表 - 如果该列表包含无法访问的地址,则程序在尝试另一个地址之前必须先遇到超时。

“不支持主机名的地址族”意味着它已识别出该地址是不需要通过 DNS 解析的 IPv6 地址,因此它尝试将其与允许的地址族列表进行匹配,失败并返回错误。

解析主机名会尝试获取主机名的“A”记录,因为这适用于本地支持的唯一地址族。不存在这样的记录,因此返回不存在记录的信息。由于它从未要求过 IPv6 地址(这毫无意义),因此它不会抱怨此处的地址族不匹配。

I think you do not have a valid IPv6 configuration. getaddrinfo() will only return IPv6 answers that are reachable, so if your system does not have an IPv6 address with global scope and a route to the resolved address, the result will be removed from the result set.

The basic idea is that you call getaddrinfo once and get a list of addresses to connect to -- if that list were to include unreachable addresses, programs would have to run into a timeout first before trying another address.

"Address family for hostname not supported" means that it has recognized that the address is an IPv6 address that need not be resolved via DNS, so it tries to match it against the list of allowed address families, fails and returns the error.

Resolving the host name attempts to get an "A" record for the host name, as that is appropriate for the only address family supported locally. No such record exists, hence it returns the information that no record exists. Since it never asked for the IPv6 address (that would have been pointless), it doesn't complain about the address family mismatch here.

ヅ她的身影、若隐若现 2024-11-13 21:36:50

您使用 getaddrinfo 作为第一步是正确的,但它无法为您进行反向 DNS 查找。您需要使用 getaddrinfo 将地址的字符串形式转换为 sockaddr,然后您可以将其传递给 getnameinfo 来执行以下操作:反向查找。

话虽如此,我认为卡尔的评论也是相关的。您的系统似乎配置为不支持 IPv6...

You're right to use getaddrinfo as the first step, but it cannot do reverse-dns lookups for you. You'll need to use getaddrinfo to convert the string form of the address to a sockaddr, which you can then pass to getnameinfo to do the reverse lookup.

With that said, I think Carl's comment is also relevant. It seems like your system is configured not to support IPv6...

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