Subject: Re: ares_gethostbyname fails to resolve localhost with AF_INET6

Re: ares_gethostbyname fails to resolve localhost with AF_INET6

From: Charlie Fenton <charlief_at_ssl.berkeley.edu>
Date: Thu, 2 Jun 2011 04:33:33 -0700

I reported a long time ago that the fallback to IPv4 does not happen under certain circumstances. (I was dealing with problem reported by our users of BOINC on Mac OS X.)

I have since determined the reason. The problem is that host_callback() in ares_gethostbyname.c falls back to IPv4 only for certain error codes, but the list of error codes is incomplete. I have fixed this on my local copy of c-ares 1.7.4 with the following patch, which falls back to IPv4 for any error from the IPv6 attempt:

@@ -208,8 +208,7 @@
         }
       end_hquery(hquery, status, host);
     }
- else if ((status == ARES_ENODATA || status == ARES_EBADRESP ||
- status == ARES_ETIMEOUT) && hquery->sent_family == AF_INET6)
+ else if (hquery->sent_family == AF_INET6) /* Modified for BOINC */
     {
       /* The AAAA query yielded no useful result. Now look up an A instead.
          We should possibly limit this attempt-next logic to AF_UNSPEC lookups

I hope this helps.

Cheers,
--Charlie

> From: Sebastian Ramacher <s.ramacher_at_gmx.at>
> Date: June 1, 2011 3:34:49 PM PDT
> To: c-ares_at_cool.haxx.se
> Subject: ares_gethostbyname fails to resolve localhost with AF_INET6
> Reply-To: c-ares hacking <c-ares_at_cool.haxx.se>
>
>
> Hi,
>
> Since my first mail didn't seem to reach the list - it can't be found in the
> list archive - I'm resending it. I'm sorry if you got it twice.
>
> As I understand the source ares_gethostbyname together with AF_INET6 falls back
> to AF_INET if no IPv6 address can be found (at least if a DNS server is
> queried). But this does not seem to be true for hosts in /etc/hosts. For example
> localhost fails to resolve with ares_gethostname together with AF_INET6.
>
> As some programs depend on this fallback behavior (znc for example) it would be
> nice to have the same for hosts defined in /etc/hosts. A possible fix would be
> to do the following in next_lookup: if file_lookup fails with AF_INET6 retry
> with AF_INET.
>
> Kind regards,
> --
> Sebastian Ramacher

--
Charlie Fenton                        charlief_at_ssl.berkeley.edu
BOINC / SETI_at_home Macintosh & Windows Programmer
Space Sciences Laboratory
UC Berkeley
Received on 2011-06-02