httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <trawi...@bellsouth.net>
Subject Re: Are we ready for an alpha?????
Date Sun, 19 Nov 2000 02:23:51 GMT
A certain somebody keeps pestering me to commit the following patch,
which changes the parameter list to apr_bind()  Do you have any
objections if I do so tonight?

Index: lib/apr/include/apr_network_io.h
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/lib/apr/include/apr_network_io.h,v
retrieving revision 1.75
diff -u -r1.75 apr_network_io.h
--- lib/apr/include/apr_network_io.h	2000/11/18 20:52:28	1.75
+++ lib/apr/include/apr_network_io.h	2000/11/18 21:48:13
@@ -245,10 +245,11 @@
 /**
  * Bind the socket to its associated port
  * @param sock The socket to bind 
- * @tip This is where we will find out if there is any other process
+ * @param sa The socket address to bind to
+ * @tip This may be where we will find out if there is any other process
  *      using the selected port.
  */
-apr_status_t apr_bind(apr_socket_t *sock);
+apr_status_t apr_bind(apr_socket_t *sock, apr_sockaddr_t *sa);
 
 /**
  * Listen to a bound socket for connections.
Index: lib/apr/network_io/os2/sockets.c
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/lib/apr/network_io/os2/sockets.c,v
retrieving revision 1.32
diff -u -r1.32 sockets.c
--- lib/apr/network_io/os2/sockets.c	2000/11/17 03:45:03	1.32
+++ lib/apr/network_io/os2/sockets.c	2000/11/18 21:48:22
@@ -189,14 +189,16 @@
 
 
 
-apr_status_t apr_bind(apr_socket_t *sock)
+apr_status_t apr_bind(apr_socket_t *sock, apr_sockaddr_t *sa)
 {
     if (bind(sock->socketdes, 
-             (struct sockaddr *)&sock->local_addr->sa,
-             sock->local_addr->sa_len) == -1)
+             (struct sockaddr *)&sa->sa,
+             sa->sa_len) == -1)
         return APR_OS2_STATUS(sock_errno());
-    else
+    else {
+        sock->local_sa = sa;
         return APR_SUCCESS;
+    }
 }
 
 apr_status_t apr_listen(apr_socket_t *sock, apr_int32_t backlog)
Index: lib/apr/network_io/unix/sockets.c
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/lib/apr/network_io/unix/sockets.c,v
retrieving revision 1.60
diff -u -r1.60 sockets.c
--- lib/apr/network_io/unix/sockets.c	2000/11/18 16:31:52	1.60
+++ lib/apr/network_io/unix/sockets.c	2000/11/18 21:48:22
@@ -170,12 +170,14 @@
     return socket_cleanup(thesocket);
 }
 
-apr_status_t apr_bind(apr_socket_t *sock)
+apr_status_t apr_bind(apr_socket_t *sock, apr_sockaddr_t *sa)
 {
     if (bind(sock->socketdes, 
-             (struct sockaddr *)&sock->local_addr->sa, sock->local_addr->sa_len)
== -1)
+             (struct sockaddr *)&sa->sa, sa->sa_len) == -1) {
         return errno;
+    }
     else {
+        sock->local_addr = sa;
         /* XXX IPv6 - this assumes sin_port and sin6_port at same offset */
         if (sock->local_addr->sa.sin.sin_port == 0) { /* no need for ntohs() when comparing
w/ 0 */
             sock->local_port_unknown = 1; /* kernel got us an ephemeral port */
Index: lib/apr/network_io/win32/sockets.c
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/lib/apr/network_io/win32/sockets.c,v
retrieving revision 1.42
diff -u -r1.42 sockets.c
--- lib/apr/network_io/win32/sockets.c	2000/11/17 03:45:03	1.42
+++ lib/apr/network_io/win32/sockets.c	2000/11/18 21:48:23
@@ -196,14 +196,15 @@
     return socket_cleanup(thesocket);
 }
 
-apr_status_t apr_bind(apr_socket_t *sock)
+apr_status_t apr_bind(apr_socket_t *sock, apr_sockaddr_t *sa)
 {
     if (bind(sock->sock, 
-             (struct sockaddr *)&sock->local_addr->sa, 
-             sock->local_addr->sa_len) == -1) {
+             (struct sockaddr *)&sa->sa, 
+             sa->sa_len) == -1) {
         return apr_get_netos_error();
     }
     else {
+        sock->local_addr = sa;
         if (sock->local_addr->sa.sin.sin_port == 0) {
             sock->local_port_unknown = 1; /* ephemeral port */
         }
Index: lib/apr/test/server.c
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/lib/apr/test/server.c,v
retrieving revision 1.19
diff -u -r1.19 server.c
--- lib/apr/test/server.c	2000/11/18 15:46:45	1.19
+++ lib/apr/test/server.c	2000/11/18 21:48:26
@@ -56,10 +56,11 @@
 #include "apr_network_io.h"
 #include "apr_errno.h"
 #include "apr_general.h"
+#include "apr_getopt.h"
 
 #define STRLEN 15
 
-int main(int argc, char *argv[])
+int main(int argc, char * const argv[])
 {
     apr_pool_t *context;
     apr_socket_t *sock;
@@ -69,8 +70,16 @@
     apr_pollfd_t *sdset;
     char datasend[STRLEN];
     char datarecv[STRLEN] = "Recv data test";
+    const char *bind_to_ipaddr = NULL;
     char *local_ipaddr, *remote_ipaddr;
     apr_port_t local_port, remote_port;
+    apr_sockaddr_t *localsa = NULL;
+    apr_status_t stat;
+    int family = APR_UNSPEC;
+    char buf[128];
+    apr_getopt_t *opt;
+    const char *optarg;
+    char optchar;
 
     fprintf(stdout, "Initializing.........");
     if (apr_initialize() != APR_SUCCESS) {
@@ -87,8 +96,43 @@
     }
     fprintf(stdout, "OK\n");
 
+    if (apr_initopt(&opt, context, argc, argv)) {
+        fprintf(stderr, "failed to initialize opts\n");
+        exit(-1);
+    }
+
+    while ((stat = apr_getopt(opt, "i:", &optchar, &optarg)) == APR_SUCCESS) {
+        switch(optchar) {
+        case 'i':
+            bind_to_ipaddr = optarg;
+            break;
+        }
+    }
+    if (stat != APR_EOF) {
+        fprintf(stderr,
+                "usage: %s [-i local-interface-address]\n",
+                argv[0]);
+        exit(-1);
+    }
+
+    if (bind_to_ipaddr) {
+        /* First, parse/resolve ipaddr so we know what address family of
+         * socket we need.  We'll use the returned sockaddr later when
+         * we bind.
+         */
+        stat = apr_getaddrinfo(&localsa, bind_to_ipaddr, APR_UNSPEC, 8021, 0,
+                               context);
+        if (stat != APR_SUCCESS) {
+            fprintf(stderr,
+                    "Couldn't build the socket address correctly: %s\n",
+                    apr_strerror(stat, buf, sizeof buf));
+            exit(-1);
+        }
+        family = localsa->sa.sin.sin_family;
+    }
+
     fprintf(stdout, "\tServer:  Creating new socket.......");
-    if (apr_create_socket(&sock, APR_UNSPEC, SOCK_STREAM, context) != APR_SUCCESS) {
+    if (apr_create_socket(&sock, family, SOCK_STREAM, context) != APR_SUCCESS) {
         fprintf(stderr, "Couldn't create socket\n");
         exit(-1);
     }
@@ -110,18 +154,16 @@
     }
     fprintf(stdout, "OK\n");
 
-    fprintf(stdout, "\tServer:  Setting port for socket.......");
-    if (apr_set_port(sock, APR_LOCAL, 8021) != APR_SUCCESS) {
-        apr_close_socket(sock);
-        fprintf(stderr, "Couldn't set the port correctly\n");
-        exit(-1);
+    if (!localsa) {
+        apr_set_port(sock, APR_LOCAL, 8021);
+        apr_get_sockaddr(&localsa, APR_LOCAL, sock);
     }
-    fprintf(stdout, "OK\n");
 
     fprintf(stdout, "\tServer:  Binding socket to port.......");
-    if (apr_bind(sock) != APR_SUCCESS) {
+    if ((stat = apr_bind(sock, localsa)) != APR_SUCCESS) {
         apr_close_socket(sock);
-        fprintf(stderr, "Could not bind\n");
+        fprintf(stderr, "Could not bind: %s\n",
+                apr_strerror(stat, buf, sizeof buf));
         exit(-1);
     }
     fprintf(stdout, "OK\n");
Index: lib/apr/test/testsf.c
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/lib/apr/test/testsf.c,v
retrieving revision 1.15
diff -u -r1.15 testsf.c
--- lib/apr/test/testsf.c	2000/11/18 15:46:45	1.15
+++ lib/apr/test/testsf.c	2000/11/18 21:48:26
@@ -90,7 +90,7 @@
 
 typedef enum {BLK, NONBLK, TIMEOUT} client_socket_mode_t;
 
-static void apr_setup(apr_pool_t **p, apr_socket_t **sock)
+static void apr_setup(apr_pool_t **p, apr_socket_t **sock, int *family)
 {
     char buf[120];
     apr_status_t rv;
@@ -114,13 +114,26 @@
     }
 
     *sock = NULL;
-    rv = apr_create_tcp_socket(sock, *p);
+    rv = apr_create_socket(sock, *family, SOCK_STREAM, *p);
     if (rv != APR_SUCCESS) {
-        fprintf(stderr, "apr_create_tcp_socket()->%d/%s\n",
+        fprintf(stderr, "apr_create_socket()->%d/%s\n",
                 rv,
                 apr_strerror(rv, buf, sizeof buf));
         exit(1);
     }
+
+    if (*family == APR_UNSPEC) {
+        apr_sockaddr_t *localsa;
+
+        rv = apr_get_sockaddr(&localsa, APR_LOCAL, *sock);
+        if (rv != APR_SUCCESS) {
+            fprintf(stderr, "apr_get_sockaddr()->%d/%s\n",
+                    rv,
+                    apr_strerror(rv, buf, sizeof buf));
+            exit(1);
+        }
+        *family = localsa->sa.sin.sin_family;
+    }
 }
 
 static void create_testfile(apr_pool_t *p, const char *fname)
@@ -205,9 +218,11 @@
     apr_pollfd_t *pfd;
     apr_int32_t nsocks;
     int i;
+    int family;
     apr_sockaddr_t *destsa;
 
-    apr_setup(&p, &sock);
+    family = APR_INET;
+    apr_setup(&p, &sock, &family);
     create_testfile(p, TESTFILE);
 
     rv = apr_open(&f, TESTFILE, APR_READ, 0, p);
@@ -218,7 +233,7 @@
         exit(1);
     }
 
-    rv = apr_getaddrinfo(&destsa, "127.0.0.1", APR_INET, TESTSF_PORT, 0, p);
+    rv = apr_getaddrinfo(&destsa, "127.0.0.1", family, TESTSF_PORT, 0, p);
     if (rv != APR_SUCCESS) {
         fprintf(stderr, "apr_getaddrinfo()->%d/%s\n",
                 rv,
@@ -493,26 +508,29 @@
     int i;
     apr_socket_t *newsock = NULL;
     apr_ssize_t bytes_read;
+    apr_sockaddr_t *localsa;
+    int family;
 
-    apr_setup(&p, &sock);
+    family = APR_UNSPEC;
+    apr_setup(&p, &sock, &family);
 
-    rv = apr_set_port(sock, APR_LOCAL, TESTSF_PORT);
+    rv = apr_setsocketopt(sock, APR_SO_REUSEADDR, 1);
     if (rv != APR_SUCCESS) {
-        fprintf(stderr, "apr_set_local_port()->%d/%s\n",
+        fprintf(stderr, "apr_setsocketopt()->%d/%s\n",
                 rv,
 		apr_strerror(rv, buf, sizeof buf));
         exit(1);
     }
 
-    rv = apr_setsocketopt(sock, APR_SO_REUSEADDR, 1);
+    rv = apr_getaddrinfo(&localsa, NULL, family, TESTSF_PORT, 0, p);
     if (rv != APR_SUCCESS) {
-        fprintf(stderr, "apr_setsocketopt()->%d/%s\n",
+        fprintf(stderr, "apr_getaddrinfo()->%d/%s\n",
                 rv,
 		apr_strerror(rv, buf, sizeof buf));
         exit(1);
     }
 
-    rv = apr_bind(sock);
+    rv = apr_bind(sock, localsa);
     if (rv != APR_SUCCESS) {
         fprintf(stderr, "apr_bind()->%d/%s\n",
                 rv,
Index: main/listen.c
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/main/listen.c,v
retrieving revision 1.36
diff -u -r1.36 listen.c
--- main/listen.c	2000/11/09 19:38:26	1.36
+++ main/listen.c	2000/11/18 21:48:35
@@ -85,12 +85,22 @@
     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 @@
     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 @@
     /* 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: main/rfc1413.c
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/main/rfc1413.c,v
retrieving revision 1.31
diff -u -r1.31 rfc1413.c
--- main/rfc1413.c	2000/11/18 16:04:06	1.31
+++ main/rfc1413.c	2000/11/18 21:48:35
@@ -119,7 +119,7 @@
     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 @@
      * 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 @@
 
     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;
Index: modules/proxy/proxy_ftp.c
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/modules/proxy/proxy_ftp.c,v
retrieving revision 1.23
diff -u -r1.23 proxy_ftp.c
--- modules/proxy/proxy_ftp.c	2000/11/16 01:57:46	1.23
+++ modules/proxy/proxy_ftp.c	2000/11/18 21:48:41
@@ -486,6 +486,7 @@
     (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 @@
     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 @@
     }
 
 /* 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 @@
     }
 
     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 @@
 	}
         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 @@
 #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);

-- 
Jeff Trawick | trawick@ibm.net | PGP public key at web site:
     http://www.geocities.com/SiliconValley/Park/9289/
          Born in Roswell... married an alien...

Mime
View raw message