apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Justin Erenkrantz <jerenkra...@ebuilt.com>
Subject [PATCH] Add support for Unix domain sockets
Date Sat, 05 Jan 2002 00:48:25 GMT
Please review.  This attempts to add support for Unix domain
sockets in APR (call APR_UNIX as the socket type).  I believe 
Win32 has Unix domain socket support, but I'm not sure.

The only caveat is that it'd be *nice* to have an API to set
the path, but it isn't a big deal because that's part of the
exposed apr_sockaddr_t.

This is needed for EGD support.  (That patch is coming up in
a sec.)  -- justin

Index: configure.in
===================================================================
RCS file: /home/cvs/apr/configure.in,v
retrieving revision 1.392
diff -u -r1.392 configure.in
--- configure.in	2 Jan 2002 09:12:37 -0000	1.392
+++ configure.in	5 Jan 2002 00:42:32 -0000
@@ -671,6 +671,7 @@
     sys/time.h		\
     sys/types.h		\
     sys/uio.h		\
+    sys/un.h		\
     sys/wait.h)
 
 dnl IRIX 6.5 has a problem in <netinet/tcp.h> which prevents it from
@@ -714,6 +715,7 @@
 AC_SUBST(sys_typesh)
 AC_SUBST(sys_timeh)
 AC_SUBST(sys_uioh)
+AC_SUBST(sys_unh)
 AC_SUBST(unistdh)
 AC_SUBST(signalh)
 AC_SUBST(sys_waith)
@@ -1335,6 +1350,10 @@
 fi
 
 AC_SUBST(have_ipv6)
+
+dnl #----------------------------- Check for Unix domain socket addressing
+APR_CHECK_SOCKADDR_UN
+AC_SUBST(have_unix_domain)
 
 dnl #----------------------------- Finalize the variables
 
Index: build/apr_network.m4
===================================================================
RCS file: /home/cvs/apr/build/apr_network.m4,v
retrieving revision 1.11
diff -u -r1.11 apr_network.m4
--- build/apr_network.m4	7 Dec 2001 15:48:05 -0000	1.11
+++ build/apr_network.m4	5 Jan 2002 00:42:32 -0000
@@ -463,6 +463,30 @@
 fi
 ])
 
+AC_DEFUN(APR_CHECK_SOCKADDR_UN,[
+AC_CACHE_CHECK(for sockaddr_un, ac_cv_define_sockaddr_un,[
+AC_TRY_COMPILE([
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_UN_H
+#include <sys/un.h>
+#endif
+],[
+struct sockaddr_un sa;
+],[
+    ac_cv_define_sockaddr_un=yes
+],[
+    ac_cv_define_sockaddr_un=no
+])
+])
+
+if test "$ac_cv_define_sockaddr_un" = "yes"; then
+  have_unix_domain=1
+else
+  have_unix_domain=0
+fi
+])
 
 dnl
 dnl Check to see if this platform includes sa_len in it's
Index: include/apr.h.in
===================================================================
RCS file: /home/cvs/apr/include/apr.h.in,v
retrieving revision 1.96
diff -u -r1.96 apr.h.in
--- include/apr.h.in	29 Dec 2001 23:14:21 -0000	1.96
+++ include/apr.h.in	5 Jan 2002 00:42:33 -0000
@@ -59,6 +59,7 @@
 #define APR_HAVE_SYS_TIME_H      @sys_timeh@
 #define APR_HAVE_SYS_TYPES_H     @sys_typesh@
 #define APR_HAVE_SYS_UIO_H       @sys_uioh@
+#define APR_HAVE_SYS_UN_H        @sys_unh@
 #define APR_HAVE_SYS_WAIT_H      @sys_waith@
 #define APR_HAVE_UNISTD_H        @unistdh@
 
@@ -104,6 +105,7 @@
 #define APR_HAVE_INET_ADDR      @have_inet_addr@
 #define APR_HAVE_INET_NETWORK   @have_inet_network@
 #define APR_HAVE_IPV6           @have_ipv6@
+#define APR_HAVE_UNIX_DOMAIN    @have_unix_domain@
 #define APR_HAVE_MEMMOVE        @have_memmove@
 #define APR_HAVE_SETRLIMIT      @have_setrlimit@
 #define APR_HAVE_SIGACTION      @have_sigaction@
Index: include/apr_network_io.h
===================================================================
RCS file: /home/cvs/apr/include/apr_network_io.h,v
retrieving revision 1.114
diff -u -r1.114 apr_network_io.h
--- include/apr_network_io.h	26 Dec 2001 21:18:26 -0000	1.114
+++ include/apr_network_io.h	5 Jan 2002 00:42:33 -0000
@@ -74,6 +74,10 @@
 #include <netinet/in.h>
 #endif
 
+#if APR_HAVE_SYS_UN_H
+#include <sys/un.h>
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
@@ -161,6 +165,9 @@
 #if APR_HAVE_IPV6
 #define APR_INET6    AF_INET6
 #endif
+#if APR_HAVE_UNIX_DOMAIN
+#define APR_UNIX     AF_UNIX
+#endif
 
 /**
  * Enum to tell us if we're interested in remote or local socket
@@ -219,6 +226,10 @@
 #if APR_HAVE_IPV6
         /** IPv6 sockaddr structure */
         struct sockaddr_in6 sin6;
+#endif
+#if APR_HAVE_UNIX_DOMAIN
+        /** Unix domain structure */
+        struct sockaddr_un sunix;
 #endif
     } sa;
     /** How big is the sockaddr we're using? */
Index: network_io/unix/sockets.c
===================================================================
RCS file: /home/cvs/apr/network_io/unix/sockets.c,v
retrieving revision 1.90
diff -u -r1.90 sockets.c
--- network_io/unix/sockets.c	26 Nov 2001 16:34:36 -0000	1.90
+++ network_io/unix/sockets.c	5 Jan 2002 00:42:33 -0000
@@ -106,6 +106,19 @@
         sock->remote_addr->ipaddr_len = sizeof(struct in6_addr);
     }
 #endif
+#if APR_HAVE_UNIX_DOMAIN
+    else if (family == APR_UNIX) {
+        sock->local_addr->salen = sizeof(struct sockaddr_un);
+        sock->local_addr->addr_str_len = 108;
+        sock->local_addr->ipaddr_ptr = NULL;
+        sock->local_addr->ipaddr_len = 0;
+
+        sock->remote_addr->salen = sizeof(struct sockaddr_un);
+        sock->remote_addr->addr_str_len = 108;
+        sock->remote_addr->ipaddr_ptr = NULL;
+        sock->remote_addr->ipaddr_len = 0;
+    }
+#endif
     sock->netmask = 0;
 #if defined(BEOS) && !defined(BEOS_BONE)
     /* BeOS pre-BONE has TCP_NODELAY on by default and it can't be
@@ -305,21 +318,28 @@
     }
 
     sock->remote_addr = sa;
-    /* XXX IPv6 assumes sin_port and sin6_port at same offset */
-    if (sock->local_addr->sa.sin.sin_port == 0) {
-        /* connect() got us an ephemeral port */
-        sock->local_port_unknown = 1;
-    }
-    /* XXX IPv6 to be handled better later... */
-    if (
+    switch(sock->local_addr->family) {
+    case APR_INET:
+    case APR_INET6:
+        /* XXX IPv6 assumes sin_port and sin6_port at same offset */
+        if (sock->local_addr->sa.sin.sin_port == 0) {
+            /* connect() got us an ephemeral port */
+            sock->local_port_unknown = 1;
+        }
+        /* XXX IPv6 to be handled better later... */
+        if (
 #if APR_HAVE_IPV6
-        sock->local_addr->sa.sin.sin_family == APR_INET6 ||
+            sock->local_addr->sa.sin.sin_family == APR_INET6 ||
 #endif
-        sock->local_addr->sa.sin.sin_addr.s_addr == 0) {
-        /* not bound to specific local interface; connect() had to assign
-         * one for the socket
-         */
-        sock->local_interface_unknown = 1;
+            sock->local_addr->sa.sin.sin_addr.s_addr == 0) {
+            /* not bound to specific local interface; connect() had to assign
+             * one for the socket
+             */
+            sock->local_interface_unknown = 1;
+        }
+        break;
+    case APR_UNIX:
+        break;
     }
 #ifndef HAVE_POLL
     sock->connected=1;


Mime
View raw message