Skip to content

Commit

Permalink
host_callback: Fall back to AF_INET on searching with AF_UNSPEC
Browse files Browse the repository at this point in the history
Previously, when an ares_gethostbyname() searched with AF_UNSPEC and the
first AF_INET6 call only returned CNAMEs, the host_callback never
retried AF_INET.

This patch makes sure than on ARES_SUCCESS, the result of AF_INET6 is
taken as authoritative only if the result contains some addresses.
  • Loading branch information
jhrozek committed Jul 24, 2014
1 parent 943e79f commit c1fe47f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ares_gethostbyname.c
Expand Up @@ -188,8 +188,9 @@ static void host_callback(void *arg, int status, int timeouts,
else if (hquery->sent_family == AF_INET6)
{
status = ares_parse_aaaa_reply(abuf, alen, &host, NULL, NULL);
if ((status == ARES_ENODATA || status == ARES_EBADRESP) &&
hquery->want_family == AF_UNSPEC) {
if ((status == ARES_ENODATA || status == ARES_EBADRESP ||
(status == ARES_SUCCESS && host && host->h_addr_list[0] == NULL)) &&
hquery->want_family == AF_UNSPEC) {
/* The query returned something but either there were no AAAA
records (e.g. just CNAME) or the response was malformed. Try
looking up A instead. */
Expand Down

0 comments on commit c1fe47f

Please sign in to comment.