This is the mail archive of the
mailing list for the glibc project.
Re: Tune global _res variable to bypass /etc/resolv.conf? If not,how to bypass /etc/resolv.conf in a C program using glibc?
> On Sat, Nov 14, 2009 at 1:47 PM, Bradley M. Kuhn <email@example.com> wrote:
> > Is there a different way that _res should be changed to bypass
> > /etc/resolv.conf and set the DNS server to something else at the C
> > programming level?
Carlos O'Donell replied:
> If you want to continue down this road I suggest you try looking into
> the "__resp" variable which should point to the correct copy of _res
> for main.
I gave it a try. The same problem appears to happen. I have not yet
stepped through the glibc code with a debugger, but by poking around in
the sources, I think this may have something to do with __res_initstamp.
Functions like getaddrinfo() usually call __res_maybe_init() which does
this test: __res_initstamp != resp->_u._ext.initstamp
That's is the only test I would deduce is turning false to cause a
reinitialization of the _res structure, as RES_INIT is set by explicitly
calling res_init(), which I do first, and not again. Yet, I can't imagine
what is changing the initstamp value in either case, as I call
getaddrinfo() immediately after mucking with __resp.
> Modifying _res does not appear to be a supported API. I understand that
> nobody wants to re-implement all of the network code, so this hack is
> immensely convenient.
It's not clear that the _res interface messing with the resolver is the
"right way" to get this done, anyway. I'd be happy for "a way" to get it
done, without changing /etc/resolv.conf.
> I can't guarantee this will work, and I've only looked at the glibc code
> quickly to see if I could answer your question.
Thanks for your effort on this. I appreciate it.