Commit 48dc74ae authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

more transparant support for IPv6 name resolving

parent 888d39e0
Loading
Loading
Loading
Loading
+11 −21
Original line number Diff line number Diff line
@@ -1020,19 +1020,19 @@ CURLcode _ftp(struct connectdata *conn)

    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,
      h=Curl_getaddrinfo(data,
                         getmyhost(myhost, sizeof(myhost)),
                     &hostdataptr);
                         0, &hostdataptr);
    }
    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 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;
@@ -1192,24 +1192,14 @@ CURLcode _ftp(struct connectdata *conn)
         * 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;
        }
+15 −7
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@

#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"
@@ -89,14 +90,17 @@ static char *MakeIP(unsigned long num,char *addr, int addr_len)
}

#ifdef ENABLE_IPV6
struct addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
Curl_addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
                                char *hostname,
			       int port)
                                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;
@@ -109,7 +113,7 @@ struct addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
  }
  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
@@ -119,8 +123,9 @@ struct addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
#define INADDR_NONE (unsigned long) ~0
#endif

struct hostent *Curl_gethost(struct SessionHandle *data,
Curl_addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
                                char *hostname,
                                int port,
                                char **bufp)
{
  struct hostent *h = NULL;
@@ -137,6 +142,7 @@ struct hostent *Curl_gethost(struct SessionHandle *data,
    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 ) {
@@ -216,6 +222,8 @@ struct hostent *Curl_gethost(struct SessionHandle *data,
  return (h);
}

#endif /* end of IPv4-specific code */

/*
 * local variables:
 * eval: (load-file "../curl-mode.el")
+12 −6
Original line number Diff line number Diff line
@@ -24,12 +24,18 @@
 *****************************************************************************/

struct addrinfo;
struct addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
                             char *hostname,
                             int port);
struct hostent;
struct SessionHandle;

#ifdef ENABLE_IPV6
typedef struct addrinfo Curl_addrinfo;
#else
typedef struct hostent Curl_addrinfo;
#endif

struct hostent *Curl_gethost(struct SessionHandle *data,
Curl_addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
                                char *hostname,
                                int port,
                                char **bufp);

#endif
+9 −16
Original line number Diff line number Diff line
@@ -1158,11 +1158,11 @@ static CURLcode ConnectPlease(struct SessionHandle *data,
    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 */
@@ -2163,16 +2163,11 @@ static CURLcode Connect(struct SessionHandle *data,

    /* 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;
    }
@@ -2182,12 +2177,10 @@ static CURLcode Connect(struct SessionHandle *data,
       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
    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;
+4 −3
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
/* This file is for lib internal stuff */

#include "setup.h"
#include "hostip.h"

#define PORT_FTP 21
#define PORT_TELNET 23
@@ -223,12 +224,12 @@ struct connectdata {
#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 */