From 0fef7ffac114befc94ab5fa794a1754442dcd531 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 28 Jan 2016 19:23:06 -0500 Subject: [PATCH] fix handling of dns response codes rcode of 3 (NxDomain) was treated as a hard EAI_NONAME failure, but it should instead return 0 (no results) so the caller can continue searching. this will be important for adding search domain support. the top-level caller will automatically return EAI_NONAME if there are zero results at the end. also, the case where rcode is 0 (success) but there are no results was not handled. this happens when the domain exists but there are no A or AAAA records for it. in this case a hard EAI_NONAME should be imposed to inhibit further search, since the name was defined and just does not have any address associated with it. previously a misleading hard failure of EAI_FAIL was reported. --- src/network/lookup_name.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/network/lookup_name.c b/src/network/lookup_name.c index df9e623e..fb7b5c12 100644 --- a/src/network/lookup_name.c +++ b/src/network/lookup_name.c @@ -152,7 +152,8 @@ static int name_from_dns(struct address buf[static MAXADDRS], char canon[static if (ctx.cnt) return ctx.cnt; if (alens[0] < 4 || (abuf[0][3] & 15) == 2) return EAI_AGAIN; - if ((abuf[0][3] & 15) == 3) return EAI_NONAME; + if ((abuf[0][3] & 15) == 0) return EAI_NONAME; + if ((abuf[0][3] & 15) == 3) return 0; return EAI_FAIL; } -- 2.25.1