From 243005861c6b9194b35aec99a2d914781bafa57d Mon Sep 17 00:00:00 2001 From: Brian Havard Date: Sun, 24 Oct 1999 05:59:22 +0000 Subject: [PATCH] Enhancements for APR network_io. Adds separate local/remote access methods for a socket's port, IP address and sockaddr_in. Updates for Apache code to use these, allowing the correct IP address of clients to be logged. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@84029 13f79535-47bb-0310-9956-ffa450edef68 --- include/http_connection.h | 3 +++ server/connection.c | 12 ++++++++++++ server/listen.c | 10 +++++----- server/mpm/prefork/prefork.c | 4 +--- server/mpm/spmt_os2/spmt_os2.c | 6 ++---- server/rfc1413.c | 12 ++++++------ 6 files changed, 29 insertions(+), 18 deletions(-) diff --git a/include/http_connection.h b/include/http_connection.h index 30be9e9dce..54eff1cbd1 100644 --- a/include/http_connection.h +++ b/include/http_connection.h @@ -59,6 +59,7 @@ #define APACHE_HTTP_CONNECTION_H #include "ap_hooks.h" +#include "apr_network_io.h" #ifdef __cplusplus extern "C" { @@ -67,6 +68,8 @@ extern "C" { conn_rec *ap_new_connection(ap_context_t *p, server_rec *server, BUFF *inout, const struct sockaddr_in *remaddr, const struct sockaddr_in *saddr, long id); +conn_rec *ap_new_apr_connection(ap_context_t *p, server_rec *server, BUFF *inout, + const ap_socket_t *conn_socket, long id); CORE_EXPORT(void) ap_process_connection(conn_rec *); int ap_process_http_connection(conn_rec *); diff --git a/server/connection.c b/server/connection.c index d81aa862d1..6f740f367a 100644 --- a/server/connection.c +++ b/server/connection.c @@ -288,3 +288,15 @@ conn_rec *ap_new_connection(ap_context_t *p, server_rec *server, BUFF *inout, return conn; } + + + +conn_rec *ap_new_apr_connection(ap_context_t *p, server_rec *server, BUFF *inout, + const ap_socket_t *conn_socket, long id) +{ + struct sockaddr_in *sa_local, *sa_remote; + + ap_get_local_name(&sa_local, conn_socket); + ap_get_remote_name(&sa_remote, conn_socket); + return ap_new_connection(p, server, inout, sa_remote, sa_local, id); +} diff --git a/server/listen.c b/server/listen.c index 991386cef7..b9c5950499 100644 --- a/server/listen.c +++ b/server/listen.c @@ -158,13 +158,13 @@ static void alloc_listener(process_rec *process, char *addr, unsigned int port) ap_listen_rec **walk; ap_listen_rec *new; ap_status_t status; - char oldaddr[17]; + char *oldaddr; unsigned int oldport; /* see if we've got an old listener for this address:port */ for (walk = &old_listeners; *walk; walk = &(*walk)->next) { - ap_getport(&oldport, (*walk)->sd); - ap_getipaddr(oldaddr,sizeof oldaddr,(*walk)->sd); + ap_get_local_port(&oldport, (*walk)->sd); + ap_get_local_ipaddr(&oldaddr,(*walk)->sd); if (!strcmp(oldaddr, addr) && port == oldport) { /* re-use existing record */ new = *walk; @@ -184,8 +184,8 @@ static void alloc_listener(process_rec *process, char *addr, unsigned int port) "make_sock: failed to get a socket for %s", addr); return; } - ap_setport(new->sd, port); - ap_setipaddr(new->sd, addr); + ap_set_local_port(new->sd, port); + ap_set_local_ipaddr(new->sd, addr); new->next = ap_listeners; ap_listeners = new; } diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index bbe3330343..5fb67599a2 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -2239,9 +2239,7 @@ static void child_main(int child_num_arg) ap_bpush_iol(conn_io, iol); - current_conn = ap_new_connection(ptrans, server_conf, conn_io, - (struct sockaddr_in *) &sa_client, - (struct sockaddr_in *) &sa_server, + current_conn = ap_new_apr_connection(ptrans, server_conf, conn_io, csd, my_child_num); ap_process_connection(current_conn); diff --git a/server/mpm/spmt_os2/spmt_os2.c b/server/mpm/spmt_os2/spmt_os2.c index 7d343e100b..98c1f842d8 100644 --- a/server/mpm/spmt_os2/spmt_os2.c +++ b/server/mpm/spmt_os2/spmt_os2.c @@ -1166,10 +1166,8 @@ static void child_main(void *child_num_arg) conn_io = ap_bcreate(ptrans, B_RDWR); ap_bpush_iol(conn_io, iol); - current_conn = ap_new_connection(ptrans, server_conf, conn_io, - (struct sockaddr_in *) &sa_client, - (struct sockaddr_in *) &sa_server, - THREAD_GLOBAL(child_num)); + current_conn = ap_new_apr_connection(ptrans, server_conf, conn_io, csd, + THREAD_GLOBAL(child_num)); ap_process_connection(current_conn); } diff --git a/server/rfc1413.c b/server/rfc1413.c index 3a9197b505..30564dca82 100644 --- a/server/rfc1413.c +++ b/server/rfc1413.c @@ -124,26 +124,26 @@ static int get_rfc1413(ap_socket_t *sock, const char *local_ip, * addresses from the query socket. */ - ap_setport(sock, ANY_PORT); - ap_setipaddr(sock, local_ip); + ap_set_local_port(sock, ANY_PORT); + ap_set_local_ipaddr(sock, local_ip); if ((status = ap_bind(sock)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, status, srv, "bind: rfc1413: Error binding to local port"); return -1; } - ap_getport(&sav_our_port, sock); + ap_get_local_port(&sav_our_port, sock); /* * errors from connect usually imply the remote machine doesn't support * the service */ - ap_setport(sock, RFC1413_PORT); - ap_setipaddr(sock, rmt_ip); + ap_set_remote_port(sock, RFC1413_PORT); + ap_set_remote_ipaddr(sock, rmt_ip); if (ap_connect(sock, NULL) != APR_SUCCESS) return -1; - ap_getport(&sav_rmt_port, sock); + ap_get_remote_port(&sav_rmt_port, sock); /* send the data */ buflen = ap_snprintf(buffer, sizeof(buffer), "%u,%u\r\n", sav_rmt_port, -- 2.50.1