]> granicus.if.org Git - apache/commitdiff
Change apr_bind() to take apr_sockaddr_t.
authorJeff Trawick <trawick@apache.org>
Sun, 19 Nov 2000 14:24:20 +0000 (14:24 +0000)
committerJeff Trawick <trawick@apache.org>
Sun, 19 Nov 2000 14:24:20 +0000 (14:24 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@87024 13f79535-47bb-0310-9956-ffa450edef68

modules/proxy/proxy_ftp.c
server/listen.c
server/rfc1413.c

index c943702ac9fd3fe433483c4f278159d251bb7ae5..a9eb55c9896d4b58da74d267cee4a0dca3ac0efd 100644 (file)
@@ -486,6 +486,7 @@ int ap_proxy_ftp_handler(request_rec *r, ap_cache_el *c, char *url)
     (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
     struct noproxy_entry *npent = (struct noproxy_entry *) conf->noproxies->elts;
     struct nocache_entry *ncent = (struct nocache_entry *) conf->nocaches->elts;
+    apr_sockaddr_t *localsa;
 
 /* stuff for PASV mode */
     unsigned int presult, h0, h1, h2, h3, p0, p1;
@@ -566,7 +567,7 @@ int ap_proxy_ftp_handler(request_rec *r, ap_cache_el *c, char *url)
     if (parms != NULL)
        *(parms++) = '\0';
 
-    if ((apr_create_tcp_socket(&sock, r->pool)) != APR_SUCCESS) {
+    if ((apr_create_socket(&sock, APR_INET, SOCK_STREAM, r->pool)) != APR_SUCCESS) {
         ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                       "proxy: error creating socket");
         return HTTP_INTERNAL_SERVER_ERROR;
@@ -787,7 +788,7 @@ int ap_proxy_ftp_handler(request_rec *r, ap_cache_el *c, char *url)
     }
 
 /* try to set up PASV data connection first */
-    if ((apr_create_tcp_socket(&dsock, r->pool)) != APR_SUCCESS) {
+    if ((apr_create_socket(&dsock, APR_INET, SOCK_STREAM, r->pool)) != APR_SUCCESS) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                     "proxy: error creating PASV socket");
        ap_bclose(f);
@@ -865,7 +866,7 @@ int ap_proxy_ftp_handler(request_rec *r, ap_cache_el *c, char *url)
     }
 
     if (!pasvmode) {           /* set up data connection */
-       if ((apr_create_tcp_socket(&dsock, r->pool)) != APR_SUCCESS) {
+       if ((apr_create_socket(&dsock, APR_INET, SOCK_STREAM, r->pool)) != APR_SUCCESS) {
            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                         "proxy: error creating socket");
            ap_bclose(f);
@@ -873,8 +874,6 @@ int ap_proxy_ftp_handler(request_rec *r, ap_cache_el *c, char *url)
        }
         apr_get_port(&npport, APR_LOCAL, sock);
         apr_get_ipaddr(&npaddr, APR_LOCAL, sock);
-        apr_set_port(dsock, APR_LOCAL, npport);
-        apr_set_ipaddr(dsock, APR_LOCAL, npaddr);
 
        if (apr_setsocketopt(dsock, APR_SO_REUSEADDR, one) != APR_SUCCESS) {
 #ifndef _OSD_POSIX /* BS2000 has this option "always on" */
@@ -886,7 +885,15 @@ int ap_proxy_ftp_handler(request_rec *r, ap_cache_el *c, char *url)
 #endif /*_OSD_POSIX*/
        }
 
-       if (apr_bind(dsock) != APR_SUCCESS) {
+        if (apr_getaddrinfo(&localsa, npaddr, APR_INET, npport, 0, r->pool) 
+            != APR_SUCCESS) {
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+                          "proxy: error creating local socket address");
+            ap_bclose(f);
+            return HTTP_INTERNAL_SERVER_ERROR;
+        }
+
+       if (apr_bind(dsock, localsa) != APR_SUCCESS) {
            char buff[22];
 
            apr_snprintf(buff, sizeof(buff), "%s:%d", npaddr, npport);
index f829d3993102dba5bed10db242cba9af37f1b469..4d6fffb9489bd9d21f069dec1e3c0ebc04ed31a5 100644 (file)
@@ -85,12 +85,22 @@ static apr_status_t make_sock(apr_pool_t *p, ap_listen_rec *server)
     apr_status_t stat;
     apr_port_t port;
     char *ipaddr;
+    apr_sockaddr_t *localsa;
 
     apr_get_port(&port, APR_LOCAL, s);
     apr_get_ipaddr(&ipaddr, APR_LOCAL, s);
     apr_snprintf(addr, sizeof(addr), "address %s port %u", ipaddr,
                (unsigned) port);
 
+    stat = apr_getaddrinfo(&localsa, ipaddr, APR_INET, port, 0, p);
+    if (stat != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_CRIT, stat, NULL,
+                     "make_sock: for %s/%hu, apr_getaddrinfo() failed", 
+                     ipaddr, port);
+        apr_close_socket(s);
+        return stat;
+    }
+
     stat = apr_setsocketopt(s, APR_SO_REUSEADDR, one);
     if (stat != APR_SUCCESS && stat != APR_ENOTIMPL) {
        ap_log_error(APLOG_MARK, APLOG_CRIT, stat, NULL,
@@ -140,7 +150,7 @@ static apr_status_t make_sock(apr_pool_t *p, ap_listen_rec *server)
     ap_sock_disable_nagle(s);
 #endif
 
-    if ((stat = apr_bind(s)) != APR_SUCCESS) {
+    if ((stat = apr_bind(s, localsa)) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_CRIT, stat, NULL,
            "make_sock: could not bind to %s", addr);
        apr_close_socket(s);
@@ -197,7 +207,8 @@ static void alloc_listener(process_rec *process, char *addr, apr_port_t port)
     /* this has to survive restarts */
     new = apr_palloc(process->pool, sizeof(ap_listen_rec));
     new->active = 0;
-    if ((status = apr_create_tcp_socket(&new->sd, process->pool)) != APR_SUCCESS) {
+    if ((status = apr_create_socket(&new->sd, APR_INET, SOCK_STREAM, 
+                                    process->pool)) != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_CRIT, status, NULL,
                  "make_sock: failed to get a socket for %s", addr);
         return;
index de545b910a06aec643e20fbbc209f21ee6d43d6e..d37fcd3dcbeee126aa78775a6b77bc5da1f1355e 100644 (file)
@@ -119,7 +119,7 @@ static int get_rfc1413(apr_socket_t *sock, apr_pool_t *p,
     char *cp;
     char buffer[RFC1413_MAXDATA + 1];
     int buflen;
-    apr_sockaddr_t *destsa;
+    apr_sockaddr_t *localsa, *destsa;
 
     /*
      * Bind the local and remote ends of the query socket to the same
@@ -130,10 +130,16 @@ static int get_rfc1413(apr_socket_t *sock, apr_pool_t *p,
      * addresses from the query socket.
      */
 
-    apr_set_port(sock, APR_LOCAL, ANY_PORT);
-    apr_set_ipaddr(sock, APR_LOCAL, local_ip);
+    if ((status = apr_getaddrinfo(&localsa, local_ip, APR_INET, 0, 0, p)) 
+        != APR_SUCCESS) {
+        /* This should not fail since we have a numeric address string
+         * as the host. */
+        ap_log_error(APLOG_MARK, APLOG_CRIT, status, srv,
+                     "rfc1413: apr_getaddrinfo() failed");
+        return -1;
+    }
 
-    if ((status = apr_bind(sock)) != APR_SUCCESS) {
+    if ((status = apr_bind(sock, localsa)) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_CRIT, status, srv,
                    "bind: rfc1413: Error binding to local port");
        return -1;
@@ -235,7 +241,8 @@ char *ap_rfc1413(conn_rec *conn, server_rec *srv)
 
     result = FROM_UNKNOWN;
 
-    if ((status = apr_create_tcp_socket(&sock, conn->pool)) != APR_SUCCESS) {
+    if ((status = apr_create_socket(&sock, APR_INET, SOCK_STREAM, 
+                                    conn->pool)) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_CRIT, status, srv,
                    "socket: rfc1413: error creating socket");
        conn->remote_logname = result;