Merged existing IPv4 and IPv6 Curl_ip2addr functions into a single one
which now also takes a protocol address family argument.
This commit is contained in:
4
CHANGES
4
CHANGES
@@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
Changelog
|
Changelog
|
||||||
|
|
||||||
|
Yang Tse (6 Nov 2008)
|
||||||
|
- Merged existing IPv4 and IPv6 Curl_ip2addr functions into a single one
|
||||||
|
which now also takes a protocol address family argument.
|
||||||
|
|
||||||
Version 7.19.1 (5 November 2008)
|
Version 7.19.1 (5 November 2008)
|
||||||
|
|
||||||
Daniel Stenberg (4 Nov 2008)
|
Daniel Stenberg (4 Nov 2008)
|
||||||
|
|||||||
@@ -91,7 +91,6 @@
|
|||||||
#include "multiif.h"
|
#include "multiif.h"
|
||||||
#include "sockaddr.h" /* required for Curl_sockaddr_storage */
|
#include "sockaddr.h" /* required for Curl_sockaddr_storage */
|
||||||
#include "inet_ntop.h"
|
#include "inet_ntop.h"
|
||||||
#include "inet_pton.h"
|
|
||||||
#include "sslgen.h" /* for Curl_ssl_check_cxn() */
|
#include "sslgen.h" /* for Curl_ssl_check_cxn() */
|
||||||
|
|
||||||
/* The last #include file should be: */
|
/* The last #include file should be: */
|
||||||
|
|||||||
@@ -190,7 +190,8 @@ Curl_getaddrinfo_ex(const char *nodename,
|
|||||||
|
|
||||||
*result = cafirst;
|
*result = cafirst;
|
||||||
|
|
||||||
return error; /* This is not a CURLcode */
|
/* This is not a CURLcode */
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
#endif /* HAVE_GETADDRINFO */
|
#endif /* HAVE_GETADDRINFO */
|
||||||
|
|
||||||
@@ -254,6 +255,8 @@ Curl_he2ai(const struct hostent *he, int port)
|
|||||||
/* no input == no output! */
|
/* no input == no output! */
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
DEBUGASSERT((he->h_name != NULL) && (he->h_addr_list != NULL));
|
||||||
|
|
||||||
for(i=0; (curr = he->h_addr_list[i]) != NULL; i++) {
|
for(i=0; (curr = he->h_addr_list[i]) != NULL; i++) {
|
||||||
|
|
||||||
int ss_size;
|
int ss_size;
|
||||||
@@ -300,7 +303,7 @@ Curl_he2ai(const struct hostent *he, int port)
|
|||||||
|
|
||||||
switch (ai->ai_family) {
|
switch (ai->ai_family) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
addr = (struct sockaddr_in *)ai->ai_addr; /* storage area for this info */
|
addr = (void *)ai->ai_addr; /* storage area for this info */
|
||||||
|
|
||||||
memcpy(&addr->sin_addr, curr, sizeof(struct in_addr));
|
memcpy(&addr->sin_addr, curr, sizeof(struct in_addr));
|
||||||
addr->sin_family = (unsigned short)(he->h_addrtype);
|
addr->sin_family = (unsigned short)(he->h_addrtype);
|
||||||
@@ -309,7 +312,7 @@ Curl_he2ai(const struct hostent *he, int port)
|
|||||||
|
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
addr6 = (struct sockaddr_in6 *)ai->ai_addr; /* storage area for this info */
|
addr6 = (void *)ai->ai_addr; /* storage area for this info */
|
||||||
|
|
||||||
memcpy(&addr6->sin6_addr, curr, sizeof(struct in6_addr));
|
memcpy(&addr6->sin6_addr, curr, sizeof(struct in6_addr));
|
||||||
addr6->sin6_family = (unsigned short)(he->h_addrtype);
|
addr6->sin6_family = (unsigned short)(he->h_addrtype);
|
||||||
@@ -330,6 +333,100 @@ Curl_he2ai(const struct hostent *he, int port)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct namebuff {
|
||||||
|
struct hostent hostentry;
|
||||||
|
union {
|
||||||
|
struct in_addr ina4;
|
||||||
|
#ifdef ENABLE_IPV6
|
||||||
|
struct in6_addr ina6;
|
||||||
|
#endif
|
||||||
|
} addrentry;
|
||||||
|
char *h_addr_list[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Curl_ip2addr()
|
||||||
|
*
|
||||||
|
* This function takes an internet address, in binary form, as input parameter
|
||||||
|
* along with its address family and the string version of the address, and it
|
||||||
|
* returns a Curl_addrinfo chain filled in correctly with information for the
|
||||||
|
* given address/host
|
||||||
|
*/
|
||||||
|
|
||||||
|
Curl_addrinfo *
|
||||||
|
Curl_ip2addr(int af, const void *inaddr, const char *hostname, int port)
|
||||||
|
{
|
||||||
|
Curl_addrinfo *ai;
|
||||||
|
|
||||||
|
#if defined(VMS) && \
|
||||||
|
defined(__INITIAL_POINTER_SIZE) && (__INITIAL_POINTER_SIZE == 64)
|
||||||
|
#pragma pointer_size save
|
||||||
|
#pragma pointer_size short
|
||||||
|
#pragma message disable PTRMISMATCH
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct hostent *h;
|
||||||
|
struct namebuff *buf;
|
||||||
|
char *addrentry;
|
||||||
|
char *hoststr;
|
||||||
|
int addrsize;
|
||||||
|
|
||||||
|
DEBUGASSERT(inaddr && hostname);
|
||||||
|
|
||||||
|
buf = malloc(sizeof(struct namebuff));
|
||||||
|
if(!buf)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
hoststr = strdup(hostname);
|
||||||
|
if(!hoststr) {
|
||||||
|
free(buf);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(af) {
|
||||||
|
case AF_INET:
|
||||||
|
addrsize = sizeof(struct in_addr);
|
||||||
|
addrentry = (void *)&buf->addrentry.ina4;
|
||||||
|
memcpy(addrentry, inaddr, sizeof(struct in_addr));
|
||||||
|
break;
|
||||||
|
#ifdef ENABLE_IPV6
|
||||||
|
case AF_INET6:
|
||||||
|
addrsize = sizeof(struct in6_addr);
|
||||||
|
addrentry = (void *)&buf->addrentry.ina6;
|
||||||
|
memcpy(addrentry, inaddr, sizeof(struct in6_addr));
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
free(hoststr);
|
||||||
|
free(buf);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
h = &buf->hostentry;
|
||||||
|
h->h_name = hoststr;
|
||||||
|
h->h_aliases = NULL;
|
||||||
|
h->h_addrtype = (short)af;
|
||||||
|
h->h_length = (short)addrsize;
|
||||||
|
h->h_addr_list = &buf->h_addr_list[0];
|
||||||
|
h->h_addr_list[0] = addrentry;
|
||||||
|
h->h_addr_list[1] = NULL; /* terminate list of entries */
|
||||||
|
|
||||||
|
#if defined(VMS) && \
|
||||||
|
defined(__INITIAL_POINTER_SIZE) && (__INITIAL_POINTER_SIZE == 64)
|
||||||
|
#pragma pointer_size restore
|
||||||
|
#pragma message enable PTRMISMATCH
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ai = Curl_he2ai(h, port);
|
||||||
|
|
||||||
|
free(hoststr);
|
||||||
|
free(buf);
|
||||||
|
|
||||||
|
return ai;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(CURLDEBUG) && defined(HAVE_FREEADDRINFO)
|
#if defined(CURLDEBUG) && defined(HAVE_FREEADDRINFO)
|
||||||
/*
|
/*
|
||||||
* curl_dofreeaddrinfo()
|
* curl_dofreeaddrinfo()
|
||||||
|
|||||||
@@ -78,6 +78,8 @@ Curl_getaddrinfo_ex(const char *nodename,
|
|||||||
Curl_addrinfo *
|
Curl_addrinfo *
|
||||||
Curl_he2ai(const struct hostent *he, int port);
|
Curl_he2ai(const struct hostent *he, int port);
|
||||||
|
|
||||||
|
Curl_addrinfo *
|
||||||
|
Curl_ip2addr(int af, const void *inaddr, const char *hostname, int port);
|
||||||
|
|
||||||
#if defined(CURLDEBUG) && defined(HAVE_FREEADDRINFO)
|
#if defined(CURLDEBUG) && defined(HAVE_FREEADDRINFO)
|
||||||
void
|
void
|
||||||
|
|||||||
63
lib/ftp.c
63
lib/ftp.c
@@ -85,6 +85,7 @@
|
|||||||
#include "connect.h"
|
#include "connect.h"
|
||||||
#include "strerror.h"
|
#include "strerror.h"
|
||||||
#include "inet_ntop.h"
|
#include "inet_ntop.h"
|
||||||
|
#include "inet_pton.h"
|
||||||
#include "select.h"
|
#include "select.h"
|
||||||
#include "parsedate.h" /* for the week day and month names */
|
#include "parsedate.h" /* for the week day and month names */
|
||||||
#include "sockaddr.h" /* required for Curl_sockaddr_storage */
|
#include "sockaddr.h" /* required for Curl_sockaddr_storage */
|
||||||
@@ -1105,41 +1106,39 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
|
|||||||
|
|
||||||
(void)fcmd; /* not used in the IPv4 code */
|
(void)fcmd; /* not used in the IPv4 code */
|
||||||
if(ftpportstr) {
|
if(ftpportstr) {
|
||||||
in_addr_t in;
|
struct in_addr in;
|
||||||
|
|
||||||
/* First check if the given name is an IP address */
|
/* First check if the given string is an IP address */
|
||||||
in=inet_addr(ftpportstr);
|
if(Curl_inet_pton(AF_INET, ftpportstr, &in) > 0) {
|
||||||
|
|
||||||
if(in != CURL_INADDR_NONE)
|
|
||||||
/* this is an IPv4 address */
|
/* this is an IPv4 address */
|
||||||
addr = Curl_ip2addr(in, ftpportstr, 0);
|
addr = Curl_ip2addr(AF_INET, &in, ftpportstr, 0);
|
||||||
else {
|
}
|
||||||
if(Curl_if2ip(AF_INET, ftpportstr, myhost, sizeof(myhost))) {
|
/* otherwise check if the given string is an interface */
|
||||||
/* The interface to IP conversion provided a dotted address */
|
else if(Curl_if2ip(AF_INET, ftpportstr, myhost, sizeof(myhost))) {
|
||||||
in=inet_addr(myhost);
|
/* The interface to IP conversion provided a dotted address */
|
||||||
addr = Curl_ip2addr(in, myhost, 0);
|
if(Curl_inet_pton(AF_INET, myhost, &in) > 0)
|
||||||
}
|
addr = Curl_ip2addr(AF_INET, &in, myhost, 0);
|
||||||
else if(strlen(ftpportstr)> 1) {
|
}
|
||||||
/* might be a host name! */
|
else if(strlen(ftpportstr)> 1) {
|
||||||
struct Curl_dns_entry *h=NULL;
|
/* might be a host name! */
|
||||||
int rc = Curl_resolv(conn, ftpportstr, 0, &h);
|
struct Curl_dns_entry *h=NULL;
|
||||||
if(rc == CURLRESOLV_PENDING)
|
int rc = Curl_resolv(conn, ftpportstr, 0, &h);
|
||||||
/* BLOCKING */
|
if(rc == CURLRESOLV_PENDING)
|
||||||
rc = Curl_wait_for_resolv(conn, &h);
|
/* BLOCKING */
|
||||||
if(h) {
|
rc = Curl_wait_for_resolv(conn, &h);
|
||||||
addr = h->addr;
|
if(h) {
|
||||||
/* when we return from this function, we can forget about this entry
|
addr = h->addr;
|
||||||
so we can unlock it now already */
|
/* when we return from this function, we can forget about this entry
|
||||||
Curl_resolv_unlock(data, h);
|
so we can unlock it now already */
|
||||||
|
Curl_resolv_unlock(data, h);
|
||||||
|
|
||||||
freeaddr = FALSE; /* make sure we don't free 'addr' in this function
|
freeaddr = FALSE; /* make sure we don't free 'addr' in this function
|
||||||
since it points to a DNS cache entry! */
|
since it points to a DNS cache entry! */
|
||||||
} /* (h) */
|
} /* (h) */
|
||||||
else {
|
else {
|
||||||
infof(data, "Failed to resolve host name %s\n", ftpportstr);
|
infof(data, "Failed to resolve host name %s\n", ftpportstr);
|
||||||
}
|
}
|
||||||
} /* strlen */
|
} /* strlen */
|
||||||
} /* CURL_INADDR_NONE */
|
|
||||||
} /* ftpportstr */
|
} /* ftpportstr */
|
||||||
|
|
||||||
if(!addr) {
|
if(!addr) {
|
||||||
|
|||||||
@@ -289,80 +289,6 @@ CURLcode Curl_wait_for_resolv(struct connectdata *conn,
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_IPV6 /* CURLRES_IPV6 */
|
|
||||||
|
|
||||||
struct namebuf6 {
|
|
||||||
struct hostent hostentry;
|
|
||||||
struct in6_addr addrentry;
|
|
||||||
char *h_addr_list[2];
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Curl_ip2addr6() takes an ipv6 internet address as input parameter
|
|
||||||
* together with a pointer to the string version of the address, and it
|
|
||||||
* returns a Curl_addrinfo chain filled in correctly with information for this
|
|
||||||
* address/host.
|
|
||||||
*
|
|
||||||
* The input parameters ARE NOT checked for validity but they are expected
|
|
||||||
* to have been checked already when this is called.
|
|
||||||
*/
|
|
||||||
Curl_addrinfo *Curl_ip2addr6(struct in6_addr *in,
|
|
||||||
const char *hostname, int port)
|
|
||||||
{
|
|
||||||
Curl_addrinfo *ai;
|
|
||||||
|
|
||||||
#if defined(VMS) && \
|
|
||||||
defined(__INITIAL_POINTER_SIZE) && (__INITIAL_POINTER_SIZE == 64)
|
|
||||||
#pragma pointer_size save
|
|
||||||
#pragma pointer_size short
|
|
||||||
#pragma message disable PTRMISMATCH
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct hostent *h;
|
|
||||||
struct in6_addr *addrentry;
|
|
||||||
struct namebuf6 *buf;
|
|
||||||
char *hoststr;
|
|
||||||
|
|
||||||
DEBUGASSERT(in && hostname);
|
|
||||||
|
|
||||||
buf = malloc(sizeof(struct namebuf6));
|
|
||||||
if(!buf)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
hoststr = strdup(hostname);
|
|
||||||
if(!hoststr) {
|
|
||||||
free(buf);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
addrentry = &buf->addrentry;
|
|
||||||
memcpy(addrentry, in, sizeof(struct in6_addr));
|
|
||||||
|
|
||||||
h = &buf->hostentry;
|
|
||||||
h->h_name = hoststr;
|
|
||||||
h->h_aliases = NULL;
|
|
||||||
h->h_addrtype = AF_INET6;
|
|
||||||
h->h_length = sizeof(struct in6_addr);
|
|
||||||
h->h_addr_list = &buf->h_addr_list[0];
|
|
||||||
h->h_addr_list[0] = (char*)addrentry;
|
|
||||||
h->h_addr_list[1] = NULL; /* terminate list of entries */
|
|
||||||
|
|
||||||
#if defined(VMS) && \
|
|
||||||
defined(__INITIAL_POINTER_SIZE) && (__INITIAL_POINTER_SIZE == 64)
|
|
||||||
#pragma pointer_size restore
|
|
||||||
#pragma message enable PTRMISMATCH
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ai = Curl_he2ai(h, port);
|
|
||||||
|
|
||||||
free(hoststr);
|
|
||||||
free(buf);
|
|
||||||
|
|
||||||
return ai;
|
|
||||||
}
|
|
||||||
#endif /* CURLRES_IPV6 */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Curl_getaddrinfo() - when using ares
|
* Curl_getaddrinfo() - when using ares
|
||||||
@@ -379,22 +305,24 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
|
|||||||
{
|
{
|
||||||
char *bufp;
|
char *bufp;
|
||||||
struct SessionHandle *data = conn->data;
|
struct SessionHandle *data = conn->data;
|
||||||
in_addr_t in = inet_addr(hostname);
|
struct in_addr in;
|
||||||
int family = PF_INET;
|
int family = PF_INET;
|
||||||
#ifdef ENABLE_IPV6 /* CURLRES_IPV6 */
|
#ifdef ENABLE_IPV6 /* CURLRES_IPV6 */
|
||||||
struct in6_addr in6;
|
struct in6_addr in6;
|
||||||
#endif /* CURLRES_IPV6 */
|
#endif /* CURLRES_IPV6 */
|
||||||
*waitp = FALSE;
|
*waitp = FALSE;
|
||||||
|
|
||||||
if(in != CURL_INADDR_NONE) {
|
/* 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 */
|
/* This is a dotted IP address 123.123.123.123-style */
|
||||||
return Curl_ip2addr(in, hostname, port);
|
return Curl_ip2addr(AF_INET, &in, hostname, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_IPV6 /* CURLRES_IPV6 */
|
#ifdef ENABLE_IPV6 /* CURLRES_IPV6 */
|
||||||
|
/* Otherwise, check if this is an IPv6 address string */
|
||||||
if (Curl_inet_pton (AF_INET6, hostname, &in6) > 0) {
|
if (Curl_inet_pton (AF_INET6, hostname, &in6) > 0) {
|
||||||
/* This must be an IPv6 address literal. */
|
/* This must be an IPv6 address literal. */
|
||||||
return Curl_ip2addr6(&in6, hostname, port);
|
return Curl_ip2addr(AF_INET6, &in6, hostname, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(data->set.ip_version) {
|
switch(data->set.ip_version) {
|
||||||
|
|||||||
85
lib/hostip.c
85
lib/hostip.c
@@ -724,88 +724,3 @@ Curl_addrinfo *Curl_addrinfo_copy(const void *org, int port)
|
|||||||
return Curl_he2ai(orig, port);
|
return Curl_he2ai(orig, port);
|
||||||
}
|
}
|
||||||
#endif /* CURLRES_ADDRINFO_COPY */
|
#endif /* CURLRES_ADDRINFO_COPY */
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* Only for plain-ipv4 and c-ares builds (NOTE: c-ares builds can be IPv6
|
|
||||||
* enabled)
|
|
||||||
**********************************************************************/
|
|
||||||
|
|
||||||
#if defined(CURLRES_IPV4) || defined(CURLRES_ARES)
|
|
||||||
|
|
||||||
struct namebuf4 {
|
|
||||||
struct hostent hostentry;
|
|
||||||
struct in_addr addrentry;
|
|
||||||
char *h_addr_list[2];
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Curl_ip2addr() takes a 32bit ipv4 internet address as input parameter
|
|
||||||
* together with a pointer to the string version of the address, and it
|
|
||||||
* returns a Curl_addrinfo chain filled in correctly with information for this
|
|
||||||
* address/host.
|
|
||||||
*
|
|
||||||
* The input parameters ARE NOT checked for validity but they are expected
|
|
||||||
* to have been checked already when this is called.
|
|
||||||
*/
|
|
||||||
Curl_addrinfo *Curl_ip2addr(in_addr_t num, const char *hostname, int port)
|
|
||||||
{
|
|
||||||
Curl_addrinfo *ai;
|
|
||||||
|
|
||||||
#if defined(VMS) && \
|
|
||||||
defined(__INITIAL_POINTER_SIZE) && (__INITIAL_POINTER_SIZE == 64)
|
|
||||||
#pragma pointer_size save
|
|
||||||
#pragma pointer_size short
|
|
||||||
#pragma message disable PTRMISMATCH
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct hostent *h;
|
|
||||||
struct in_addr *addrentry;
|
|
||||||
struct namebuf4 *buf;
|
|
||||||
char *hoststr;
|
|
||||||
|
|
||||||
DEBUGASSERT(hostname);
|
|
||||||
|
|
||||||
buf = malloc(sizeof(struct namebuf4));
|
|
||||||
if(!buf)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
hoststr = strdup(hostname);
|
|
||||||
if(!hoststr) {
|
|
||||||
free(buf);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
addrentry = &buf->addrentry;
|
|
||||||
#ifdef _CRAYC
|
|
||||||
/* On UNICOS, s_addr is a bit field and for some reason assigning to it
|
|
||||||
* doesn't work. There must be a better fix than this ugly hack.
|
|
||||||
*/
|
|
||||||
memcpy(addrentry, &num, SIZEOF_in_addr);
|
|
||||||
#else
|
|
||||||
addrentry->s_addr = num;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
h = &buf->hostentry;
|
|
||||||
h->h_name = hoststr;
|
|
||||||
h->h_aliases = NULL;
|
|
||||||
h->h_addrtype = AF_INET;
|
|
||||||
h->h_length = sizeof(struct in_addr);
|
|
||||||
h->h_addr_list = &buf->h_addr_list[0];
|
|
||||||
h->h_addr_list[0] = (char*)addrentry;
|
|
||||||
h->h_addr_list[1] = NULL; /* terminate list of entries */
|
|
||||||
|
|
||||||
#if defined(VMS) && \
|
|
||||||
defined(__INITIAL_POINTER_SIZE) && (__INITIAL_POINTER_SIZE == 64)
|
|
||||||
#pragma pointer_size restore
|
|
||||||
#pragma message enable PTRMISMATCH
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ai = Curl_he2ai(h, port);
|
|
||||||
|
|
||||||
free(hoststr);
|
|
||||||
free(buf);
|
|
||||||
|
|
||||||
return ai;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* CURLRES_IPV4 || CURLRES_ARES */
|
|
||||||
|
|||||||
@@ -104,11 +104,6 @@
|
|||||||
#define ares_destroy(x) do {} while(0)
|
#define ares_destroy(x) do {} while(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CURLRES_IPV6) && defined(CURLRES_ARES)
|
|
||||||
Curl_addrinfo *Curl_ip2addr6(struct in6_addr *in,
|
|
||||||
const char *hostname, int port);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct addrinfo;
|
struct addrinfo;
|
||||||
struct hostent;
|
struct hostent;
|
||||||
struct SessionHandle;
|
struct SessionHandle;
|
||||||
@@ -224,10 +219,6 @@ CURLcode Curl_addrinfo6_callback(void *arg,
|
|||||||
Curl_addrinfo *ai);
|
Curl_addrinfo *ai);
|
||||||
|
|
||||||
|
|
||||||
/* [ipv4/ares only] Creates a Curl_addrinfo struct from a numerical-only IP
|
|
||||||
address */
|
|
||||||
Curl_addrinfo *Curl_ip2addr(in_addr_t num, const char *hostname, int port);
|
|
||||||
|
|
||||||
/* Clone a Curl_addrinfo struct, works protocol independently */
|
/* Clone a Curl_addrinfo struct, works protocol independently */
|
||||||
Curl_addrinfo *Curl_addrinfo_copy(const void *orig, int port);
|
Curl_addrinfo *Curl_addrinfo_copy(const void *orig, int port);
|
||||||
|
|
||||||
|
|||||||
@@ -118,20 +118,18 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
|
|||||||
#endif
|
#endif
|
||||||
Curl_addrinfo *ai = NULL;
|
Curl_addrinfo *ai = NULL;
|
||||||
struct hostent *h = NULL;
|
struct hostent *h = NULL;
|
||||||
in_addr_t in;
|
struct in_addr in;
|
||||||
struct hostent *buf = NULL;
|
struct hostent *buf = NULL;
|
||||||
|
|
||||||
#ifdef CURL_DISABLE_VERBOSE_STRINGS
|
#ifdef CURL_DISABLE_VERBOSE_STRINGS
|
||||||
(void)conn;
|
(void)conn;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
(void)port; /* unused in IPv4 code */
|
|
||||||
|
|
||||||
*waitp = 0; /* don't wait, we act synchronously */
|
*waitp = 0; /* don't wait, we act synchronously */
|
||||||
|
|
||||||
if(1 == Curl_inet_pton(AF_INET, hostname, &in))
|
if(Curl_inet_pton(AF_INET, hostname, &in) > 0)
|
||||||
/* This is a dotted IP address 123.123.123.123-style */
|
/* This is a dotted IP address 123.123.123.123-style */
|
||||||
return Curl_ip2addr(in, hostname, port);
|
return Curl_ip2addr(AF_INET, &in, hostname, port);
|
||||||
|
|
||||||
#if defined(HAVE_GETHOSTBYNAME_R)
|
#if defined(HAVE_GETHOSTBYNAME_R)
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -70,6 +70,7 @@
|
|||||||
#include "strerror.h"
|
#include "strerror.h"
|
||||||
#include "url.h"
|
#include "url.h"
|
||||||
#include "multiif.h"
|
#include "multiif.h"
|
||||||
|
#include "inet_pton.h"
|
||||||
|
|
||||||
#define _MPRINTF_REPLACE /* use our functions only */
|
#define _MPRINTF_REPLACE /* use our functions only */
|
||||||
#include <curl/mprintf.h>
|
#include <curl/mprintf.h>
|
||||||
@@ -665,14 +666,13 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
|
|||||||
{
|
{
|
||||||
struct hostent *h = NULL;
|
struct hostent *h = NULL;
|
||||||
struct SessionHandle *data = conn->data;
|
struct SessionHandle *data = conn->data;
|
||||||
in_addr_t in;
|
struct in_addr in;
|
||||||
|
|
||||||
*waitp = 0; /* don't wait, we act synchronously */
|
*waitp = 0; /* don't wait, we act synchronously */
|
||||||
|
|
||||||
in = inet_addr(hostname);
|
if(Curl_inet_pton(AF_INET, hostname, &in) > 0)
|
||||||
if(in != CURL_INADDR_NONE)
|
|
||||||
/* This is a dotted IP address 123.123.123.123-style */
|
/* This is a dotted IP address 123.123.123.123-style */
|
||||||
return Curl_ip2addr(in, hostname, port);
|
return Curl_ip2addr(AF_INET, &in, hostname, port);
|
||||||
|
|
||||||
/* fire up a new resolver thread! */
|
/* fire up a new resolver thread! */
|
||||||
if(init_resolve_thread(conn, hostname, port, NULL)) {
|
if(init_resolve_thread(conn, hostname, port, NULL)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user