From: Stefan Eissing Date: Mon, 11 Aug 2025 13:58:11 +0000 (+0200) Subject: ares: use `ares_strerror()` to retrieve error messages X-Git-Tag: curl-8_16_0~128 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b111f0a8c8a0796ace3def7472a6b6666f3a18e;p=thirdparty%2Fcurl.git ares: use `ares_strerror()` to retrieve error messages Add optional detail to `Curl_resolver_error()` to add to failure message where available. This makes, for c-ares, the reason for a failed resource available to the user without extra trace config. When "dns" tracing enabled, print the c-ares server config at the start of a resolve. Closes #18251 --- diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c index 3eb769d934..e955990878 100644 --- a/lib/asyn-ares.c +++ b/lib/asyn-ares.c @@ -359,32 +359,10 @@ CURLcode Curl_async_is_resolved(struct Curl_easy *data, /* if we have not found anything, report the proper * CURLE_COULDNT_RESOLVE_* code */ if(!result && !data->state.async.dns) { - result = Curl_resolver_error(data); - if(ares->ares_status != ARES_SUCCESS) { - const char *msg; - switch(ares->ares_status) { - case ARES_ECONNREFUSED: - msg = "connection to DNS server refused"; - break; - case ARES_ETIMEOUT: - msg = "query to DNS server timed out"; - break; - case ARES_ENOTFOUND: - msg = "DNS server did not find the address"; - break; - case ARES_EREFUSED: - msg = "DNS server refused query"; - break; - default: - msg = "resolve failed"; - break; - } - CURL_TRC_DNS(data, "asyn-ares: %s (error %d)", msg, ares->ares_status); -#if ARES_VERSION >= 0x011800 /* >= v1.24.0 */ - CURL_TRC_DNS(data, "asyn-ares config: %s", - ares_get_servers_csv(ares->channel)); -#endif - } + const char *msg = NULL; + if(ares->ares_status != ARES_SUCCESS) + msg = ares_strerror(ares->ares_status); + result = Curl_resolver_error(data, msg); } if(result) @@ -768,6 +746,11 @@ struct Curl_addrinfo *Curl_async_getaddrinfo(struct Curl_easy *data, ares->ares_status = ARES_ENOTFOUND; ares->result = CURLE_OK; +#if ARES_VERSION >= 0x011800 /* >= v1.24.0 */ + CURL_TRC_DNS(data, "asyn-ares: servers=%s", + ares_get_servers_csv(ares->channel)); +#endif + #ifdef HAVE_CARES_GETADDRINFO { struct ares_addrinfo_hints hints; diff --git a/lib/asyn-thrdd.c b/lib/asyn-thrdd.c index 1ff2d949d2..a6eb250ed2 100644 --- a/lib/asyn-thrdd.c +++ b/lib/asyn-thrdd.c @@ -683,7 +683,7 @@ CURLcode Curl_async_is_resolved(struct Curl_easy *data, } if(!result && !data->state.async.dns) - result = Curl_resolver_error(data); + result = Curl_resolver_error(data, NULL); if(result) Curl_resolv_unlink(data, &data->state.async.dns); *dns = data->state.async.dns; diff --git a/lib/hostip.c b/lib/hostip.c index e36184b4e3..dfff9d61da 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -1552,7 +1552,7 @@ CURLcode Curl_resolv_check(struct Curl_easy *data, if(data->conn->bits.doh) { result = Curl_doh_is_resolved(data, dns); if(result) - Curl_resolver_error(data); + Curl_resolver_error(data, NULL); } else #endif @@ -1618,7 +1618,7 @@ CURLcode Curl_once_resolved(struct Curl_easy *data, */ #ifdef USE_CURL_ASYNC -CURLcode Curl_resolver_error(struct Curl_easy *data) +CURLcode Curl_resolver_error(struct Curl_easy *data, const char *detail) { struct connectdata *conn = data->conn; const char *host_or_proxy = "host"; @@ -1634,7 +1634,8 @@ CURLcode Curl_resolver_error(struct Curl_easy *data) } #endif - failf(data, "Could not resolve %s: %s", host_or_proxy, name); + failf(data, "Could not resolve %s: %s%s%s%s", host_or_proxy, name, + detail ? " (" : "", detail ? detail : "", detail ? ")" : ""); return result; } #endif /* USE_CURL_ASYNC */ diff --git a/lib/hostip.h b/lib/hostip.h index 65fa78fa50..2f78be82c2 100644 --- a/lib/hostip.h +++ b/lib/hostip.h @@ -201,7 +201,7 @@ CURLcode Curl_resolv_check(struct Curl_easy *data, CURLcode Curl_resolv_pollset(struct Curl_easy *data, struct easy_pollset *ps); -CURLcode Curl_resolver_error(struct Curl_easy *data); +CURLcode Curl_resolver_error(struct Curl_easy *data, const char *detail); #ifdef CURLRES_SYNCH /*