From: Jeff Trawick Date: Fri, 17 Nov 2000 03:45:02 +0000 (+0000) Subject: APR: Change apr_connect() to take apr_sockaddr_t instead of hostname. X-Git-Tag: APACHE_2_0_ALPHA_8~44 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3463c8ca6c4257724b08e9106889ea140ef34f98;p=apache APR: Change apr_connect() to take apr_sockaddr_t instead of hostname. 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 --- diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index f29fbc0c1c..74953c22d5 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -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; diff --git a/server/rfc1413.c b/server/rfc1413.c index a7a90c2ba5..094ed1fa48 100644 --- a/server/rfc1413.c +++ b/server/rfc1413.c @@ -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; diff --git a/support/ab.c b/support/ab.c index 7704d47a60..5b64d93db9 100644 --- a/support/ab.c +++ b/support/ab.c @@ -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("

\n"); - printf(" This is ApacheBench, Version %s <%s> apache-2.0
\n", AB_VERSION, "$Revision: 1.32 $"); + printf(" This is ApacheBench, Version %s <%s> apache-2.0
\n", AB_VERSION, "$Revision: 1.33 $"); 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

\n"); diff --git a/support/httpd.exp b/support/httpd.exp index 577c6330b6..ec715314f7 100644 --- a/support/httpd.exp +++ b/support/httpd.exp @@ -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