mirror of
https://github.com/curl/curl.git
synced 2026-08-24 16:33:33 +03:00
more transparant support for IPv6 name resolving
This commit is contained in:
parent
888d39e083
commit
48dc74aecc
5 changed files with 51 additions and 53 deletions
32
lib/ftp.c
32
lib/ftp.c
|
|
@ -1020,19 +1020,19 @@ CURLcode _ftp(struct connectdata *conn)
|
||||||
|
|
||||||
if(data->set.ftpport) {
|
if(data->set.ftpport) {
|
||||||
if(Curl_if2ip(data->set.ftpport, myhost, sizeof(myhost))) {
|
if(Curl_if2ip(data->set.ftpport, myhost, sizeof(myhost))) {
|
||||||
h = Curl_gethost(data, myhost, &hostdataptr);
|
h = Curl_getaddrinfo(data, myhost, 0, &hostdataptr);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(strlen(data->set.ftpport)>1)
|
if(strlen(data->set.ftpport)>1)
|
||||||
h = Curl_gethost(data, data->set.ftpport, &hostdataptr);
|
h = Curl_getaddrinfo(data, data->set.ftpport, 0, &hostdataptr);
|
||||||
if(h)
|
if(h)
|
||||||
strcpy(myhost, data->set.ftpport); /* buffer overflow risk */
|
strcpy(myhost, data->set.ftpport); /* buffer overflow risk */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(! *myhost) {
|
if(! *myhost) {
|
||||||
h=Curl_gethost(data,
|
h=Curl_getaddrinfo(data,
|
||||||
getmyhost(myhost, sizeof(myhost)),
|
getmyhost(myhost, sizeof(myhost)),
|
||||||
&hostdataptr);
|
0, &hostdataptr);
|
||||||
}
|
}
|
||||||
infof(data, "We connect from %s\n", myhost);
|
infof(data, "We connect from %s\n", myhost);
|
||||||
|
|
||||||
|
|
@ -1151,11 +1151,11 @@ CURLcode _ftp(struct connectdata *conn)
|
||||||
unsigned short newport; /* remote port, not necessary the local one */
|
unsigned short newport; /* remote port, not necessary the local one */
|
||||||
unsigned short connectport; /* the local port connect() should use! */
|
unsigned short connectport; /* the local port connect() should use! */
|
||||||
char newhost[32];
|
char newhost[32];
|
||||||
#ifdef ENABLE_IPV6
|
|
||||||
struct addrinfo *res;
|
Curl_addrinfo *he;
|
||||||
#else
|
|
||||||
struct hostent *he;
|
|
||||||
char *hostdataptr=NULL;
|
char *hostdataptr=NULL;
|
||||||
|
|
||||||
|
#ifndef ENABLE_IPV6
|
||||||
char *ip_addr;
|
char *ip_addr;
|
||||||
#endif
|
#endif
|
||||||
char *str=buf;
|
char *str=buf;
|
||||||
|
|
@ -1192,24 +1192,14 @@ CURLcode _ftp(struct connectdata *conn)
|
||||||
* proxy again here. We already have the name info for it since the
|
* proxy again here. We already have the name info for it since the
|
||||||
* previous lookup.
|
* previous lookup.
|
||||||
*/
|
*/
|
||||||
#ifdef ENABLE_IPV6
|
|
||||||
res = conn->hp;
|
|
||||||
#else
|
|
||||||
he = conn->hp;
|
he = conn->hp;
|
||||||
#endif
|
|
||||||
connectport =
|
connectport =
|
||||||
(unsigned short)conn->port; /* we connect to the proxy's port */
|
(unsigned short)conn->port; /* we connect to the proxy's port */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* normal, direct, ftp connection */
|
/* normal, direct, ftp connection */
|
||||||
#ifdef ENABLE_IPV6
|
he = Curl_getaddrinfo(data, newhost, newport, &hostdataptr);
|
||||||
res = Curl_getaddrinfo(data, newhost, newport);
|
if(!he) {
|
||||||
if(!res)
|
|
||||||
#else
|
|
||||||
he = Curl_gethost(data, newhost, &hostdataptr);
|
|
||||||
if(!he)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
failf(data, "Can't resolve new host %s", newhost);
|
failf(data, "Can't resolve new host %s", newhost);
|
||||||
return CURLE_FTP_CANT_GET_HOST;
|
return CURLE_FTP_CANT_GET_HOST;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
22
lib/hostip.c
22
lib/hostip.c
|
|
@ -55,6 +55,7 @@
|
||||||
|
|
||||||
#include "urldata.h"
|
#include "urldata.h"
|
||||||
#include "sendf.h"
|
#include "sendf.h"
|
||||||
|
#include "hostip.h"
|
||||||
|
|
||||||
#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
|
#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
|
||||||
#include "inet_ntoa_r.h"
|
#include "inet_ntoa_r.h"
|
||||||
|
|
@ -89,14 +90,17 @@ static char *MakeIP(unsigned long num,char *addr, int addr_len)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
struct addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
|
Curl_addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
|
||||||
char *hostname,
|
char *hostname,
|
||||||
int port)
|
int port,
|
||||||
|
char **bufp)
|
||||||
{
|
{
|
||||||
struct addrinfo hints, *res;
|
struct addrinfo hints, *res;
|
||||||
int error;
|
int error;
|
||||||
char sbuf[NI_MAXSERV];
|
char sbuf[NI_MAXSERV];
|
||||||
|
|
||||||
|
*bufp=NULL; /* pointer unused with IPv6 */
|
||||||
|
|
||||||
memset(&hints, 0, sizeof(hints));
|
memset(&hints, 0, sizeof(hints));
|
||||||
hints.ai_family = PF_UNSPEC;
|
hints.ai_family = PF_UNSPEC;
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
|
@ -109,7 +113,7 @@ struct addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
#endif
|
#else /* following code is IPv4-only */
|
||||||
|
|
||||||
/* The original code to this function was once stolen from the Dancer source
|
/* The original code to this function was once stolen from the Dancer source
|
||||||
code, written by Bjorn Reese, it has since been patched and modified
|
code, written by Bjorn Reese, it has since been patched and modified
|
||||||
|
|
@ -119,9 +123,10 @@ struct addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
|
||||||
#define INADDR_NONE (unsigned long) ~0
|
#define INADDR_NONE (unsigned long) ~0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct hostent *Curl_gethost(struct SessionHandle *data,
|
Curl_addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
|
||||||
char *hostname,
|
char *hostname,
|
||||||
char **bufp)
|
int port,
|
||||||
|
char **bufp)
|
||||||
{
|
{
|
||||||
struct hostent *h = NULL;
|
struct hostent *h = NULL;
|
||||||
unsigned long in;
|
unsigned long in;
|
||||||
|
|
@ -137,6 +142,7 @@ struct hostent *Curl_gethost(struct SessionHandle *data,
|
||||||
return NULL; /* major failure */
|
return NULL; /* major failure */
|
||||||
*bufp = buf;
|
*bufp = buf;
|
||||||
|
|
||||||
|
port=0; /* unused in IPv4 code */
|
||||||
ret = 0; /* to prevent the compiler warning */
|
ret = 0; /* to prevent the compiler warning */
|
||||||
|
|
||||||
if ( (in=inet_addr(hostname)) != INADDR_NONE ) {
|
if ( (in=inet_addr(hostname)) != INADDR_NONE ) {
|
||||||
|
|
@ -216,6 +222,8 @@ struct hostent *Curl_gethost(struct SessionHandle *data,
|
||||||
return (h);
|
return (h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* end of IPv4-specific code */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* local variables:
|
* local variables:
|
||||||
* eval: (load-file "../curl-mode.el")
|
* eval: (load-file "../curl-mode.el")
|
||||||
|
|
|
||||||
18
lib/hostip.h
18
lib/hostip.h
|
|
@ -24,12 +24,18 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
struct addrinfo;
|
struct addrinfo;
|
||||||
struct addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
|
struct hostent;
|
||||||
char *hostname,
|
struct SessionHandle;
|
||||||
int port);
|
|
||||||
|
|
||||||
struct hostent *Curl_gethost(struct SessionHandle *data,
|
#ifdef ENABLE_IPV6
|
||||||
char *hostname,
|
typedef struct addrinfo Curl_addrinfo;
|
||||||
char **bufp);
|
#else
|
||||||
|
typedef struct hostent Curl_addrinfo;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Curl_addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
|
||||||
|
char *hostname,
|
||||||
|
int port,
|
||||||
|
char **bufp);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
25
lib/url.c
25
lib/url.c
|
|
@ -1158,11 +1158,11 @@ static CURLcode ConnectPlease(struct SessionHandle *data,
|
||||||
unsigned long in;
|
unsigned long in;
|
||||||
|
|
||||||
if(Curl_if2ip(data->set.device, myhost, sizeof(myhost))) {
|
if(Curl_if2ip(data->set.device, myhost, sizeof(myhost))) {
|
||||||
h = Curl_gethost(data, myhost, &hostdataptr);
|
h = Curl_getaddrinfo(data, myhost, 0, &hostdataptr);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(strlen(data->set.device)>1) {
|
if(strlen(data->set.device)>1) {
|
||||||
h = Curl_gethost(data, data->set.device, &hostdataptr);
|
h = Curl_getaddrinfo(data, data->set.device, 0, &hostdataptr);
|
||||||
}
|
}
|
||||||
if(h) {
|
if(h) {
|
||||||
/* we know data->set.device is shorter than the myhost array */
|
/* we know data->set.device is shorter than the myhost array */
|
||||||
|
|
@ -2163,16 +2163,11 @@ static CURLcode Connect(struct SessionHandle *data,
|
||||||
|
|
||||||
/* Resolve target host right on */
|
/* Resolve target host right on */
|
||||||
if(!conn->hp) {
|
if(!conn->hp) {
|
||||||
#ifdef ENABLE_IPV6
|
|
||||||
/* it might already be set if reusing a connection */
|
/* it might already be set if reusing a connection */
|
||||||
conn->hp = Curl_getaddrinfo(data, conn->name, conn->port);
|
conn->hp = Curl_getaddrinfo(data, conn->name, conn->port,
|
||||||
#else
|
&conn->hostent_buf);
|
||||||
/* it might already be set if reusing a connection */
|
|
||||||
conn->hp = Curl_gethost(data, conn->name, &conn->hostent_buf);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
if(!conn->hp)
|
if(!conn->hp) {
|
||||||
{
|
|
||||||
failf(data, "Couldn't resolve host '%s'", conn->name);
|
failf(data, "Couldn't resolve host '%s'", conn->name);
|
||||||
return CURLE_COULDNT_RESOLVE_HOST;
|
return CURLE_COULDNT_RESOLVE_HOST;
|
||||||
}
|
}
|
||||||
|
|
@ -2182,12 +2177,10 @@ static CURLcode Connect(struct SessionHandle *data,
|
||||||
if we're reusing an existing connection. */
|
if we're reusing an existing connection. */
|
||||||
|
|
||||||
/* resolve proxy */
|
/* resolve proxy */
|
||||||
#ifdef ENABLE_IPV6
|
/* it might already be set if reusing a connection */
|
||||||
/* it might already be set if reusing a connection */
|
conn->hp = Curl_getaddrinfo(data, conn->proxyhost, conn->port,
|
||||||
conn->hp = Curl_getaddrinfo(data, conn->proxyhost, conn->port);
|
&conn->hostent_buf);
|
||||||
#else
|
|
||||||
conn->hp = Curl_gethost(data, conn->proxyhost, &conn->hostent_buf);
|
|
||||||
#endif
|
|
||||||
if(!conn->hp) {
|
if(!conn->hp) {
|
||||||
failf(data, "Couldn't resolve proxy '%s'", conn->proxyhost);
|
failf(data, "Couldn't resolve proxy '%s'", conn->proxyhost);
|
||||||
return CURLE_COULDNT_RESOLVE_PROXY;
|
return CURLE_COULDNT_RESOLVE_PROXY;
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
/* This file is for lib internal stuff */
|
/* This file is for lib internal stuff */
|
||||||
|
|
||||||
#include "setup.h"
|
#include "setup.h"
|
||||||
|
#include "hostip.h"
|
||||||
|
|
||||||
#define PORT_FTP 21
|
#define PORT_FTP 21
|
||||||
#define PORT_TELNET 23
|
#define PORT_TELNET 23
|
||||||
|
|
@ -223,12 +224,12 @@ struct connectdata {
|
||||||
#define PROT_FILE (1<<8)
|
#define PROT_FILE (1<<8)
|
||||||
#define PROT_FTPS (1<<9)
|
#define PROT_FTPS (1<<9)
|
||||||
|
|
||||||
|
Curl_addrinfo *hp; /* IP-protocol independent host info pointer list */
|
||||||
|
char *hostent_buf; /* pointer to allocated memory for name info */
|
||||||
|
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
struct addrinfo *hp; /* host info pointer list */
|
|
||||||
struct addrinfo *ai; /* the particular host we use */
|
struct addrinfo *ai; /* the particular host we use */
|
||||||
#else
|
#else
|
||||||
char *hostent_buf; /* pointer to allocated memory for name info */
|
|
||||||
struct hostent *hp;
|
|
||||||
struct sockaddr_in serv_addr;
|
struct sockaddr_in serv_addr;
|
||||||
#endif
|
#endif
|
||||||
char protostr[64]; /* store the protocol string in this buffer */
|
char protostr[64]; /* store the protocol string in this buffer */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue