I am using libresolv library to create an application which takes DNS server names in command line arguments and query host names to this specific DNS server.
_res.nsaddr_list[0].sin_family = AF_INET;
_res.nsaddr_list[0].sin_addr.s_addr = inet_addr(argv[2]);
_res.nsaddr_list[0].sin_port = htons(NS_PORT);
_res.nscount = 1;
res_init ();
l = res_query(argv[1], ns_c_any, ns_t_a, nsbuf, sizeof(nsbuf));
This works for local DNS servers if used. But when I try to pass 8.8.8.8 (google nameserver) res_query always returns -1. I searched something similar on net and found res_init loads /etc/resolv.conf. Which I do notwant. I want to override resolv.conf and tell resolver to use user entered name server to be used.(Which fails for google server)