On some OS the following code works - I use that for regression testing when I need fake DNS data:
void dns_setns(struct in_addr *ns, unsigned int port) { if ((_res.options & RES_INIT) == 0) (void) res_init(); _res.nsaddr_list[0].sin_family = AF_INET; _res.nsaddr_list[0].sin_addr = *ns; if (port != 0) _res.nsaddr_list[0].sin_port = htons(port); _res.nscount = 1; }