cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: DNS round-robin multi-homed FTP server + EPSV = trouble

From: Richard Atterer <richard_at_list04.atterer.net>
Date: Sun, 5 Dec 2004 02:22:10 +0100

On Sat, Dec 04, 2004 at 11:03:55PM +0100, Daniel Stenberg wrote:
> Correct. It should certainly *not* resolve the host name again. I would
> very much appreciate that patch!

The attached patch fixes the issue for me.

However, I am not 100% sure about one issue:
Does Curl_printable_address(conn->ip_addr, ...) output a string for
the first IP returned by the DNS query, or for the actual IP of the control
connection? In the former case, there might still be a problem if the first
DNS IP is not reachable.

Regarding the implementation, I find it weird to leave the call to
Curl_resolv (ftp.c:1601) in the code, because its argument is always an IP
address in string format. However, after playing around with
Curl_ip2addr()/Curl_cache_addr() etc for a while, this turned out to be the
easiest fix - maybe there's a better way?

Cheers,

  Richard

-- 
  __   _
  |_) /|  Richard Atterer     |  GnuPG key:
  | \/¯|  http://atterer.net  |  0x888354F7
  ¯ '` ¯
--- ftp.c.orig	2004-10-18 00:21:02.000000000 +0200
+++ ftp.c	2004-12-05 01:21:06.000000000 +0100
@@ -1486,8 +1486,8 @@
 
   /* newhost must be able to hold a full IP-style address in ASCII, which
      in the IPv6 case means 5*8-1 = 39 letters */
-  char newhost[48];
-  char *newhostp=NULL;
+#define NEWHOST_BUFSIZE 48
+  char newhost[NEWHOST_BUFSIZE];
 
   for (modeoff = (data->set.ftp_use_epsv?0:1);
        mode[modeoff]; modeoff++) {
@@ -1536,7 +1536,6 @@
 
     snprintf(newhost, sizeof(newhost),
              "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
-    newhostp = newhost;
     newport = (port[0]<<8) + port[1];
   }
   else if (229 == results[modeoff]) {
@@ -1565,8 +1564,8 @@
         if(ptr) {
           newport = num;
 
-          /* we should use the same host we already are connected to */
-          newhostp = conn->host.name;
+          /* We must use the same IP we are already connected to */
+          Curl_printable_address(conn->ip_addr, newhost, NEWHOST_BUFSIZE);
         }
       }
       else
@@ -1598,12 +1597,12 @@
   }
   else {
     /* normal, direct, ftp connection */
-    rc = Curl_resolv(conn, newhostp, newport, &addr);
+    rc = Curl_resolv(conn, newhost, newport, &addr);
     if(rc == CURLRESOLV_PENDING)
       rc = Curl_wait_for_resolv(conn, &addr);
 
     if(!addr) {
-      failf(data, "Can't resolve new host %s:%d", newhostp, newport);
+      failf(data, "Can't resolve new host %s:%d", newhost, newport);
       return CURLE_FTP_CANT_GET_HOST;
     }
     connectport = newport; /* we connect to the remote port */
@@ -1628,13 +1627,13 @@
 
   if(data->set.verbose)
     /* this just dumps information about this second connection */
-    ftp_pasv_verbose(conn, conninfo, newhostp, connectport);
+    ftp_pasv_verbose(conn, conninfo, newhost, connectport);
 
 #ifndef CURL_DISABLE_HTTP
   if(conn->bits.tunnel_proxy) {
     /* We want "seamless" FTP operations through HTTP proxy tunnel */
     result = Curl_ConnectHTTPProxyTunnel(conn, SECONDARYSOCKET,
-                                         newhostp, newport);
+                                         newhost, newport);
     if(CURLE_OK != result)
       return result;
   }
Received on 2004-12-05