GetAddrInfo无法解析ipv6.google.com(但是nslookup可以) [英] GetAddrInfo cannot resolve ipv6.google.com (but nslookup can)
问题描述
我可以尝试使用 GetAddrInfo
来解决 ipv6。 google.com
:
i can trying to use GetAddrInfo
to resolve ipv6.google.com
:
wsaError = getaddrinfo("ipv6.google.com", null, null, ref addrInfo);
返回的套接字错误代码为 11001
The returned socket error code is 11001
(No such host is known).
注意:已弃用的旧版功能
GetHostByName
不支持IPv6。已被的getaddrinfo
。
Note: The deprecated legacy function
GetHostByName
does not support IPv6. It has been replaced withGetAddrInfo
.
奇怪的是,我可以使用 nslookup
,它可以找到地址很好:
The strange thing is that i can use nslookup
and it can find the address just fine:
问题
SendRequest(), len 33
HEADER:
opcode = QUERY, id = 4, rcode = NOERROR
header flags: query, want recursion
questions = 1, answers = 0, authority records = 0, additional = 0
QUESTIONS:
ipv6.google.com, type = A, class = IN
权威答案
Got answer (106 bytes):
HEADER:
opcode = QUERY, id = 4, rcode = NOERROR
header flags: response, want recursion, recursion avail.
questions = 1, answers = 1, authority records = 1, additional = 0
QUESTIONS:
ipv6.google.com, type = A, class = IN
ANSWERS:
-> ipv6.google.com
type = CNAME, class = IN, dlen = 9
canonical name = ipv6.l.google.com
ttl = 21743 (6 hours 2 mins 23 secs)
AUTHORITY RECORDS:
-> l.google.com
type = SOA, class = IN, dlen = 38
ttl = 30 (30 secs)
primary name server = ns4.google.com
responsible mail addr = dns-admin.google.com
serial = 1486713
refresh = 900 (15 mins)
retry = 900 (15 mins)
expire = 1800 (30 mins)
default TTL = 60 (1 min)
非权威性问题
SendRequest(), len 33
HEADER:
opcode = QUERY, id = 5, rcode = NOERROR
header flags: query, want recursion
questions = 1, answers = 0, authority records = 0, additional = 0
QUESTIONS:
ipv6.google.com, type = AAAA, class = IN
非授权答案
Got answer (82 bytes):
HEADER:
opcode = QUERY, id = 5, rcode = NOERROR
header flags: response, want recursion, recursion avail.
questions = 1, answers = 2, authority records = 0, additional = 0
QUESTIONS:
ipv6.google.com, type = AAAA, class = IN
ANSWERS:
-> ipv6.google.com
type = CNAME, class = IN, dlen = 9
canonical name = ipv6.l.google.com
ttl = 21743 (6 hours 2 mins 23 secs)
-> ipv6.l.google.com
type = AAAA, class = IN, dlen = 16
AAAA IPv6 address = 2607:f8b0:4009:801::1012
ttl = 270 (4 mins 30 secs)
------------
Name: ipv6.l.google.com
Address: 2607:f8b0:4009:801::1012
Aliases: ipv6.google.com
什么可以导致 nslookup
可以在 GetAddrInfo
不能?我可以使用 GetAddrInfo
做不同的工作吗?
What can cause nslookup
to be able to resolve an address when GetAddrInfo
cannot? And what can i do differently with GetAddrInfo
so it works?
推荐答案
尝试通过 pHints
参数中的 AF_INET6
来处理IPV6地址。这似乎对我有用:
Try passing AF_INET6
in pHints
parameter to work with IPV6 addresses. This seems to be working for me:
struct addrinfo *result = NULL;
struct addrinfo hints;
ZeroMemory( &hints, sizeof(hints) );
hints.ai_family = AF_INET6;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = IPPROTO_UDP;
dwRetval = getaddrinfo("ipv6.google.com", NULL, &hints, &result);
// check your dwRetval here ...
这篇关于GetAddrInfo无法解析ipv6.google.com(但是nslookup可以)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!