]> granicus.if.org Git - apache/commitdiff
APR: Change apr_connect() to take apr_sockaddr_t instead of hostname.
authorJeff Trawick <trawick@apache.org>
Fri, 17 Nov 2000 03:45:02 +0000 (03:45 +0000)
committerJeff Trawick <trawick@apache.org>
Fri, 17 Nov 2000 03:45:02 +0000 (03:45 +0000)
Add generic apr_create_socket().  Add apr_getaddrinfo() for doing
hostname resolution/address string parsing and building
apr_sockaddr_t.
Submitted by: David Reid
Reviewed by: Jeff Trawick

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@86990 13f79535-47bb-0310-9956-ffa450edef68

modules/proxy/proxy_util.c
server/rfc1413.c
support/ab.c
support/httpd.exp

index f29fbc0c1c0a5fc53ad1f578a404495408cccdac..74953c22d5aaf56c5acd852f4b09100a6b8a02b7 100644 (file)
@@ -1109,25 +1109,15 @@ apr_status_t ap_proxy_doconnect(apr_socket_t *sock, char *host, apr_uint32_t por
 {
     apr_status_t rv;
     int i;
+    apr_sockaddr_t *destsa;
 
-    for (i = 0; host[i] != '\0'; i++)
-        if (!apr_isdigit(host[i]) && host[i] != '.')
-            break;
-
-    apr_set_port(sock, APR_REMOTE, port);
-    if (host[i] == '\0') {
-        apr_set_ipaddr(sock, APR_REMOTE, host);
-        host = NULL;
+    rv = apr_getaddrinfo(&destsa, host, AF_INET, port, r->pool);
+    if (rv == APR_SUCCESS) {
+        rv = apr_connect(sock, destsa);
     }
-
-    do
-    {
-        rv = apr_connect(sock, host);
-    } while (APR_STATUS_IS_EINTR(rv));
-
     if (rv != APR_SUCCESS)
     {
-        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
             "proxy connect to %s port %d failed", host, port);
     }
     return rv;
index a7a90c2ba53d9f6c73069e8b68dd4ed0a3ef875e..094ed1fa48da39376a52f2ba67fe7e22418f1516 100644 (file)
@@ -108,8 +108,8 @@ int ap_rfc1413_timeout = RFC1413_TIMEOUT;   /* Global so it can be changed */
 
 /* bind_connect - bind both ends of a socket */
 /* Ambarish fix this. Very broken */
-static int get_rfc1413(apr_socket_t *sock, const char *local_ip,
-                      const char *rmt_ip, 
+static int get_rfc1413(apr_socket_t *sock, apr_pool_t *p, 
+                       const char *local_ip, const char *rmt_ip, 
                       char user[RFC1413_USERLEN+1], server_rec *srv)
 {
     apr_port_t rmt_port, our_port;
@@ -119,6 +119,7 @@ static int get_rfc1413(apr_socket_t *sock, const char *local_ip,
     char *cp;
     char buffer[RFC1413_MAXDATA + 1];
     int buflen;
+    apr_sockaddr_t *destsa;
 
     /*
      * Bind the local and remote ends of the query socket to the same
@@ -138,14 +139,19 @@ static int get_rfc1413(apr_socket_t *sock, const char *local_ip,
        return -1;
     }
 
+    if ((status = apr_getaddrinfo(&destsa, rmt_ip, AF_INET, RFC1413_PORT, 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;
+    }
 /*
  * errors from connect usually imply the remote machine doesn't support
  * the service
  */
-    apr_set_port(sock, APR_REMOTE, RFC1413_PORT);
-    apr_set_ipaddr(sock, APR_REMOTE, rmt_ip);
-                    
-    if (apr_connect(sock, NULL) != APR_SUCCESS)
+    if (apr_connect(sock, destsa) != APR_SUCCESS)
         return -1;
     apr_get_port(&sav_our_port, APR_LOCAL, sock);
     apr_get_port(&sav_rmt_port, APR_REMOTE, sock);
@@ -235,7 +241,7 @@ char *ap_rfc1413(conn_rec *conn, server_rec *srv)
        conn->remote_logname = result;
     }
 
-    if (get_rfc1413(sock, conn->local_ip, conn->remote_ip, user, srv) >= 0)
+    if (get_rfc1413(sock, conn->pool, conn->local_ip, conn->remote_ip, user, srv) >= 0)
         result = user;
     apr_close_socket(sock);
     conn->remote_logname = result;
index 7704d47a60217219d37d6948807daa39da18a267..5b64d93db9754d4941d49679fd716cfebf453de0 100644 (file)
@@ -482,6 +482,7 @@ static void output_html_results(void)
 static void start_connect(struct connection *c)
 {
     apr_status_t rv;
+    apr_sockaddr_t *destsa;
 
     if(!(started < requests)) return;
 
@@ -491,14 +492,15 @@ static void start_connect(struct connection *c)
     c->cbx = 0;
     c->gotheader = 0;
 
+    if ((rv = apr_getaddrinfo(&destsa, hostname, AF_INET, port, 0, cntxt))
+         != APR_SUCCESS) {
+        apr_err("apr_getaddrinfo()", rv);
+    }
     if ((rv = apr_create_tcp_socket(&c->aprsock, cntxt)) != APR_SUCCESS) {
         apr_err("Socket:", rv);
     }
-    if ((rv = apr_set_port(c->aprsock, APR_REMOTE, port)) != APR_SUCCESS) {
-        apr_err("Port:", rv);
-    }
     c->start = apr_now();
-    if ((rv = apr_connect(c->aprsock, hostname)) != APR_SUCCESS) {
+    if ((rv = apr_connect(c->aprsock, destsa)) != APR_SUCCESS) {
         if (APR_STATUS_IS_EINPROGRESS(rv)) {
             c->state = STATE_CONNECTING;
             apr_add_poll_socket(readbits, c->aprsock, APR_POLLOUT);
@@ -876,14 +878,14 @@ static void test(void)
 static void copyright(void)
 {
     if (!use_html) {
-        printf("This is ApacheBench, Version %s\n", AB_VERSION " <$Revision: 1.32 $> apache-2.0");
+        printf("This is ApacheBench, Version %s\n", AB_VERSION " <$Revision: 1.33 $> apache-2.0");
         printf("Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\n");
         printf("Copyright (c) 1998-2000 The Apache Software Foundation, http://www.apache.org/\n");
         printf("\n");
     }
     else {
         printf("<p>\n");
-        printf(" This is ApacheBench, Version %s <i>&lt;%s&gt;</i> apache-2.0<br>\n", AB_VERSION, "$Revision: 1.32 $");
+        printf(" This is ApacheBench, Version %s <i>&lt;%s&gt;</i> apache-2.0<br>\n", AB_VERSION, "$Revision: 1.33 $");
         printf(" Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/<br>\n");
         printf(" Copyright (c) 1998-2000 The Apache Software Foundation, http://www.apache.org/<br>\n");
         printf("</p>\n<p>\n");
index 577c6330b63fac1622652f1162fcd99dd8f4f17f..ec715314f75373e0ea9b9f9c3e960aea2b008796 100644 (file)
@@ -404,6 +404,7 @@ apr_format_uuid
 apr_fprintf
 apr_full_read
 apr_full_write
+apr_getaddrinfo
 apr_get_dir_filename
 apr_get_filedata
 apr_get_hostname