IOS - Get the device’s DNS server address only on an IPv6 network

I am trying to get the device’s DNS server address when connecting to the network only on IPv6 on iOS. The following code works well when connected to an IPv4 network, but does not work on an IPv6 network. Code taken from this.

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 an IPv6 network, sin_family always AF_UNSPEC . Any suggestions / alternatives?

+1
source share

All Articles