1

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?

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219

2 Answers2

2

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 ...
seva titov
  • 11,720
  • 2
  • 35
  • 54
  • The lets me resolve `ipv6.google.com`, but then `stackoverflow.com` doesn't resolve. i still need to solve the issue of how `nslookup` can manage it. – Ian Boyd May 26 '12 at 19:14
  • i figured out *how* `nslookup` accomplishes its task. It runs an `A` query, then separately does an `AAAA` lookup. So i *have* to call `getaddrinfo` twice, once for IPv6 then again for IPv4. – Ian Boyd May 26 '12 at 21:58
  • 1
    Try setting `hints.ai_family` to `AF_UNSPEC` to allow `getaddrinfo()` to query both IPv4 and IPv6 information at the same time. – Remy Lebeau May 28 '12 at 04:22
  • @RemyLebeau Setting family to AF_UNSPEC does not help. i thought maybe family should be a bit-flag (`AF_INET6 or AF_INET`); but it *isn't* a bitwise flag. – Ian Boyd Jun 01 '12 at 20:35
  • 1
    No, it is not a bitmask. [The documentation](http://msdn.microsoft.com/en-us/library/windows/desktop/ms738520.aspx) clearly states: "A value of AF_UNSPEC for ai_family indicates the caller will accept any protocol family. This value can be used to return both IPv4 and IPv6 addresses for the host name pointed to by the pNodeName parameter. On Windows Server 2003 and Windows XP, IPv6 addresses are returned only if IPv6 is installed on the local computer." – Remy Lebeau Jun 01 '12 at 21:52
1

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

Ben
  • 15
  • 2