You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by wr...@apache.org on 2007/12/11 13:01:36 UTC

svn commit: r603218 - /httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c

Author: wrowe
Date: Tue Dec 11 04:01:33 2007
New Revision: 603218

URL: http://svn.apache.org/viewvc?rev=603218&view=rev
Log:
Based on hints provided by Joe and Colm - save ourselves a long
roundtrip and duplicate the sockaddr for the ftp_cmd_eptr origin
interface/family/ip address, simply injecting the port.

Modified:
    httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c

Modified: httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c
URL: http://svn.apache.org/viewvc/httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c?rev=603218&r1=603217&r2=603218&view=diff
==============================================================================
--- httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c (original)
+++ httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c Tue Dec 11 04:01:33 2007
@@ -1695,7 +1695,6 @@
     apr_sockaddr_t *sa;
     apr_socket_t *s;
     apr_status_t rv;
-    apr_port_t local_port;
     char *arg_tok, *ip_addr;
     apr_int32_t family;
     apr_port_t port;
@@ -1742,45 +1741,25 @@
         return FTP_REPLY_CANNOT_OPEN_DATACONN;
     }
 
+    sa = apr_palloc(c->pool, sizeof(apr_sockaddr_t));
+    memcpy(sa, c->local_addr, sizeof(apr_sockaddr_t));
+    sa->next = NULL;
+    if (sa->family == APR_INET)
+        addr->ipaddr_ptr = &(addr->sa.sin.sin_addr);
+#if APR_HAVE_IPV6
+    else if (sa->family == APR_INET6)
+        addr->ipaddr_ptr = &(addr->sa.sin6.sin6_addr);
+#endif
+
     if (fsc->active_min != -1) {
-        local_port = fsc->active_min +
+        sa->port = fsc->active_min +
                      (apr_port_t)(rand() % (fsc->active_max -
                                             fsc->active_min + 1));
     }
     else {
-        local_port = 0;
-    }
-
-    /* XXX: Anything special to handle IPv6 ip_addr string where c->remote_ip
-     * is IPv4 mapped?
-     */
-    if (((c->local_addr->family == APR_INET) && (family == APR_INET))
-#if APR_HAVE_IPV6
-            || ((c->local_addr->family == APR_INET6) && (family == APR_INET6))
-#endif
-       ) {
-        apr_sockaddr_info_get(&sa, c->local_ip, family,
-                              local_port, 0, c->pool);
-        if (!sa) {
-            ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r,
-                          "Couldn't resolve explicit local socket address"
-                          " (apr or socket stack bug?)  Retrying");
-            apr_sockaddr_info_get(&sa, NULL, family,
-                                  local_port, 0, c->pool);
-        }
-    }
-    else {
-        /* If the family differs, it's difficult to map the EPRT origin IP */
-        apr_sockaddr_info_get(&sa, NULL, family,
-                              local_port, 0, c->pool);
-    }
-
-    if (!sa) {
-        ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
-                      "Couldn't resolve local socket address"
-                      " (apr or socket stack bug?)  Giving up");
-        return FTP_REPLY_CANNOT_OPEN_DATACONN;
+        sa->port = 0;
     }
+    sa->sa.sin.sin_port = htons(sa->port);
 
     apr_socket_opt_set(s, APR_SO_REUSEADDR, 1);
     rv = apr_socket_bind(s, sa);