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: libresolv with getaddrinfo


On 03/13/2015 10:28 AM, Joshua Rogers wrote:
> Hi,
> On 14/03/15 00:56, Carlos O'Donell wrote:
>> Other than that, it must accurately set RES_INIT flag to indicate
>> the structure is initialized and does not need to be initialized
>> again.
>>
>> The obvious dislcaimer is that this is very fragile and may break
>> at any time if we change the layout of _res.
>>
> Would that be what res_init() is for?

That function is intended to initialize the internals of the resolver.
That isn't what you're interested in doing though. You want to alter
the internals, and those internals might change. You have no option
but to keep modifying your code and recompiling if the internals of _res
change.
 
> If so, that doesn't seem to work either. If I use res_init(); before I
> set _res, it still overwrites it on the first call to getaddrinfo.
> This is the same for using res_query.

How are you overwriting _res? Are you following the same rules glibc
follows internally to avoid reinitializing?

Every call to every function may reinitialize _res if certain rules
are not followed. Those rules are documented in __res_maybe_init() function.

Note that it is __res_vinit() which sets RES_INIT in the options to indicate
intialization is complete.
 
> Anyways, for my code, I assume I should be using the res_* family, as
> getaddrinfo is not guaranteed to use _res, right?

Yes and no.

Calls to getaddrinfo use NSS, which uses plugins, which in turn might
use the DNS plugin, which uses _res, so it should work.

However, it may depend on the plugin configured by the user, and the
system configuration. For example you might have nscd installed, in which
case the resolution is done by nscd and returned to you without a chance
to intercept. Or a 3rd party plugin like sssd might do the resolution.

You can't easily do what you want robustly.

Cheers,
Carlos.


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