This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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 <bkuhn@ebb.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[0] = 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
> _res.
>
> 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
> list.

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
for main.

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.

Good luck!

Cheers,
Carlos.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]