mirror of
https://github.com/moparisthebest/curl
synced 2024-08-13 17:03:50 -04:00
hostip: move code to resolve IP address literals to Curl_resolv
The code was duplicated in the various resolver backends. Also, it was called after the call to `Curl_ipvalid`, which matters in case of `CURLRES_IPV4` when called from `connect.c:bindlocal`. This caused test 1048 to fail on classic MinGW. The code ignores `conn->ip_version` as done previously in the individual resolver backends. Move the call to the `resolver_start` callback up to appease test 655, which wants it to be called also for literal addresses. Closes https://github.com/curl/curl/pull/4798
This commit is contained in:
parent
062eaa63b5
commit
875314ed0b
@ -626,26 +626,11 @@ Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
|
||||
{
|
||||
char *bufp;
|
||||
struct Curl_easy *data = conn->data;
|
||||
struct in_addr in;
|
||||
int family = PF_INET;
|
||||
#ifdef ENABLE_IPV6 /* CURLRES_IPV6 */
|
||||
struct in6_addr in6;
|
||||
#endif /* CURLRES_IPV6 */
|
||||
|
||||
*waitp = 0; /* default to synchronous response */
|
||||
|
||||
/* First check if this is an IPv4 address string */
|
||||
if(Curl_inet_pton(AF_INET, hostname, &in) > 0) {
|
||||
/* This is a dotted IP address 123.123.123.123-style */
|
||||
return Curl_ip2addr(AF_INET, &in, hostname, port);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_IPV6 /* CURLRES_IPV6 */
|
||||
/* Otherwise, check if this is an IPv6 address string */
|
||||
if(Curl_inet_pton (AF_INET6, hostname, &in6) > 0)
|
||||
/* This must be an IPv6 address literal. */
|
||||
return Curl_ip2addr(AF_INET6, &in6, hostname, port);
|
||||
|
||||
switch(conn->ip_version) {
|
||||
default:
|
||||
#if ARES_VERSION >= 0x010601
|
||||
|
@ -71,7 +71,6 @@
|
||||
#include "strerror.h"
|
||||
#include "url.h"
|
||||
#include "multiif.h"
|
||||
#include "inet_pton.h"
|
||||
#include "inet_ntop.h"
|
||||
#include "curl_threads.h"
|
||||
#include "connect.h"
|
||||
@ -692,26 +691,11 @@ Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
|
||||
int port,
|
||||
int *waitp)
|
||||
{
|
||||
struct in_addr in;
|
||||
struct Curl_easy *data = conn->data;
|
||||
struct resdata *reslv = (struct resdata *)data->state.resolver;
|
||||
|
||||
*waitp = 0; /* default to synchronous response */
|
||||
|
||||
#ifdef ENABLE_IPV6
|
||||
{
|
||||
struct in6_addr in6;
|
||||
/* check if this is an IPv6 address string */
|
||||
if(Curl_inet_pton(AF_INET6, hostname, &in6) > 0)
|
||||
/* This is an IPv6 address literal */
|
||||
return Curl_ip2addr(AF_INET6, &in6, hostname, port);
|
||||
}
|
||||
#endif /* ENABLE_IPV6 */
|
||||
|
||||
if(Curl_inet_pton(AF_INET, hostname, &in) > 0)
|
||||
/* This is a dotted IP address 123.123.123.123-style */
|
||||
return Curl_ip2addr(AF_INET, &in, hostname, port);
|
||||
|
||||
reslv->start = Curl_now();
|
||||
|
||||
/* fire up a new resolver thread! */
|
||||
@ -743,25 +727,6 @@ Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
|
||||
|
||||
*waitp = 0; /* default to synchronous response */
|
||||
|
||||
#ifndef USE_RESOLVE_ON_IPS
|
||||
{
|
||||
struct in_addr in;
|
||||
/* First check if this is an IPv4 address string */
|
||||
if(Curl_inet_pton(AF_INET, hostname, &in) > 0)
|
||||
/* This is a dotted IP address 123.123.123.123-style */
|
||||
return Curl_ip2addr(AF_INET, &in, hostname, port);
|
||||
}
|
||||
#ifdef ENABLE_IPV6
|
||||
{
|
||||
struct in6_addr in6;
|
||||
/* check if this is an IPv6 address string */
|
||||
if(Curl_inet_pton(AF_INET6, hostname, &in6) > 0)
|
||||
/* This is an IPv6 address literal */
|
||||
return Curl_ip2addr(AF_INET6, &in6, hostname, port);
|
||||
}
|
||||
#endif /* ENABLE_IPV6 */
|
||||
#endif /* !USE_RESOLVE_ON_IPS */
|
||||
|
||||
#ifdef CURLRES_IPV6
|
||||
/*
|
||||
* Check if a limited name resolve has been requested.
|
||||
|
38
lib/hostip.c
38
lib/hostip.c
@ -59,6 +59,7 @@
|
||||
#include "strerror.h"
|
||||
#include "url.h"
|
||||
#include "inet_ntop.h"
|
||||
#include "inet_pton.h"
|
||||
#include "multiif.h"
|
||||
#include "doh.h"
|
||||
#include "warnless.h"
|
||||
@ -512,13 +513,11 @@ int Curl_resolv(struct connectdata *conn,
|
||||
if(!dns) {
|
||||
/* The entry was not in the cache. Resolve it to IP address */
|
||||
|
||||
Curl_addrinfo *addr;
|
||||
Curl_addrinfo *addr = NULL;
|
||||
int respwait = 0;
|
||||
|
||||
/* 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;
|
||||
#ifndef USE_RESOLVE_ON_IPS
|
||||
struct in_addr in;
|
||||
#endif
|
||||
|
||||
/* notify the resolver start callback */
|
||||
if(data->set.resolver_start) {
|
||||
@ -531,13 +530,35 @@ int Curl_resolv(struct connectdata *conn,
|
||||
return CURLRESOLV_ERROR;
|
||||
}
|
||||
|
||||
#ifndef USE_RESOLVE_ON_IPS
|
||||
/* First check if this is an IPv4 address string */
|
||||
if(Curl_inet_pton(AF_INET, hostname, &in) > 0)
|
||||
/* This is a dotted IP address 123.123.123.123-style */
|
||||
addr = Curl_ip2addr(AF_INET, &in, hostname, port);
|
||||
#ifdef ENABLE_IPV6
|
||||
if(!addr) {
|
||||
struct in6_addr in6;
|
||||
/* check if this is an IPv6 address string */
|
||||
if(Curl_inet_pton(AF_INET6, hostname, &in6) > 0)
|
||||
/* This is an IPv6 address literal */
|
||||
addr = Curl_ip2addr(AF_INET6, &in6, hostname, port);
|
||||
}
|
||||
#endif /* ENABLE_IPV6 */
|
||||
#endif /* !USE_RESOLVE_ON_IPS */
|
||||
|
||||
if(!addr) {
|
||||
/* 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(allowDOH && data->set.doh) {
|
||||
addr = Curl_doh(conn, hostname, port, &respwait);
|
||||
}
|
||||
else {
|
||||
/* 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 */
|
||||
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]
|
||||
@ -546,6 +567,7 @@ int Curl_resolv(struct connectdata *conn,
|
||||
#endif
|
||||
hostname, port, &respwait);
|
||||
}
|
||||
}
|
||||
if(!addr) {
|
||||
if(respwait) {
|
||||
/* the response to our resolve call will come asynchronously at
|
||||
|
@ -52,7 +52,6 @@
|
||||
#include "share.h"
|
||||
#include "strerror.h"
|
||||
#include "url.h"
|
||||
#include "inet_pton.h"
|
||||
/* The last 3 #include files should be in this order */
|
||||
#include "curl_printf.h"
|
||||
#include "curl_memory.h"
|
||||
@ -128,25 +127,9 @@ Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname,
|
||||
#endif
|
||||
Curl_addrinfo *ai = NULL;
|
||||
struct hostent *h = NULL;
|
||||
struct in_addr in;
|
||||
struct hostent *buf = NULL;
|
||||
|
||||
#ifdef ENABLE_IPV6
|
||||
{
|
||||
struct in6_addr in6;
|
||||
/* check if this is an IPv6 address string */
|
||||
if(Curl_inet_pton(AF_INET6, hostname, &in6) > 0)
|
||||
/* This is an IPv6 address literal */
|
||||
return Curl_ip2addr(AF_INET6, &in6, hostname, port);
|
||||
}
|
||||
#endif /* ENABLE_IPV6 */
|
||||
|
||||
if(Curl_inet_pton(AF_INET, hostname, &in) > 0)
|
||||
/* This is a dotted IP address 123.123.123.123-style */
|
||||
return Curl_ip2addr(AF_INET, &in, hostname, port);
|
||||
|
||||
#if defined(HAVE_GETADDRINFO_THREADSAFE)
|
||||
else {
|
||||
struct addrinfo hints;
|
||||
char sbuf[12];
|
||||
char *sbufptr = NULL;
|
||||
@ -167,7 +150,6 @@ Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname,
|
||||
* Since there are three different versions of it, the following code is
|
||||
* somewhat #ifdef-ridden.
|
||||
*/
|
||||
else {
|
||||
int h_errnop;
|
||||
|
||||
buf = calloc(1, CURL_HOSTENT_SIZE);
|
||||
@ -301,10 +283,8 @@ Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname,
|
||||
* getaddrinfo() nor gethostbyname_r() function or for which
|
||||
* gethostbyname() is the preferred one.
|
||||
*/
|
||||
else {
|
||||
h = gethostbyname((void *)hostname);
|
||||
#endif /* HAVE_GETADDRINFO_THREADSAFE || HAVE_GETHOSTBYNAME_R */
|
||||
}
|
||||
|
||||
if(h) {
|
||||
ai = Curl_he2ai(h, port);
|
||||
|
Loading…
Reference in New Issue
Block a user