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?
- From: "Carlos O'Donell" <carlos at systemhalted dot org>
- To: "Bradley M. Kuhn" <bkuhn at ebb dot org>
- Cc: libc-help at sourceware dot org
- Date: Sat, 14 Nov 2009 14:26:45 -0500
- Subject: Re: Tune global _res variable to bypass /etc/resolv.conf? If not, how to bypass /etc/resolv.conf in a C program using glibc?
- References: <email@example.com>
On Sat, Nov 14, 2009 at 1:47 PM, Bradley M. Kuhn <firstname.lastname@example.org> wrote:
> Based on various examples I've found from various sources regarding
> using the resolver in libc, the code example below is presumably
> supposed to force the resolver use the DNS server of my choice. ?It
> appears that changing _res in this way has no impact on glibc; it always
> uses the list of DNS servers from /etc/resolv.conf.
> 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?
> I have tried calling res_init() both before and after I muck with _res
> and I get the same results -- the entries in /etc/resolv.conf are used
> rather than my settings via:
> ? ?_res.nscount = 1; _res.nsaddr_list = serverSock;
> FWIW, the seminal source for information online about using _res in this
> way appears to be the DNS & Bind book:
> ? ? ? ?http://docstore.mik.ua/orelly/networking_2ndEd/dns/ch15_02.htm
> which I realize is quite old and perhaps inaccurate.
> If anyone can point to a README or FAQ that explains how to stop the
> glibc resolver from falling back to /etc/resolv.conf (i.e., how to
> control what DNS servers are used completely via the libc API), I'd much
> appreciate it. ?I've searched around and been unable to find any
> suggestions other than the aforementioned suggestions about modifying
> If anyone is interested in why I'm asking, it's because I'm trying to
> close this bug in BusyBox: https://bugs.busybox.net/show_bug.cgi?id=675
> I apologize if this is a dumb question; it's my first time posting to this
I am by no means an expert in this code.
However, the variable _res appears to be an undocumented internal
variable that is used to support reentrancy for the network functions.
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.
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
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.