This is the mail archive of the
mailing list for the glibc project.
Re: libresolv with getaddrinfo
- From: "Carlos O'Donell" <carlos at redhat dot com>
- To: Joshua Rogers <glibc at internot dot info>, libc-help at sourceware dot org
- Date: Fri, 13 Mar 2015 09:56:20 -0400
- Subject: Re: libresolv with getaddrinfo
- Authentication-results: sourceware.org; auth=none
- References: <5502EB12 dot 9030002 at internot dot info>
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:
> 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:
>> 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
The obvious dislcaimer is that this is very fragile and may break
at any time if we change the layout of _res.