mirror of
https://github.com/curl/curl.git
synced 2026-06-09 03:04:16 +03:00
dns error messages, take2
Use `ares_strerror()` to retrieve error message from c-ares. 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.
This commit is contained in:
parent
4db91c4411
commit
785ca19837
4 changed files with 15 additions and 31 deletions
|
|
@ -358,32 +358,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)
|
||||
|
|
@ -767,6 +745,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;
|
||||
|
|
|
|||
|
|
@ -606,7 +606,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;
|
||||
|
|
|
|||
|
|
@ -1548,7 +1548,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
|
||||
|
|
@ -1614,7 +1614,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";
|
||||
|
|
@ -1630,7 +1630,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 */
|
||||
|
|
|
|||
|
|
@ -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
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue