diff options
author | Daniel Stenberg <daniel@haxx.se> | 2017-10-06 15:16:57 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2017-10-06 15:16:57 +0200 |
commit | 60d2b795eb1ade015415975e95b7b15d886c92de (patch) | |
tree | 6bf73ea26accf95d6ccdc61bfb8de82cab742e73 | |
parent | 454dae0092d6f367fe486bdfd49f781329bf4500 (diff) | |
download | curl-bagder/hostip-use-fake-hostname.tar.gz |
hostip: allow debug builds to override what host name to resolvebagder/hostip-use-fake-hostname
The environment variable CURL_URL_HOSTNAME can be set to a host name
that will make libcurl resolve and use that host name instead of the
name it would otherwise use. Only for debug builds.
This also removes the special case debug support for LocalHost in the
interface string that kind of provided a similar debug approach. That
was brought in 7e07da977ce748 but doesn't seem to be used these days.
-rw-r--r-- | lib/hostip.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/lib/hostip.c b/lib/hostip.c index 1a18a3ed7..0d477bea9 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -430,10 +430,6 @@ Curl_cache_addr(struct Curl_easy *data, * function is used. You MUST call Curl_resolv_unlock() later (when you're * done using this struct) to decrease the counter again. * - * In debug mode, we specifically test for an interface name "LocalHost" - * and resolve "localhost" instead as a means to permit test cases - * to connect to a local test server with any host name. - * * Return codes: * * CURLRESOLV_ERROR (-1) = error, no pointer @@ -450,6 +446,11 @@ int Curl_resolv(struct connectdata *conn, struct Curl_easy *data = conn->data; CURLcode result; int rc = CURLRESOLV_ERROR; /* default to failure */ +#ifdef DEBUGBUILD + char *fakehost = curl_getenv("CURL_URL_HOSTNAME"); + if(fakehost) + hostname = fakehost; +#endif *entry = NULL; @@ -475,19 +476,15 @@ int Curl_resolv(struct connectdata *conn, /* Check what IP specifics the app has requested and if we can provide it. * If not, bail out. */ - if(!Curl_ipvalid(conn)) - return CURLRESOLV_ERROR; + if(!Curl_ipvalid(conn)) { + rc = CURLRESOLV_ERROR; + goto end; + } /* If Curl_getaddrinfo() returns NULL, 'respwait' might be set to a non-zero value indicating that we need to wait for the response to the resolve call */ - addr = Curl_getaddrinfo(conn, -#ifdef DEBUGBUILD - (data->set.str[STRING_DEVICE] - && !strcmp(data->set.str[STRING_DEVICE], - "LocalHost"))?"localhost": -#endif - hostname, port, &respwait); + addr = Curl_getaddrinfo(conn, hostname, port, &respwait); if(!addr) { if(respwait) { @@ -522,7 +519,10 @@ int Curl_resolv(struct connectdata *conn, } *entry = dns; - + end: +#ifdef DEBUGBUILD + free(fakehost); +#endif return rc; } |