From: Jeff Trawick Date: Sun, 19 Nov 2000 14:24:20 +0000 (+0000) Subject: Change apr_bind() to take apr_sockaddr_t. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c46b78c0f610a4154923d0c2551c6f2b0cac4b87;p=apache Change apr_bind() to take apr_sockaddr_t. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@87024 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/proxy/proxy_ftp.c b/modules/proxy/proxy_ftp.c index c943702ac9..a9eb55c989 100644 --- a/modules/proxy/proxy_ftp.c +++ b/modules/proxy/proxy_ftp.c @@ -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); diff --git a/server/listen.c b/server/listen.c index f829d39931..4d6fffb948 100644 --- a/server/listen.c +++ b/server/listen.c @@ -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; diff --git a/server/rfc1413.c b/server/rfc1413.c index de545b910a..d37fcd3dcb 100644 --- a/server/rfc1413.c +++ b/server/rfc1413.c @@ -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;