问题
i can trying to use GetAddrInfo to resolve ipv6.google.com:
wsaError = getaddrinfo("ipv6.google.com", null, null, ref addrInfo);
The returned socket error code is 11001
(No such host is known).
Note: The deprecated legacy function GetHostByName does not support IPv6. It has been replaced with GetAddrInfo.
The strange thing is that i can use nslookup
and it can find the address just fine:
Question
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
Authoritative Answer
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)
Non-authoritative question
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
Non-authoritative answer
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
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?
回答1:
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 ...
回答2:
I had similar issues, wasn't a problem with the code, but the operating system. The following command meant windows resolved the IPv6 addresses correctly instead of giving a WSANO_DATA error:
Netsh interface teredo set state enterpriseclient
Source:
http://netscantools.blogspot.co.uk/2011/06/ipv6-teredo-problems-and-solutions-on.html
来源:https://stackoverflow.com/questions/10767107/getaddrinfo-cannot-resolve-ipv6-google-com-but-nslookup-can