From d2917f30b2f43e4447ce3782d66f57826a72a195 Mon Sep 17 00:00:00 2001 From: trawick Date: Wed, 2 May 2001 02:32:49 +0000 Subject: Add a family field to apr_sockaddr_t so there is a straightforward place to look to find the address family. (Yes, it could be found in addr->sa.sin.sin_family even if it was not an AF_INET socket but that isn't so friendly.) Also, try fairly hard to get the port field filled out properly. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@61580 13f79535-47bb-0310-9956-ffa450edef68 --- include/apr_network_io.h | 2 ++ network_io/os2/sockets.c | 4 +++- network_io/unix/sa_common.c | 4 ++++ network_io/unix/sockets.c | 4 +++- network_io/win32/sockets.c | 4 +++- test/client.c | 2 +- 6 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/apr_network_io.h b/include/apr_network_io.h index 316ac95f3..ac1e0bd72 100644 --- a/include/apr_network_io.h +++ b/include/apr_network_io.h @@ -176,6 +176,8 @@ struct apr_sockaddr_t { char *servname; /** The numeric port */ apr_port_t port; + /** The family */ + apr_int32_t family; union { /** IPv4 sockaddr structure */ struct sockaddr_in sin; diff --git a/network_io/os2/sockets.c b/network_io/os2/sockets.c index 6b6ba9328..c1a7c5185 100644 --- a/network_io/os2/sockets.c +++ b/network_io/os2/sockets.c @@ -85,7 +85,9 @@ static apr_status_t socket_cleanup(void *sock) static void set_socket_vars(apr_socket_t *sock, int family) { + sock->local_addr->family = family; sock->local_addr->sa.sin.sin_family = family; + sock->remote_addr->family = family; sock->remote_addr->sa.sin.sin_family = family; if (family == AF_INET) { @@ -222,7 +224,7 @@ apr_status_t apr_accept(apr_socket_t **new, apr_socket_t *sock, apr_pool_t *conn if ((*new)->socketdes < 0) { return APR_OS2_STATUS(sock_errno()); } - + (*new)->remote_addr->port = ntohs((*new)->remote_addr->sa.sin.sin_port); apr_pool_cleanup_register((*new)->cntxt, (void *)(*new), socket_cleanup, apr_pool_cleanup_null); return APR_SUCCESS; diff --git a/network_io/unix/sa_common.c b/network_io/unix/sa_common.c index b823a91fb..a4c5c940e 100644 --- a/network_io/unix/sa_common.c +++ b/network_io/unix/sa_common.c @@ -74,6 +74,7 @@ APR_DECLARE(apr_status_t) apr_sockaddr_port_set(apr_sockaddr_t *sockaddr, apr_port_t port) { + sockaddr->port = port; /* XXX IPv6: assumes sin_port and sin6_port at same offset */ sockaddr->sa.sin.sin_port = htons(port); return APR_SUCCESS; @@ -137,6 +138,9 @@ APR_DECLARE(apr_status_t) apr_sockaddr_ip_get(char **addr, static void set_sockaddr_vars(apr_sockaddr_t *addr, int family) { + addr->family = family; + /* XXX IPv6: assumes sin_port and sin6_port at same offset */ + addr->port = ntohs(addr->sa.sin.sin_port); addr->sa.sin.sin_family = family; if (family == APR_INET) { diff --git a/network_io/unix/sockets.c b/network_io/unix/sockets.c index adeb96121..d60712e9e 100644 --- a/network_io/unix/sockets.c +++ b/network_io/unix/sockets.c @@ -75,7 +75,9 @@ static apr_status_t socket_cleanup(void *sock) static void set_socket_vars(apr_socket_t *sock, int family, int type) { sock->type = type; + sock->local_addr->family = family; sock->local_addr->sa.sin.sin_family = family; + sock->remote_addr->family = family; sock->remote_addr->sa.sin.sin_family = family; if (family == APR_INET) { @@ -224,7 +226,7 @@ apr_status_t apr_accept(apr_socket_t **new, apr_socket_t *sock, apr_pool_t *conn (*new)->local_addr->ipaddr_ptr = &(*new)->local_addr->sa.sin6.sin6_addr; } #endif - + (*new)->remote_addr->port = ntohs((*new)->remote_addr->sa.sin.sin_port); if (sock->local_port_unknown) { /* not likely for a listening socket, but theoretically possible :) */ (*new)->local_port_unknown = 1; diff --git a/network_io/win32/sockets.c b/network_io/win32/sockets.c index 748758942..dff1cd780 100644 --- a/network_io/win32/sockets.c +++ b/network_io/win32/sockets.c @@ -75,7 +75,9 @@ static apr_status_t socket_cleanup(void *sock) static void set_socket_vars(apr_socket_t *sock, int family, int type) { sock->type = type; + sock->local_addr->family = family; sock->local_addr->sa.sin.sin_family = family; + sock->remote_addr->family = family; sock->remote_addr->sa.sin.sin_family = family; if (family == AF_INET) { @@ -248,7 +250,7 @@ APR_DECLARE(apr_status_t) apr_accept(apr_socket_t **new, apr_socket_t *sock, (*new)->local_addr->ipaddr_ptr = &(*new)->local_addr->sa.sin6.sin6_addr; } #endif - + (*new)->remote_addr->port = ntohs((*new)->remote_addr->sa.sin.sin_port); if (sock->local_port_unknown) { /* not likely for a listening socket, but theoretically possible :) */ (*new)->local_port_unknown = 1; diff --git a/test/client.c b/test/client.c index bb5d3db63..7f95d5ba2 100644 --- a/test/client.c +++ b/test/client.c @@ -115,7 +115,7 @@ int main(int argc, char *argv[]) fprintf(stdout,"OK\n"); fprintf(stdout, "\tClient: Creating new socket......."); - if (apr_socket_create(&sock, remote_sa->sa.sin.sin_family, SOCK_STREAM, + if (apr_socket_create(&sock, remote_sa->family, SOCK_STREAM, context) != APR_SUCCESS) { fprintf(stderr, "Couldn't create socket\n"); exit(-1); -- cgit v1.2.1