简体   繁体   English

iOS-在仅IPv6的网络上获取设备的DNS服务器地址

[英]iOS - Get device's DNS server address on IPv6 only network

I am trying to get device's DNS server address while connected to IPv6 only network on iOS. 我正在尝试连接到iOS上仅IPv6的网络时获取设备的DNS服务器地址。 The following code works well for when connected to IPv4 network but doesn't work on IPv6 network. 以下代码适用于连接到IPv4网络的情况,但不适用于IPv6网络。 Code taken from this answer . 从此答案中获取的代码。

res_ninit(&_res);
res_state res = &_res;

for (int i=0; i < res->nscount; i++) {
    sa_family_t family = res->nsaddr_list[i].sin_family;

    if (family == AF_INET) {
      NSLog(@"IPv4");
      char str[INET_ADDRSTRLEN]; // String representation of address
      inet_ntop(AF_INET, & (res->nsaddr_list[i].sin_addr.s_addr), str, INET_ADDRSTRLEN);
    } else if (family == AF_INET6) {
      NSLog(@"IPv6");
      char address[INET6_ADDRSTRLEN]; // String representation of address
      inet_ntop(AF_INET6, &(res->nsaddr_list [i].sin_addr.s_addr), address, INET6_ADDRSTRLEN);
    } else {
      NSLog(@"Unspecified");
    }
}

On IPv6 network, sin_family is always AF_UNSPEC . 在IPv6网络上, sin_family始终为AF_UNSPEC Any suggestions/alternatives? 有什么建议/替代品吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM