bjh 99/10/23 22:59:23
Modified: src/include http_connection.h
src/lib/apr/include apr_network_io.h
src/lib/apr/network_io/os2 Makefile.in networkio.h sockets.c
src/lib/apr/network_io/unix Makefile.in networkio.h
sockets.c sockopt.c
src/lib/apr/test ab_apr.c client.c server.c
src/main http_connection.c listen.c rfc1413.c
src/modules/mpm/prefork prefork.c
src/modules/mpm/spmt_os2 spmt_os2.c
Added: src/lib/apr/network_io/os2 sockaddr.c
src/lib/apr/network_io/unix sockaddr.c
Log:
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.
Revision Changes Path
1.9 +3 -0 apache-2.0/src/include/http_connection.h
Index: http_connection.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/include/http_connection.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- http_connection.h 1999/08/31 05:32:18 1.8
+++ http_connection.h 1999/10/24 05:59:12 1.9
@@ -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 @@
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 *);
1.12 +18 -4 apache-2.0/src/lib/apr/include/apr_network_io.h
Index: apr_network_io.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_network_io.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- apr_network_io.h 1999/10/15 14:19:57 1.11
+++ apr_network_io.h 1999/10/24 05:59:13 1.12
@@ -64,6 +64,10 @@
#include "apr_errno.h"
#include <time.h>
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
@@ -123,10 +127,20 @@
ap_status_t ap_recv(ap_socket_t *, char *, ap_ssize_t *);
ap_status_t ap_setsocketopt(ap_socket_t *, ap_int32_t, ap_int32_t);
-ap_status_t ap_setport(ap_socket_t *, ap_uint32_t);
-ap_status_t ap_setipaddr(ap_socket_t *, const char *);
-ap_status_t ap_getport(ap_uint32_t *, ap_socket_t *);
-ap_status_t ap_getipaddr(char *buf, ap_ssize_t len, const ap_socket_t *sock);
+
+ap_status_t ap_set_local_port(ap_socket_t *sock, ap_uint32_t port);
+ap_status_t ap_set_remote_port(ap_socket_t *sock, ap_uint32_t port);
+ap_status_t ap_get_local_port(ap_uint32_t *port, ap_socket_t *sock);
+ap_status_t ap_get_remote_port(ap_uint32_t *port, ap_socket_t *sock);
+ap_status_t ap_set_local_ipaddr(ap_socket_t *sock, const char *addr);
+ap_status_t ap_set_remote_ipaddr(ap_socket_t *sock, const char *addr);
+ap_status_t ap_get_local_ipaddr(char **addr, const ap_socket_t *sock);
+ap_status_t ap_get_remote_ipaddr(char **addr, const ap_socket_t *sock);
+
+#ifdef HAVE_NETINET_IN_H
+ap_status_t ap_get_local_name(struct sockaddr_in **name, const ap_socket_t
*sock);
+ap_status_t ap_get_remote_name(struct sockaddr_in **name, const ap_socket_t
*sock);
+#endif
ap_status_t ap_setup_poll(ap_pollfd_t **, ap_int32_t, ap_context_t *);
ap_status_t ap_poll(ap_pollfd_t *, ap_int32_t *, ap_int32_t);
1.5 +7 -1 apache-2.0/src/lib/apr/network_io/os2/Makefile.in
Index: Makefile.in
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/os2/Makefile.in,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Makefile.in 1999/10/18 12:06:53 1.4
+++ Makefile.in 1999/10/24 05:59:13 1.5
@@ -18,6 +18,7 @@
sendrecv.o \
sockets.o \
sockopt.o \
+ sockaddr.o
.c.o:
$(CC) $(CFLAGS) -c $(INCLUDES) $<
@@ -63,6 +64,11 @@
$(INCDIR1)/apr_general.h $(INCDIR1)/apr_config.h \
$(INCDIR1)/apr_errno.h $(INCDIR1)/apr_lib.h \
$(INCDIR1)/apr_file_io.h
+sockaddr.o: sockaddr.c ../unix/sockaddr.c ../unix/networkio.h \
+ $(INCDIR1)/apr_network_io.h $(INCDIR1)/apr_general.h \
+ $(INCDIR1)/apr_config.h $(INCDIR1)/apr_errno.h \
+ $(INCDIR1)/apr_lock.h $(INCDIR1)/apr_lib.h \
+ $(INCDIR1)/apr_file_io.h
sockets.o: sockets.c networkio.h $(INCDIR1)/apr_network_io.h \
$(INCDIR1)/apr_general.h $(INCDIR1)/apr_config.h \
$(INCDIR1)/apr_errno.h $(INCDIR1)/apr_portable.h \
@@ -73,4 +79,4 @@
$(INCDIR1)/apr_network_io.h $(INCDIR1)/apr_general.h \
$(INCDIR1)/apr_config.h $(INCDIR1)/apr_errno.h \
$(INCDIR1)/apr_lock.h $(INCDIR1)/apr_lib.h \
- $(INCDIR1)/apr_file_io.h $(INCDIR)/apr_macro.h
+ $(INCDIR1)/apr_file_io.h
1.4 +2 -1 apache-2.0/src/lib/apr/network_io/os2/networkio.h
Index: networkio.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/os2/networkio.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- networkio.h 1999/10/18 11:36:03 1.3
+++ networkio.h 1999/10/24 05:59:13 1.4
@@ -62,7 +62,8 @@
struct socket_t {
ap_context_t *cntxt;
int socketdes;
- struct sockaddr_in *addr;
+ struct sockaddr_in *local_addr;
+ struct sockaddr_in *remote_addr;
int addr_len;
int timeout;
};
1.5 +21 -60 apache-2.0/src/lib/apr/network_io/os2/sockets.c
Index: sockets.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/os2/sockets.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- sockets.c 1999/10/18 11:14:21 1.4
+++ sockets.c 1999/10/24 05:59:14 1.5
@@ -86,18 +86,21 @@
return APR_ENOMEM;
}
(*new)->cntxt = cont;
- (*new)->addr = (struct sockaddr_in *)ap_palloc((*new)->cntxt,
- sizeof(struct sockaddr_in));
+ (*new)->local_addr = (struct sockaddr_in *)ap_palloc((*new)->cntxt,
+ sizeof(struct sockaddr_in));
+ (*new)->remote_addr = (struct sockaddr_in *)ap_palloc((*new)->cntxt,
+ sizeof(struct sockaddr_in));
- if ((*new)->addr == NULL) {
+ if ((*new)->local_addr == NULL || (*new)->remote_addr == NULL) {
return APR_ENOMEM;
}
(*new)->socketdes = socket(AF_INET ,SOCK_STREAM, IPPROTO_TCP);
- (*new)->addr->sin_family = AF_INET;
+ (*new)->local_addr->sin_family = AF_INET;
+ (*new)->remote_addr->sin_family = AF_INET;
- (*new)->addr_len = sizeof(*(*new)->addr);
+ (*new)->addr_len = sizeof(*(*new)->local_addr);
if ((*new)->socketdes < 0) {
return errno;
@@ -124,57 +127,13 @@
return socket_cleanup(thesocket);
}
-ap_status_t ap_setport(struct socket_t *sock, ap_uint32_t port)
-{
- sock->addr->sin_port = htons((short)port);
- return APR_SUCCESS;
-}
-
-
-
-ap_status_t ap_getport(ap_uint32_t *port, struct socket_t *sock)
-{
- *port = ntohs(sock->addr->sin_port);
- return APR_SUCCESS;
-}
-
-
-
-ap_status_t ap_setipaddr(struct socket_t *sock, const char *addr)
-{
- ULONG ipaddr;
-
- if (!strcmp(addr, APR_ANYADDR)) {
- sock->addr->sin_addr.s_addr = htonl(INADDR_ANY);
- return APR_SUCCESS;
- }
-
- ipaddr = inet_addr(addr);
-
- if (ipaddr == (ULONG)-1) {
- return errno;
- }
-
- *(ULONG *)&sock->addr->sin_addr = ipaddr;
- return APR_SUCCESS;
-}
-
-ap_status_t ap_getipaddr(char *addr, ap_ssize_t len,
- const struct socket_t *sock)
-{
- char *temp = inet_ntoa(sock->addr->sin_addr);
- ap_cpystrn(addr,temp,len-1);
- return APR_SUCCESS;
-}
-
-
ap_status_t ap_bind(struct socket_t *sock)
{
- sock->addr->sin_addr.s_addr = INADDR_ANY;
- if (bind(sock->socketdes, (struct sockaddr *)sock->addr, sock->addr_len)
== -1)
+ sock->local_addr->sin_addr.s_addr = INADDR_ANY;
+ if (bind(sock->socketdes, (struct sockaddr *)sock->local_addr,
sock->addr_len) == -1)
return errno;
else
return APR_SUCCESS;
@@ -194,17 +153,18 @@
sizeof(struct socket_t));
(*new)->cntxt = sock->cntxt;
- (*new)->addr = (struct sockaddr_in *)ap_palloc((*new)->cntxt,
- sizeof(struct sockaddr_in));
+ (*new)->remote_addr = (struct sockaddr_in *)ap_palloc((*new)->cntxt,
+ sizeof(struct sockaddr_in));
+ (*new)->local_addr = sock->local_addr;
(*new)->addr_len = sizeof(struct sockaddr_in);
- (*new)->socketdes = accept(sock->socketdes, (struct sockaddr
*)(*new)->addr,
+ (*new)->socketdes = accept(sock->socketdes, (struct sockaddr
*)(*new)->remote_addr,
&(*new)->addr_len);
if ((*new)->socketdes < 0) {
return errno;
}
-
+
ap_register_cleanup((*new)->cntxt, (void *)(*new),
socket_cleanup, NULL);
return APR_SUCCESS;
@@ -217,7 +177,7 @@
if (hostname != NULL) {
hp = gethostbyname(hostname);
- if ((sock->socketdes < 0) || (!sock->addr)) {
+ if ((sock->socketdes < 0) || (!sock->remote_addr)) {
return APR_ENOTSOCK;
}
if (!hp) {
@@ -227,16 +187,17 @@
return h_errno;
}
- memcpy((char *)&sock->addr->sin_addr, hp->h_addr_list[0],
hp->h_length);
-
- sock->addr_len = sizeof(*sock->addr);
+ memcpy((char *)&sock->remote_addr->sin_addr, hp->h_addr_list[0],
hp->h_length);
+ sock->addr_len = sizeof(*sock->remote_addr);
}
- if ((connect(sock->socketdes, (const struct sockaddr *)sock->addr,
sock->addr_len) < 0) &&
+ if ((connect(sock->socketdes, (const struct sockaddr
*)sock->remote_addr, sock->addr_len) < 0) &&
(errno != EINPROGRESS)) {
return errno;
}
else {
+ int namelen = sizeof(*sock->local_addr);
+ getsockname(sock->socketdes, (struct sockaddr *)sock->local_addr,
&namelen);
return APR_SUCCESS;
}
}
1.1 apache-2.0/src/lib/apr/network_io/os2/sockaddr.c
Index: sockaddr.c
===================================================================
#include "../unix/sockaddr.c"
1.6 +1 -0 apache-2.0/src/lib/apr/network_io/unix/Makefile.in
Index: Makefile.in
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/Makefile.in,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Makefile.in 1999/09/23 18:19:07 1.5
+++ Makefile.in 1999/10/24 05:59:14 1.6
@@ -19,6 +19,7 @@
sendrecv.o \
sockets.o \
sockopt.o \
+ sockaddr.o
.c.o:
$(CC) $(CFLAGS) -c $(INCLUDES) $<
1.8 +2 -1 apache-2.0/src/lib/apr/network_io/unix/networkio.h
Index: networkio.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/networkio.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- networkio.h 1999/10/16 14:07:00 1.7
+++ networkio.h 1999/10/24 05:59:15 1.8
@@ -66,7 +66,8 @@
struct socket_t {
ap_context_t *cntxt;
int socketdes;
- struct sockaddr_in *addr;
+ struct sockaddr_in *local_addr;
+ struct sockaddr_in *remote_addr;
size_t addr_len;
int timeout;
#ifndef HAVE_POLL
1.19 +20 -76 apache-2.0/src/lib/apr/network_io/unix/sockets.c
Index: sockets.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/sockets.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- sockets.c 1999/10/19 19:21:18 1.18
+++ sockets.c 1999/10/24 05:59:15 1.19
@@ -97,18 +97,21 @@
return APR_ENOMEM;
}
(*new)->cntxt = cont;
- (*new)->addr = (struct sockaddr_in *)ap_palloc((*new)->cntxt,
- sizeof(struct sockaddr_in));
+ (*new)->local_addr = (struct sockaddr_in *)ap_palloc((*new)->cntxt,
+ sizeof(struct sockaddr_in));
+ (*new)->remote_addr = (struct sockaddr_in *)ap_palloc((*new)->cntxt,
+ sizeof(struct sockaddr_in));
- if ((*new)->addr == NULL) {
+ if ((*new)->local_addr == NULL || (*new)->remote_addr == NULL) {
return APR_ENOMEM;
}
(*new)->socketdes = socket(AF_INET ,SOCK_STREAM, IPPROTO_TCP);
- (*new)->addr->sin_family = AF_INET;
+ (*new)->local_addr->sin_family = AF_INET;
+ (*new)->remote_addr->sin_family = AF_INET;
- (*new)->addr_len = sizeof(*(*new)->addr);
+ (*new)->addr_len = sizeof(*(*new)->local_addr);
if ((*new)->socketdes < 0) {
return errno;
@@ -152,69 +155,6 @@
}
/* ***APRDOC********************************************************
- * ap_status_t ap_setport(ap_socket_t *, ap_uint32_t)
- * Assocaite a port with a socket.
- * arg 1) The socket use
- * arg 2) The port this socket will be dealing with.
- * NOTE: This does not bind the two together, it is just telling apr
- * that this socket is going to use this port if possible. If
- * the port is already used, we won't find out about it here.
- */
-ap_status_t ap_setport(struct socket_t *sock, ap_uint32_t port)
-{
- sock->addr->sin_port = htons((short)port);
- return APR_SUCCESS;
-}
-
-/* ***APRDOC********************************************************
- * ap_status_t ap_getport(ap_uint32_t *, ap_socket_t *)
- * Return the port with a socket.
- * arg 1) The socket use
- * arg 2) The port this socket will be dealing with.
- */
-ap_status_t ap_getport(ap_uint32_t *port, struct socket_t *sock)
-{
- *port = ntohs(sock->addr->sin_port);
- return APR_SUCCESS;
-}
-
-/* ***APRDOC********************************************************
- * ap_status_t ap_setipaddr(ap_socket_t *, cont char *addr)
- * Assocaite a socket addr with an apr socket.
- * arg 1) The socket to use
- * arg 2) The IP address to attach to the socket.
- * Use APR_ANYADDR to use any IP addr on the machine.
- * NOTE: This does not bind the two together, it is just telling apr
- * that this socket is going to use this address if possible.
- */
-ap_status_t ap_setipaddr(struct socket_t *sock, const char *addr)
-{
- if (!strcmp(addr, APR_ANYADDR)) {
- sock->addr->sin_addr.s_addr = htonl(INADDR_ANY);
- return APR_SUCCESS;
- }
- if (inet_aton(addr, &sock->addr->sin_addr) == 0) {
- return errno;
- }
- return APR_SUCCESS;
-}
-
-/* ***APRDOC********************************************************
- * ap_status_t ap_getipaddr(char *addr, int len, const ap_socket_t *)
- * Return the IP address associated with an apr socket.
- * arg 1) A buffer for the IP address associated with the socket.
- * arg 2) The total length of the buffer (including terminating NUL)
- * arg 3) The socket to use
- */
-ap_status_t ap_getipaddr(char *addr, ap_ssize_t len,
- const struct socket_t *sock)
-{
- char *temp = inet_ntoa(sock->addr->sin_addr);
- ap_cpystrn(addr, temp, len - 1);
- return APR_SUCCESS;
-}
-
-/* ***APRDOC********************************************************
* ap_status_t ap_bind(ap_socket_t *)
* Bind the socket to it's assocaited port
* arg 1) The socket to bind
@@ -223,8 +163,8 @@
*/
ap_status_t ap_bind(struct socket_t *sock)
{
- sock->addr->sin_addr.s_addr = INADDR_ANY;
- if (bind(sock->socketdes, (struct sockaddr *)sock->addr, sock->addr_len)
== -1)
+ sock->local_addr->sin_addr.s_addr = INADDR_ANY;
+ if (bind(sock->socketdes, (struct sockaddr *)sock->local_addr,
sock->addr_len) == -1)
return errno;
else
return APR_SUCCESS;
@@ -260,14 +200,16 @@
sizeof(struct socket_t));
(*new)->cntxt = sock->cntxt;
- (*new)->addr = (struct sockaddr_in *)ap_palloc((*new)->cntxt,
+ (*new)->local_addr = (struct sockaddr_in *)ap_palloc((*new)->cntxt,
+ sizeof(struct sockaddr_in));
+ (*new)->remote_addr = (struct sockaddr_in *)ap_palloc((*new)->cntxt,
sizeof(struct sockaddr_in));
(*new)->addr_len = sizeof(struct sockaddr_in);
#ifndef HAVE_POLL
(*new)->connected = 1;
#endif
- (*new)->socketdes = accept(sock->socketdes, (struct sockaddr
*)(*new)->addr,
+ (*new)->socketdes = accept(sock->socketdes, (struct sockaddr
*)(*new)->remote_addr,
&(*new)->addr_len);
if ((*new)->socketdes < 0) {
@@ -295,7 +237,7 @@
if (hostname != NULL) {
hp = gethostbyname(hostname);
- if ((sock->socketdes < 0) || (!sock->addr)) {
+ if ((sock->socketdes < 0) || (!sock->remote_addr)) {
return APR_ENOTSOCK;
}
if (!hp) {
@@ -305,16 +247,18 @@
return h_errno;
}
- memcpy((char *)&sock->addr->sin_addr, hp->h_addr_list[0],
hp->h_length);
+ memcpy((char *)&sock->remote_addr->sin_addr, hp->h_addr_list[0],
hp->h_length);
- sock->addr_len = sizeof(*sock->addr);
+ sock->addr_len = sizeof(*sock->remote_addr);
}
- if ((connect(sock->socketdes, (const struct sockaddr *)sock->addr,
sock->addr_len) < 0) &&
+ if ((connect(sock->socketdes, (const struct sockaddr
*)sock->remote_addr, sock->addr_len) < 0) &&
(errno != EINPROGRESS)) {
return errno;
}
else {
+ int namelen = sizeof(*sock->local_addr);
+ getsockname(sock->socketdes, (struct sockaddr *)sock->local_addr,
&namelen);
#ifndef HAVE_POLL
sock->connected=1;
#endif
1.11 +1 -1 apache-2.0/src/lib/apr/network_io/unix/sockopt.c
Index: sockopt.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/sockopt.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- sockopt.c 1999/10/19 19:21:20 1.10
+++ sockopt.c 1999/10/24 05:59:15 1.11
@@ -204,7 +204,7 @@
{
struct hostent *hptr;
- hptr = gethostbyaddr((char *)&(sock->addr->sin_addr),
+ hptr = gethostbyaddr((char *)&(sock->remote_addr->sin_addr),
sizeof(struct in_addr), AF_INET);
if (hptr != NULL) {
*name = ap_pstrdup(sock->cntxt, hptr->h_name);
1.1 apache-2.0/src/lib/apr/network_io/unix/sockaddr.c
Index: sockaddr.c
===================================================================
/* ====================================================================
* Copyright (c) 1999 The Apache Group. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* 4. The names "Apache Server" and "Apache Group" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Group.
* For more information on the Apache Group and the Apache HTTP server
* project, please see <http://www.apache.org/>.
*
*/
#include "networkio.h"
#include "apr_network_io.h"
#include "apr_general.h"
#include "apr_lib.h"
#include <errno.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
#include <arpa/inet.h>
/* ***APRDOC********************************************************
* ap_status_t ap_set_local_port(ap_socket_t *socket, ap_uint32_t port)
* Assocaite a local port with a socket.
* arg 1) The socket to set
* arg 2) The local port this socket will be dealing with.
* NOTE: This does not bind the two together, it is just telling apr
* that this socket is going to use this port if possible. If
* the port is already used, we won't find out about it here.
*/
ap_status_t ap_set_local_port(struct socket_t *sock, ap_uint32_t port)
{
sock->local_addr->sin_port = htons((short)port);
return APR_SUCCESS;
}
/* ***APRDOC********************************************************
* ap_status_t ap_set_remote_port(ap_socket_t *socket, ap_uint32_t port)
* Assocaite a remote port with a socket.
* arg 1) The socket to enquire about.
* arg 2) The local port this socket will be dealing with.
* NOTE: This does not make a connection to the remote port, it is just
* telling apr which port ap_connect() should attempt to connect to.
*/
ap_status_t ap_set_remote_port(struct socket_t *sock, ap_uint32_t port)
{
sock->remote_addr->sin_port = htons((short)port);
return APR_SUCCESS;
}
/* ***APRDOC********************************************************
* ap_status_t ap_get_local_port(ap_uint32_t *port, ap_socket_t *socket)
* Return the local port with a socket.
* arg 1) The local port this socket is associated with.
* arg 2) The socket to enquire about.
*/
ap_status_t ap_get_local_port(ap_uint32_t *port, struct socket_t *sock)
{
*port = ntohs(sock->local_addr->sin_port);
return APR_SUCCESS;
}
/* ***APRDOC********************************************************
* ap_status_t ap_get_remote_port(ap_uint32_t *port, ap_socket_t *socket)
* Return the remote port associated with a socket.
* arg 1) The remote port this socket is associated with.
* arg 2) The socket to enquire about.
*/
ap_status_t ap_get_remote_port(ap_uint32_t *port, struct socket_t *sock)
{
*port = ntohs(sock->remote_addr->sin_port);
return APR_SUCCESS;
}
/* ***APRDOC********************************************************
* ap_status_t ap_set_local_ipaddr(ap_socket_t *socket, cont char *addr)
* Assocaite a local socket addr with an apr socket.
* arg 1) The socket to use
* arg 2) The IP address to attach to the socket.
* Use APR_ANYADDR to use any IP addr on the machine.
* NOTE: This does not bind the two together, it is just telling apr
* that this socket is going to use this address if possible.
*/
ap_status_t ap_set_local_ipaddr(struct socket_t *sock, const char *addr)
{
u_long ipaddr;
if (!strcmp(addr, APR_ANYADDR)) {
sock->local_addr->sin_addr.s_addr = htonl(INADDR_ANY);
return APR_SUCCESS;
}
ipaddr = inet_addr(addr);
if (ipaddr == -1) {
return errno;
}
sock->local_addr->sin_addr.s_addr = ipaddr;
return APR_SUCCESS;
}
/* ***APRDOC********************************************************
* ap_status_t ap_set_remote_ipaddr(ap_socket_t *socket, cont char *addr)
* Assocaite a remote socket addr with an apr socket.
* arg 1) The socket to use
* arg 2) The IP address to attach to the socket.
* NOTE: This does not make a connection to the remote address, it is just
* telling apr which address ap_connect() should attempt to connect to.
*/
ap_status_t ap_set_remote_ipaddr(struct socket_t *sock, const char *addr)
{
u_long ipaddr;
if (!strcmp(addr, APR_ANYADDR)) {
sock->remote_addr->sin_addr.s_addr = htonl(INADDR_ANY);
return APR_SUCCESS;
}
ipaddr = inet_addr(addr);
if (ipaddr == (u_long)-1) {
return errno;
}
sock->remote_addr->sin_addr.s_addr = ipaddr;
return APR_SUCCESS;
}
/* ***APRDOC********************************************************
* ap_status_t ap_get_local_ipaddr(char **addr, const ap_socket_t *socket)
* Return the local IP address associated with an apr socket.
* arg 1) The local IP address associated with the socket.
* arg 2) The socket to use
*/
ap_status_t ap_get_local_ipaddr(char **addr, const struct socket_t *sock)
{
*addr = ap_pstrdup(sock->cntxt, inet_ntoa(sock->local_addr->sin_addr));
return APR_SUCCESS;
}
/* ***APRDOC********************************************************
* ap_status_t ap_get_remote_ipaddr(char **addr, const ap_socket_t *socket)
* Return the remote IP address associated with an apr socket.
* arg 1) The remote IP address associated with the socket.
* arg 2) The socket to use
*/
ap_status_t ap_get_remote_ipaddr(char **addr, const struct socket_t *sock)
{
*addr = ap_pstrdup(sock->cntxt, inet_ntoa(sock->remote_addr->sin_addr));
return APR_SUCCESS;
}
#if HAVE_NETINET_IN_H
/* ***APRDOC********************************************************
* ap_status_t ap_get_local_name(struct sockaddr_in **name, const ap_socket_t
*socket)
* Return the local socket name as a BSD style struct sockaddr_in.
* arg 1) The local name associated with the socket.
* arg 2) The socket to use
*/
ap_status_t ap_get_local_name(struct sockaddr_in **name, const struct
socket_t *sock)
{
*name = sock->local_addr;
return APR_SUCCESS;
}
/* ***APRDOC********************************************************
* ap_status_t ap_get_remote_name(struct sockaddr_in **name, const
ap_socket_t *socket)
* Return the remote socket name as a BSD style struct sockaddr_in.
* arg 1) The remote name associated with the socket.
* arg 2) The socket to use
*/
ap_status_t ap_get_remote_name(struct sockaddr_in **name, const struct
socket_t *sock)
{
*name = sock->remote_addr;
return APR_SUCCESS;
}
#endif
1.10 +1 -1 apache-2.0/src/lib/apr/test/ab_apr.c
Index: ab_apr.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/test/ab_apr.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ab_apr.c 1999/10/15 14:20:17 1.9
+++ ab_apr.c 1999/10/24 05:59:16 1.10
@@ -453,7 +453,7 @@
if (ap_create_tcp_socket(&c->aprsock, cntxt) != APR_SUCCESS) {
err("Socket:");
}
- if (ap_setport(c->aprsock, port) != APR_SUCCESS) {
+ if (ap_set_remote_port(c->aprsock, port) != APR_SUCCESS) {
err("Port:");
}
ap_current_time(c->start);
1.5 +14 -4 apache-2.0/src/lib/apr/test/client.c
Index: client.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/test/client.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- client.c 1999/10/04 16:37:23 1.4
+++ client.c 1999/10/24 05:59:17 1.5
@@ -68,6 +68,8 @@
ap_status_t stat;
char datasend[STRLEN] = "Send data test";
char datarecv[STRLEN];
+ char *local_ipaddr, *remote_ipaddr;
+ ap_uint32_t local_port, remote_port;
fprintf(stdout, "Creating context.......");
if (ap_create_context(&context, NULL) != APR_SUCCESS) {
@@ -92,7 +94,7 @@
fprintf(stdout, "OK\n");
fprintf(stdout, "\tClient: Setting port for socket.......");
- if (ap_setport(sock, 8021) != APR_SUCCESS) {
+ if (ap_set_remote_port(sock, 8021) != APR_SUCCESS) {
ap_close_socket(sock);
fprintf(stderr, "Couldn't set the port correctly\n");
exit(-1);
@@ -100,9 +102,11 @@
fprintf(stdout, "OK\n");
fprintf(stdout, "\tClient: Connecting to socket.......");
-do {
- stat = ap_connect(sock, "127.0.0.1");
-} while (stat == APR_ECONNREFUSED);
+
+ do {
+ stat = ap_connect(sock, "127.0.0.1");
+ } while (stat == APR_ECONNREFUSED);
+
if (stat != APR_SUCCESS) {
ap_close_socket(sock);
fprintf(stderr, "Could not connect %d\n", stat);
@@ -110,6 +114,12 @@
exit(-1);
}
fprintf(stdout, "OK\n");
+
+ ap_get_remote_ipaddr(&remote_ipaddr, sock);
+ ap_get_remote_port(&remote_port, sock);
+ ap_get_local_ipaddr(&local_ipaddr, sock);
+ ap_get_local_port(&local_port, sock);
+ fprintf(stdout, "\tClient socket: %s:%u -> %s:%u\n", local_ipaddr,
local_port, remote_ipaddr, remote_port);
fprintf(stdout, "\tClient: Trying to send data over socket.......");
length = STRLEN;
1.6 +9 -1 apache-2.0/src/lib/apr/test/server.c
Index: server.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/test/server.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- server.c 1999/10/10 20:35:00 1.5
+++ server.c 1999/10/24 05:59:17 1.6
@@ -69,6 +69,8 @@
ap_pollfd_t *sdset;
char datasend[STRLEN];
char datarecv[STRLEN] = "Recv data test";
+ char *local_ipaddr, *remote_ipaddr;
+ ap_uint32_t local_port, remote_port;
fprintf(stdout, "Creating context.......");
if (ap_create_context(&context, NULL) != APR_SUCCESS) {
@@ -93,7 +95,7 @@
fprintf(stdout, "OK\n");
fprintf(stdout, "\tServer: Setting port for socket.......");
- if (ap_setport(sock, 8021) != APR_SUCCESS) {
+ if (ap_set_local_port(sock, 8021) != APR_SUCCESS) {
ap_close_socket(sock);
fprintf(stderr, "Couldn't set the port correctly\n");
exit(-1);
@@ -142,6 +144,12 @@
exit(-1);
}
fprintf(stdout, "OK\n");
+
+ ap_get_remote_ipaddr(&remote_ipaddr, sock2);
+ ap_get_remote_port(&remote_port, sock2);
+ ap_get_local_ipaddr(&local_ipaddr, sock2);
+ ap_get_local_port(&local_port, sock2);
+ fprintf(stdout, "\tServer socket: %s:%u -> %s:%u\n", local_ipaddr,
local_port, remote_ipaddr, remote_port);
length = STRLEN;
fprintf(stdout, "\tServer: Trying to recv data from socket.......");
1.22 +12 -0 apache-2.0/src/main/http_connection.c
Index: http_connection.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/main/http_connection.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- http_connection.c 1999/10/13 05:24:13 1.21
+++ http_connection.c 1999/10/24 05:59:18 1.22
@@ -288,3 +288,15 @@
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);
+}
1.16 +5 -5 apache-2.0/src/main/listen.c
Index: listen.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/main/listen.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- listen.c 1999/10/20 12:49:55 1.15
+++ listen.c 1999/10/24 05:59:18 1.16
@@ -158,13 +158,13 @@
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 @@
"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;
}
1.7 +6 -6 apache-2.0/src/main/rfc1413.c
Index: rfc1413.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/main/rfc1413.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- rfc1413.c 1999/10/20 12:49:56 1.6
+++ rfc1413.c 1999/10/24 05:59:18 1.7
@@ -124,26 +124,26 @@
* 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,
1.47 +1 -3 apache-2.0/src/modules/mpm/prefork/prefork.c
Index: prefork.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/modules/mpm/prefork/prefork.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- prefork.c 1999/10/20 12:50:05 1.46
+++ prefork.c 1999/10/24 05:59:20 1.47
@@ -2239,9 +2239,7 @@
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);
1.17 +2 -4 apache-2.0/src/modules/mpm/spmt_os2/spmt_os2.c
Index: spmt_os2.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/modules/mpm/spmt_os2/spmt_os2.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- spmt_os2.c 1999/10/20 15:15:36 1.16
+++ spmt_os2.c 1999/10/24 05:59:22 1.17
@@ -1166,10 +1166,8 @@
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);
}