if(data->set.ftpport) {
if(Curl_if2ip(data->set.ftpport, myhost, sizeof(myhost))) {
- h = Curl_gethost(data, myhost, &hostdataptr);
+ h = Curl_getaddrinfo(data, myhost, 0, &hostdataptr);
}
else {
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)
strcpy(myhost, data->set.ftpport); /* buffer overflow risk */
}
}
if(! *myhost) {
- h=Curl_gethost(data,
- getmyhost(myhost, sizeof(myhost)),
- &hostdataptr);
+ h=Curl_getaddrinfo(data,
+ getmyhost(myhost, sizeof(myhost)),
+ 0, &hostdataptr);
}
infof(data, "We connect from %s\n", myhost);
unsigned short newport; /* remote port, not necessary the local one */
unsigned short connectport; /* the local port connect() should use! */
char newhost[32];
-#ifdef ENABLE_IPV6
- struct addrinfo *res;
-#else
- struct hostent *he;
+
+ Curl_addrinfo *he;
char *hostdataptr=NULL;
+
+#ifndef ENABLE_IPV6
char *ip_addr;
#endif
char *str=buf;
* proxy again here. We already have the name info for it since the
* previous lookup.
*/
-#ifdef ENABLE_IPV6
- res = conn->hp;
-#else
he = conn->hp;
-#endif
connectport =
(unsigned short)conn->port; /* we connect to the proxy's port */
}
else {
/* normal, direct, ftp connection */
-#ifdef ENABLE_IPV6
- res = Curl_getaddrinfo(data, newhost, newport);
- if(!res)
-#else
- he = Curl_gethost(data, newhost, &hostdataptr);
- if(!he)
-#endif
- {
+ he = Curl_getaddrinfo(data, newhost, newport, &hostdataptr);
+ if(!he) {
failf(data, "Can't resolve new host %s", newhost);
return CURLE_FTP_CANT_GET_HOST;
}
#include "urldata.h"
#include "sendf.h"
+#include "hostip.h"
#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
#include "inet_ntoa_r.h"
}
#ifdef ENABLE_IPV6
-struct addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
- char *hostname,
- int port)
+Curl_addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
+ char *hostname,
+ int port,
+ char **bufp)
{
struct addrinfo hints, *res;
int error;
char sbuf[NI_MAXSERV];
+ *bufp=NULL; /* pointer unused with IPv6 */
+
memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
}
return res;
}
-#endif
+#else /* following code is IPv4-only */
/* 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
#define INADDR_NONE (unsigned long) ~0
#endif
-struct hostent *Curl_gethost(struct SessionHandle *data,
- char *hostname,
- char **bufp)
+Curl_addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
+ char *hostname,
+ int port,
+ char **bufp)
{
struct hostent *h = NULL;
unsigned long in;
return NULL; /* major failure */
*bufp = buf;
+ port=0; /* unused in IPv4 code */
ret = 0; /* to prevent the compiler warning */
if ( (in=inet_addr(hostname)) != INADDR_NONE ) {
return (h);
}
+#endif /* end of IPv4-specific code */
+
/*
* local variables:
* eval: (load-file "../curl-mode.el")
*****************************************************************************/
struct addrinfo;
-struct addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
- char *hostname,
- int port);
+struct hostent;
+struct SessionHandle;
-struct hostent *Curl_gethost(struct SessionHandle *data,
- char *hostname,
- char **bufp);
+#ifdef ENABLE_IPV6
+typedef struct addrinfo Curl_addrinfo;
+#else
+typedef struct hostent Curl_addrinfo;
+#endif
+
+Curl_addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
+ char *hostname,
+ int port,
+ char **bufp);
#endif
unsigned long in;
if(Curl_if2ip(data->set.device, myhost, sizeof(myhost))) {
- h = Curl_gethost(data, myhost, &hostdataptr);
+ h = Curl_getaddrinfo(data, myhost, 0, &hostdataptr);
}
else {
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) {
/* we know data->set.device is shorter than the myhost array */
/* Resolve target host right on */
if(!conn->hp) {
-#ifdef ENABLE_IPV6
- /* it might already be set if reusing a connection */
- conn->hp = Curl_getaddrinfo(data, conn->name, conn->port);
-#else
/* it might already be set if reusing a connection */
- conn->hp = Curl_gethost(data, conn->name, &conn->hostent_buf);
-#endif
+ conn->hp = Curl_getaddrinfo(data, conn->name, conn->port,
+ &conn->hostent_buf);
}
- if(!conn->hp)
- {
+ if(!conn->hp) {
failf(data, "Couldn't resolve host '%s'", conn->name);
return CURLE_COULDNT_RESOLVE_HOST;
}
if we're reusing an existing connection. */
/* resolve proxy */
-#ifdef ENABLE_IPV6
- /* it might already be set if reusing a connection */
- conn->hp = Curl_getaddrinfo(data, conn->proxyhost, conn->port);
-#else
- conn->hp = Curl_gethost(data, conn->proxyhost, &conn->hostent_buf);
-#endif
+ /* it might already be set if reusing a connection */
+ conn->hp = Curl_getaddrinfo(data, conn->proxyhost, conn->port,
+ &conn->hostent_buf);
+
if(!conn->hp) {
failf(data, "Couldn't resolve proxy '%s'", conn->proxyhost);
return CURLE_COULDNT_RESOLVE_PROXY;
/* This file is for lib internal stuff */
#include "setup.h"
+#include "hostip.h"
#define PORT_FTP 21
#define PORT_TELNET 23
#define PROT_FILE (1<<8)
#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
- struct addrinfo *hp; /* host info pointer list */
struct addrinfo *ai; /* the particular host we use */
#else
- char *hostent_buf; /* pointer to allocated memory for name info */
- struct hostent *hp;
struct sockaddr_in serv_addr;
#endif
char protostr[64]; /* store the protocol string in this buffer */