I'm trying to retrieve a list of IPv6 DNS servers programmatically. Currently I'm using libresolv and next code:
#include <stdio.h>
#include <netinet/in.h>
#include <resolv.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char** argv)
{
res_state res = malloc(sizeof(struct __res_state));
res_ninit(res);
printf("%p\n", res->_u._ext.nsaddrs[0]); // (nil) here
}
According to resolv.h, res->_u._ext.nsaddrs field should contain an array of "struct sockaddr_in6 *" with needed addresses, but it contains an array of NULLs.
IPv4 DNS servers list is accessible via res->nsaddr_list field, but IPv6 list is always empty. I've checked this with both Ubuntu and CentOS. IPv6 is configured correctly.
Your code seems to be correct. Most likely
res_ninit()
doesn't put any IPv6 DNS servers into thestruct res_state
because your system is not aware of any.Try to put the following line into your /etc/resolv.conf: