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 09:50 AM, Joshua Rogers wrote:
> Hi everybody,
> 
> I'm trying to use libresolv in conjunction with getaddrinfo to resolve a
> hostname with a custom NS server. I got it all worked and documented my
> finding here:
> http://blog.internot.info/2015/03/specifying-dnsns-server-for-address.html
> 
> However, one thing I found, was that on the first usage of
> getaddrinfo(), the _res struct is overwritten.
> 
> So, in my code, I must do this, before I full in _res.nsaddr_list[0]:
> 
>>         getaddrinfo("google.com", NULL, &hints, &servinfo);
>>         freeaddrinfo((struct addrinfo*)servinfo);
> 
> 
> Is there a specific reason for this?
> Is it a bug?
> 
> 
> Any hints or info would be highly appreciated.

You can't win, other threads, or libraries may request a reinit.

Whatever custom library you are using to add a custom DNS must
interpose the res initialization function.

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.

Cheers,
Carlos.


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