【问题标题】:GetAddrInfo cannot resolve ipv6.google.com (but nslookup can)GetAddrInfo 无法解析 ipv6.google.com(但 nslookup 可以)
【发布时间】:2012-06-01 18:50:54
【问题描述】:

我可以尝试使用GetAddrInfo 来解析ipv6.google.com

wsaError = getaddrinfo("ipv6.google.com", null, null, ref addrInfo);

返回的套接字错误代码是11001(不知道这样的主机)。

注意:已弃用的旧版函数GetHostByName 不支持 IPv6。它已替换为GetAddrInfo

奇怪的是,我可以使用nslookup,它可以很好地找到地址:

问题

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

GetAddrInfo 不能解析地址时,什么会导致nslookup 能够解析地址?我可以用GetAddrInfo 做些什么不同的事情来让它起作用?

【问题讨论】:

    标签: winapi sockets dns ipv6


    【解决方案1】:

    尝试在pHints 参数中传递AF_INET6 以使用IPV6 地址。这似乎对我有用:

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

    【讨论】:

    • 让我解析ipv6.google.com,但随后stackoverflow.com 无法解析。我还需要解决nslookup如何管理它的问题。
    • 我发现了如何 nslookup 完成它的任务。它运行A 查询,然后单独进行AAAA 查找。所以我不得不getaddrinfo打电话两次,一次是为了IPv6,一次是为了IPv4。
    • 尝试将hints.ai_family设置为AF_UNSPEC,让getaddrinfo()同时查询IPv4和IPv6信息。
    • @RemyLebeau 将族设置为 AF_UNSPEC 没有帮助。我想也许家庭应该是一个标志(AF_INET6 or AF_INET);但它不是位标志。
    • 不,它不是位掩码。 The documentation 明确指出:“ai_family 的 AF_UNSPEC 值表示调用者将接受任何协议族。该值可用于返回 pNodeName 参数指向的主机名的 IPv4 和 IPv6 地址。在 Windows Server 2003 和Windows XP,只有在本地计算机上安装了 IPv6 时才会返回 IPv6 地址。"
    【解决方案2】:

    我也有类似的问题,不是代码问题,而是操作系统问题。以下命令意味着 windows 正确解析了 IPv6 地址,而不是给出 WSANA_DATA 错误:

    Netsh 接口 teredo set state enterpriseclient

    来源:

    http://netscantools.blogspot.co.uk/2011/06/ipv6-teredo-problems-and-solutions-on.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-22
      • 2020-11-18
      相关资源
      最近更新 更多