nslookup's Server: 0.0.0.0 but resolves correctly

Rich Felker dalias at libc.org
Sun Nov 2 22:59:54 UTC 2014


On Sun, Nov 02, 2014 at 09:02:57PM +0000, Steven Honeyman wrote:
> On 2 November 2014 18:05,  <stroblsw at gmail.com> wrote:
> >> musl:
> >>
> >>  24
> >>  25 /* unused; purely for broken apps */
> >>  26 typedef struct __res_state {
> >>  27     int retrans;
> >>
> >
> > sorry you lost me.
> > is this an nslookup.c from your own repo?
> > I thought musl only needs header patches with bb.
> 
> No - that's in the dns related source code of musl libc (which is also
> broken like you describe android bionic)
> 
> I should really say now, I know almost nothing about android/bionic
> which is why I can't offer any direct suggestions for that... but I
> use musl quite a bit so can try to approach that way.
> 
> Basically, busybox tries to get dns settings through an (old?) method
> that is not supported in musl (and possibly bionic). The code in musl
> behind the scenes is just a bunch of return 0; to keep "broken apps"
> happy in thinking the res functions work, but meanwhile it uses its
> own method of parsing resolv.conf - which might be the easiest way I
> can think of to work around this issue... but I'm sure there is a much
> better way that I don't know about.
> 
> ^ that's my current understanding at least, but if anyone can explain
> better then I'm sure we'd all benefit!

I'll try to explain what it's like for musl.

The above comment in regards to __res_state is referring to the idea
that this structure was never meant to be a public API, but got abused
as one by applications attempting to override nameservers or settings
or otherwise fiddle with the resolver's internal state.

musl's resolver is completely stateless and parses resolv.conf on each
request. This both ensures that it's always using fresh data (e.g. on
systems where the DNS configuration changes frequently) and avoids all
the issues of having global state that's not thread-safe or
library-safe. (IIRC glibc avoids this by making the resolver state
thread-local, and by providing the new "n-prefixed" versions of the
res functions which can use a caller-provided __res_state.)

The res_* functions are not stubs/dummies in musl. As of a few
versions ago, they're all intended to work. res_init is a nop simply
because there is no state.

The right way to do lookups with a custom DNS is to call res_mkquery
and then sendto() your preferred DNS.

Rich


More information about the busybox mailing list