aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/net
diff options
context:
space:
mode:
authorMike Karels <karels@FreeBSD.org>2022-11-02 15:57:59 +0000
committerMike Karels <karels@FreeBSD.org>2022-12-03 15:16:46 +0000
commitf395174bbb2c6a0a7bba7b08364e8e5e289ef780 (patch)
tree3db06affe9209dec72d9f6659e58bc9c5808f827 /lib/libc/net
parenta467b5003320b53ff153c91f8dccdf40f29e6181 (diff)
getaddrinfo: distinguish missing addrs from unresolvable names
Rework getaddrinfo(3) to return different error values for unresolvable names (same as before, EAI_NONAME) and those without a requested addr (EAI_ADDRFAMILY) when using DNS. This is implemented via an added error in the nsswitch layer, NS_ADDRFAMILY, which is used only by getaddrinfo(). The error is passed through nsdispatch(3), but that routine has no changes to handle this error. The error originates in the getaddrinfo DNS layer called via nsdispatch(), and is processed by the search layer that calls nsdispatch(). While here, add a little style to returns near those that were modified. Reviewed in https://reviews.freebsd.org/D37139 with related changes. Reviewed by: bz (cherry picked from commit 144361386696582c04592f200a4c2e3339c81a25)
Diffstat (limited to 'lib/libc/net')
-rw-r--r--lib/libc/net/getaddrinfo.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c
index abe4eb17cf72..14729087b82a 100644
--- a/lib/libc/net/getaddrinfo.c
+++ b/lib/libc/net/getaddrinfo.c
@@ -1953,6 +1953,9 @@ explore_fqdn(const struct addrinfo *pai, const char *hostname,
case NS_NOTFOUND:
error = EAI_NONAME;
goto free;
+ case NS_ADDRFAMILY:
+ error = EAI_ADDRFAMILY;
+ goto free;
case NS_SUCCESS:
error = 0;
for (cur = result; cur; cur = cur->ai_next) {
@@ -2341,7 +2344,9 @@ _dns_getaddrinfo(void *rv, void *cb_data, va_list ap)
if (res_searchN(hostname, &q, res) < 0) {
free(buf);
free(buf2);
- return NS_NOTFOUND;
+ if (res->res_h_errno == NO_DATA)
+ return (NS_ADDRFAMILY);
+ return (NS_NOTFOUND);
}
/* prefer IPv6 */
if (q.next) {
@@ -2363,15 +2368,16 @@ _dns_getaddrinfo(void *rv, void *cb_data, va_list ap)
if (sentinel.ai_next == NULL)
switch (res->res_h_errno) {
case HOST_NOT_FOUND:
+ return (NS_NOTFOUND);
case NO_DATA:
- return NS_NOTFOUND;
+ return (NS_ADDRFAMILY);
case TRY_AGAIN:
- return NS_TRYAGAIN;
+ return (NS_TRYAGAIN);
default:
- return NS_UNAVAIL;
+ return (NS_UNAVAIL);
}
*((struct addrinfo **)rv) = sentinel.ai_next;
- return NS_SUCCESS;
+ return (NS_SUCCESS);
}
static void