[SCM] Socket Wrapper Repository - branch master updated

Andreas Schneider asn at samba.org
Thu Dec 5 05:59:38 MST 2013


The branch, master has been updated
       via  76baedf swrap: Remove deprecated functions.
       via  fe9d674 swrap: Use swrap structure for writev.
       via  5387e90 swrap: Use swrap structure for socket.
       via  d5581e7 swrap: Use swrap structure for setsockopt.
       via  156ba02 swrap: Use swrap structure for sendto.
       via  bb16b46 swrap: Use swrap structure for sendmsg.
       via  f146e8f swrap: Use swrap structure for send.
       via  9edc0af swrap: Use swrap structure for recvfrom.
       via  063c81a swrap: Use swrap structure for recv.
       via  bc81181 swrap: Use swrap structure for readv.
       via  7c271fd swrap: Use swrap structure for read.
       via  134903a swrap: Use swrap structure for listen.
       via  a1e494b swrap: Use swrap structure for ioctl.
       via  e0767c2 swrap: Use swrap structure for getsockopt.
       via  8745a7f swrap: Use swrap structure for getsockname.
       via  ee6466e swrap: Use swrap structure for getpeername.
       via  9a391ba swrap: Use swrap structure for dup2.
       via  2cd7116 swrap: Use swrap structure for dup.
       via  8e1dcb5 swrap: Use swrap structure for connect.
       via  0beaff2 swrap: Use swrap structure for close.
       via  19ada82 swrap: Use swrap structure for bind.
       via  bc5ff6a swrap: Use swrap structure for accept.
       via  0e3ebfe swrap: Add swrap_init() and swrap_enabled().
       via  2ca8c44 swrap: Add swrap_libc_init() function.
       via  fcbfac3 swrap: Add a swrap structure.
       via  883231b Add .gitignore.
       via  6dddbf0 cmake: Set _FORTIFY_SOURCE only for optimized builds.
      from  2af983f tests: Fix test on Solaris.

http://gitweb.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 76baedfc887b61c8b98d37b21348cb49c1545381
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 13:55:43 2013 +0100

    swrap: Remove deprecated functions.

commit fe9d674f431957f4068e5ad512abd7db4cf7cd35
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 13:54:49 2013 +0100

    swrap: Use swrap structure for writev.

commit 5387e90765707cc14c8d6d010134ec8c452570f7
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 13:54:17 2013 +0100

    swrap: Use swrap structure for socket.

commit d5581e77abb06960868798f2f5f2263626d57003
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 13:53:01 2013 +0100

    swrap: Use swrap structure for setsockopt.

commit 156ba02ef15dcdf0d45e3be9fe06fe8acccf5607
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 13:51:21 2013 +0100

    swrap: Use swrap structure for sendto.

commit bb16b4616bc07a506ff99e50477abb9407722688
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 13:50:15 2013 +0100

    swrap: Use swrap structure for sendmsg.

commit f146e8ff232566fb50bb460649280cf4953d6446
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 13:49:27 2013 +0100

    swrap: Use swrap structure for send.

commit 9edc0af55a62b06e3dd41d2ad388064b2c1a3a79
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 13:47:47 2013 +0100

    swrap: Use swrap structure for recvfrom.

commit 063c81a918b899b35645d238063f9c6a11881a32
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 13:46:26 2013 +0100

    swrap: Use swrap structure for recv.

commit bc81181b2dfea7eb99cec9003f62705f6797d0dc
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 13:45:19 2013 +0100

    swrap: Use swrap structure for readv.

commit 7c271fdbba87b4cc782077126c8ac4b0795b6b29
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 12:19:48 2013 +0100

    swrap: Use swrap structure for read.

commit 134903a7c4622a7971e7d4cc7f0fbfc1350beb82
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 12:18:31 2013 +0100

    swrap: Use swrap structure for listen.

commit a1e494ba5d4a7badafc0c3debfddfd9f6d3e4e61
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 12:17:27 2013 +0100

    swrap: Use swrap structure for ioctl.

commit e0767c253ec920044c93b8c14cdf64e953fc8e49
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 12:14:32 2013 +0100

    swrap: Use swrap structure for getsockopt.

commit 8745a7f2752a747655499ecc290c91390e4caaa7
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 12:13:04 2013 +0100

    swrap: Use swrap structure for getsockname.

commit ee6466ee26d8642137959d8d17029736a35cdb96
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 12:11:57 2013 +0100

    swrap: Use swrap structure for getpeername.

commit 9a391bab56829a6881b48de96a86b7cba1668d45
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 12:11:01 2013 +0100

    swrap: Use swrap structure for dup2.

commit 2cd71169229374e0b83dbc2a4bcdd2d84a4aad6a
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 12:10:10 2013 +0100

    swrap: Use swrap structure for dup.

commit 8e1dcb5295bb032ea2774b2d07ba11db4b8854c0
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 12:08:21 2013 +0100

    swrap: Use swrap structure for connect.

commit 0beaff21197b4bc23100eac025c08f0e957243e8
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 12:07:27 2013 +0100

    swrap: Use swrap structure for close.

commit 19ada82dbdab1d01fe8b449ab5b2448ffeac51b5
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 12:05:24 2013 +0100

    swrap: Use swrap structure for bind.

commit bc5ff6a765847bee90001014a195f728585ad98c
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 12:04:01 2013 +0100

    swrap: Use swrap structure for accept.

commit 0e3ebfe55b7afd62c232f360cf930bdf41cea785
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 11:58:21 2013 +0100

    swrap: Add swrap_init() and swrap_enabled().

commit 2ca8c448104fa30cb9c102332a2e6a37596b858d
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 11:41:39 2013 +0100

    swrap: Add swrap_libc_init() function.

commit fcbfac342e4bef9c4d0741f249ce395a342b6d9a
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Wed Dec 4 18:19:59 2013 +0100

    swrap: Add a swrap structure.

commit 883231bbf092faf298bef89f2835e335582aa98e
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Thu Dec 5 12:08:49 2013 +0100

    Add .gitignore.

commit 6dddbf00c37fb22f08ff422195ed278c2aea8379
Author: Andreas Schneider <asn at cryptomilk.org>
Date:   Wed Dec 4 17:41:05 2013 +0100

    cmake: Set _FORTIFY_SOURCE only for optimized builds.

-----------------------------------------------------------------------

Summary of changes:
 .gitignore                              |    9 +
 cmake/Modules/DefineCompilerFlags.cmake |    6 +-
 config.h.cmake                          |    1 +
 src/socket_wrapper.c                    |  614 ++++++++++++++-----------------
 4 files changed, 290 insertions(+), 340 deletions(-)
 create mode 100644 .gitignore


Changeset truncated at 500 lines:

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8fd1310
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,9 @@
+*.a
+*.o
+.*
+*.swp
+*~$
+build
+obj
+cscope.*
+tags
diff --git a/cmake/Modules/DefineCompilerFlags.cmake b/cmake/Modules/DefineCompilerFlags.cmake
index 582ea1c..0ab8802 100644
--- a/cmake/Modules/DefineCompilerFlags.cmake
+++ b/cmake/Modules/DefineCompilerFlags.cmake
@@ -28,10 +28,10 @@ if (UNIX AND NOT WIN32)
 
         if (CMAKE_BUILD_TYPE)
             string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
-            if (NOT CMAKE_BUILD_TYPE_LOWER MATCHES debug)
-                check_c_compiler_flag("-D_FORTIFY_SOURCE=2" WITH_FORTIFY_SOURCE)
+            if (CMAKE_BUILD_TYPE_LOWER MATCHES (release|relwithdebinfo|minsizerel))
+                check_c_compiler_flag("-Wp,-D_FORTIFY_SOURCE=2" WITH_FORTIFY_SOURCE)
                 if (WITH_FORTIFY_SOURCE)
-                    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=2")
+                    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wp,-D_FORTIFY_SOURCE=2")
                 endif (WITH_FORTIFY_SOURCE)
             endif()
         endif()
diff --git a/config.h.cmake b/config.h.cmake
index d47478b..3def5e7 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -38,6 +38,7 @@
 #cmakedefine HAVE_IPV6 1
 
 #cmakedefine HAVE_APPLE 1
+#cmakedefine HAVE_LIBSOCKET 1
 
 /*************************** ENDIAN *****************************/
 
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index bf4828d..4f31311 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -62,6 +62,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <stdarg.h>
+#include <stdbool.h>
 #include <unistd.h>
 
 enum swrap_dbglvl_e {
@@ -269,344 +270,241 @@ static void swrap_log(enum swrap_dbglvl_e dbglvl, const char *format, ...)
 
 #include <dlfcn.h>
 
-#define LIBC_NAME "libc.so"
+struct swrap_libc_fns {
+	int (*libc_accept)(int sockfd,
+			   struct sockaddr *addr,
+			   socklen_t *addrlen);
+	int (*libc_bind)(int sockfd,
+			 const struct sockaddr *addr,
+			 socklen_t addrlen);
+	int (*libc_close)(int fd);
+	int (*libc_connect)(int sockfd,
+			    const struct sockaddr *addr,
+			    socklen_t addrlen);
+	int (*libc_dup)(int fd);
+	int (*libc_dup2)(int oldfd, int newfd);
+	int (*libc_getpeername)(int sockfd,
+				struct sockaddr *addr,
+				socklen_t *addrlen);
+	int (*libc_getsockname)(int sockfd,
+				struct sockaddr *addr,
+				socklen_t *addrlen);
+	int (*libc_getsockopt)(int sockfd,
+			       int level,
+			       int optname,
+			       void *optval,
+			       socklen_t *optlen);
+	int (*libc_ioctl)(int d, unsigned long int request, ...);
+	int (*libc_listen)(int sockfd, int backlog);
+	int (*libc_read)(int fd, void *buf, size_t count);
+	ssize_t (*libc_readv)(int fd, const struct iovec *iov, int iovcnt);
+	int (*libc_recv)(int sockfd, void *buf, size_t len, int flags);
+	int (*libc_recvfrom)(int sockfd,
+			     void *buf,
+			     size_t len,
+			     int flags,
+			     struct sockaddr *src_addr,
+			     socklen_t *addrlen);
+	int (*libc_send)(int sockfd, const void *buf, size_t len, int flags);
+	int (*libc_sendmsg)(int sockfd, const struct msghdr *msg, int flags);
+	int (*libc_sendto)(int sockfd,
+			   const void *buf,
+			   size_t len,
+			   int flags,
+			   const  struct sockaddr *dst_addr,
+			   socklen_t addrlen);
+	int (*libc_setsockopt)(int sockfd,
+			       int level,
+			       int optname,
+			       const void *optval,
+			       socklen_t optlen);
+	int (*libc_socket)(int domain, int type, int protocol);
+	ssize_t (*libc_writev)(int fd, const struct iovec *iov, int iovcnt);
+};
 
-#ifndef HAVE_APPLE
-static void *libc_hnd;
+struct swrap {
+	void *libc_handle;
+	void *libsocket_handle;
 
-static int libc_dlopen(void)
-{
-	unsigned int i;
-	int flags = RTLD_LAZY;
+	bool initialised;
+	bool enabled;
 
-#ifdef RTLD_DEEPBIND
-	flags |= RTLD_DEEPBIND;
-#endif
+	char *socket_dir;
 
-	if (libc_hnd != NULL) {
-		return 0;
-	}
-
-	for (libc_hnd = NULL, i = 10; libc_hnd == NULL; i--) {
-		char soname[256] = {0};
+	struct swrap_libc_fns fns;
+};
 
-		snprintf(soname, sizeof(soname), "%s.%u", LIBC_NAME, i);
-		libc_hnd = dlopen(soname, flags);
-	}
+static struct swrap swrap;
 
-	if (libc_hnd == NULL) {
-		SWRAP_LOG(SWRAP_LOG_ERROR,
-			  "Failed to dlopen %s.%u: %s\n",
-			  LIBC_NAME, i, dlerror());
-		exit(-1);
-	}
+/* prototypes */
+static const char *socket_wrapper_dir(void);
 
-	return 0;
-}
-#endif
+#define LIBC_NAME "libc.so"
 
-static void *libc_dlsym(const char *name)
+static void *swrap_libc_fn(void *handle, const char *fn_name)
 {
 	void *func;
 
-#ifdef HAVE_APPLE
-	func = dlsym(RTLD_NEXT, name);
-#else
-	libc_dlopen();
-
-	func = dlsym(libc_hnd, name);
-#endif
+	if (handle == NULL) {
+		return NULL;
+	}
 
+	func = dlsym(handle, fn_name);
 	if (func == NULL) {
 		SWRAP_LOG(SWRAP_LOG_ERROR,
-			  "Failed to find %s in %s: %s\n",
-			  name, LIBC_NAME, dlerror());
+			  "Failed to find %s: %s\n",
+			  fn_name, dlerror());
 		exit(-1);
 	}
 
 	return func;
 }
 
-static int (*libc_accept)(int sockfd,
-			  struct sockaddr *addr,
-			  socklen_t *addrlen);
-
-static int real_accept(int sockfd,
-		       struct sockaddr *addr,
-		       socklen_t *addrlen)
+static void swrap_libc_init(void)
 {
-	if (libc_accept == NULL) {
-		*(void **)(&libc_accept) = libc_dlsym("accept");
-	}
-
-	return libc_accept(sockfd, addr, addrlen);
-}
-
-static int (*libc_bind)(int sockfd,
-			const struct sockaddr *addr,
-			socklen_t addrlen);
+	int i;
+	int flags = RTLD_LAZY;
+	void *handle;
 
-static int real_bind(int sockfd,
-		     const struct sockaddr *addr,
-		     socklen_t addrlen)
-{
-	if (libc_bind == NULL) {
-		*(void **)(&libc_bind) = libc_dlsym("bind");
-	}
+#ifdef HAVE_APPLE
+	handle = RTLD_NEXT;
+#else /* !HAVE_APPLE */
 
-	return libc_bind(sockfd, addr, addrlen);
-}
+#ifdef RTLD_DEEPBIND
+	flags |= RTLD_DEEPBIND;
+#endif
 
-static int (*libc_close)(int fd);
+	/* Load libc.so */
+	for (swrap.libc_handle = NULL, i = 10; swrap.libc_handle == NULL && i >= 0; i--) {
+		char soname[256] = {0};
 
-static int real_close(int fd)
-{
-	if (libc_close == NULL) {
-		*(void **)(&libc_close) = libc_dlsym("close");
+		snprintf(soname, sizeof(soname), "%s.%d", LIBC_NAME, i);
+		swrap.libc_handle = dlopen(soname, flags);
 	}
 
-	return libc_close(fd);
-}
-
-static int (*libc_connect)(int sockfd,
-			   const struct sockaddr *addr,
-			   socklen_t addrlen);
-
-static int real_connect(int sockfd,
-			const struct sockaddr *addr,
-			socklen_t addrlen)
-{
-	if (libc_connect == NULL) {
-		*(void **)(&libc_connect) = libc_dlsym("connect");
+	if (swrap.libc_handle == NULL) {
+		SWRAP_LOG(SWRAP_LOG_ERROR,
+			  "Failed to dlopen %s.%d: %s\n",
+			  LIBC_NAME, i, dlerror());
+		exit(-1);
 	}
 
-	return libc_connect(sockfd, addr, addrlen);
-}
-
-static int (*libc_dup)(int fd);
+#ifdef HAVE_LIBSOCKET
+	for (swrap.libsocket_handle = NULL, i = 10; swrap.libsocket_handle == NULL && i >= 0; i--) {
+		char soname[256] = {0};
+                i = 1;
 
-static int real_dup(int fd)
-{
-	if (libc_dup == NULL) {
-		*(void **)(&libc_dup) = libc_dlsym("dup");
+		snprintf(soname, sizeof(soname), "libsocket.so.%d", i);
+		swrap.libsocket_handle = dlopen(soname, flags);
 	}
 
-	return libc_dup(fd);
-}
-
-static int (*libc_dup2)(int oldfd, int newfd);
-
-static int real_dup2(int oldfd, int newfd)
-{
-	if (libc_dup2 == NULL) {
-		*(void **)(&libc_dup2) = libc_dlsym("dup2");
+	if (swrap.libsocket_handle == NULL) {
+		SWRAP_LOG(SWRAP_LOG_ERROR,
+			 "Failed to dlopen libsocket.so: %s",
+			 dlerror());
+		exit(-1);
 	}
+#endif /* HAVE_LIBSOCKET */
 
-	return libc_dup2(oldfd, newfd);
-}
+#endif /* !HAVE_APPLE */
 
-static int (*libc_getpeername)(int sockfd,
-			       struct sockaddr *addr,
-			       socklen_t *addrlen);
+	/* Load libc functions */
+#ifndef HAVE_APPLE
+	handle = swrap.libc_handle;
+#endif
+	*(void **) (&swrap.fns.libc_close) =
+		swrap_libc_fn(handle, "close");
+	*(void **) (&swrap.fns.libc_dup) =
+		swrap_libc_fn(handle, "dup");
+	*(void **) (&swrap.fns.libc_dup2) =
+		swrap_libc_fn(handle, "dup2");
+	*(void **) (&swrap.fns.libc_ioctl) =
+		swrap_libc_fn(handle, "ioctl");
+	*(void **) (&swrap.fns.libc_read) =
+		swrap_libc_fn(handle, "read");
+	*(void **) (&swrap.fns.libc_readv) =
+		swrap_libc_fn(handle, "readv");
+	*(void **) (&swrap.fns.libc_writev) =
+		swrap_libc_fn(handle, "writev");
+
+	/* Load libsocket funcitons */
+#if !defined(HAVE_APPLE) && defined(HAVE_LIBSOCKET)
+	handle = swrap.libsocket_handle;
+#endif
 
-static int real_getpeername(int sockfd,
-			    struct sockaddr *addr,
-			    socklen_t *addrlen)
-{
-	if (libc_getpeername == NULL) {
-		*(void **)(&libc_getpeername) = libc_dlsym("getpeername");
+	*(void **) (&swrap.fns.libc_accept) =
+		swrap_libc_fn(handle, "accept");
+	*(void **) (&swrap.fns.libc_bind) =
+		swrap_libc_fn(handle, "bind");
+	*(void **) (&swrap.fns.libc_connect) =
+		swrap_libc_fn(handle, "connect");
+	*(void **) (&swrap.fns.libc_getpeername) =
+		swrap_libc_fn(handle, "getpeername");
+	*(void **) (&swrap.fns.libc_getsockname) =
+		swrap_libc_fn(handle, "getsockname");
+	*(void **) (&swrap.fns.libc_getsockopt) =
+		swrap_libc_fn(handle, "getsockopt");
+	*(void **) (&swrap.fns.libc_listen) =
+		swrap_libc_fn(handle, "listen");
+	*(void **) (&swrap.fns.libc_recv) =
+		swrap_libc_fn(handle, "recv");
+	*(void **) (&swrap.fns.libc_recvfrom) =
+		swrap_libc_fn(handle, "recvfrom");
+	*(void **) (&swrap.fns.libc_send) =
+		swrap_libc_fn(handle, "send");
+	*(void **) (&swrap.fns.libc_sendmsg) =
+		swrap_libc_fn(handle, "sendmsg");
+	*(void **) (&swrap.fns.libc_sendto) =
+		swrap_libc_fn(handle, "sendto");
+	*(void **) (&swrap.fns.libc_setsockopt) =
+		swrap_libc_fn(handle, "setsockopt");
+	*(void **) (&swrap.fns.libc_socket) =
+		swrap_libc_fn(handle, "socket");
+}
+
+static void swrap_init(void)
+{
+	if (swrap.initialised) {
+		return;
 	}
 
-	return libc_getpeername(sockfd, addr, addrlen);
-}
-
-static int (*libc_getsockname)(int sockfd,
-			       struct sockaddr *addr,
-			       socklen_t *addrlen);
-
-static int real_getsockname(int sockfd,
-			    struct sockaddr *addr,
-			    socklen_t *addrlen)
-{
-	if (libc_getsockname == NULL) {
-		*(void **)(&libc_getsockname) = libc_dlsym("getsockname");
+	swrap.socket_dir = strdup(socket_wrapper_dir());
+	if (swrap.socket_dir != NULL) {
+		swrap.enabled = true;
 	}
 
-	return libc_getsockname(sockfd, addr, addrlen);
-}
+	swrap_libc_init();
 
-static int (*libc_getsockopt)(int sockfd,
-			      int level,
-			      int optname,
-			      void *optval,
-			      socklen_t *optlen);
+	swrap.initialised = true;
+}
 
-static int real_getsockopt(int sockfd,
-			   int level,
-			   int optname,
-			   void *optval,
-			   socklen_t *optlen)
+static int swrap_enabled(void)
 {
-	if (libc_getsockopt == NULL) {
-		*(void **)(&libc_getsockopt) = libc_dlsym("getsockopt");
-	}
+	swrap_init();
 
-	return libc_getsockopt(sockfd, level, optname, optval, optlen);
+	return swrap.enabled ? 1 : 0;
 }
 
-static int (*libc_ioctl)(int d, unsigned long int request, ...);
-
-static int real_vioctl(int d, unsigned long int request, va_list ap) {
+static int libc_vioctl(int d, unsigned long int request, va_list ap)
+{
 	long int args[4];
 	int rc;
 	int i;
 
-	if (libc_ioctl == NULL) {
-		*(void **)(&libc_ioctl) = libc_dlsym("ioctl");
-	}
-
 	for (i = 0; i < 4; i++) {
 		args[i] = va_arg(ap, long int);
 	}
 
-	rc = libc_ioctl(d, request, args[0], args[1], args[2], args[3]);
+	rc = swrap.fns.libc_ioctl(d,
+				  request,
+				  args[0],
+				  args[1],
+				  args[2],
+				  args[3]);
 
 	return rc;
 }
 
-static int (*libc_listen)(int sockfd, int backlog);
-
-static int real_listen(int sockfd, int backlog)
-{
-	if (libc_listen == NULL) {
-		*(void **)(&libc_listen) = libc_dlsym("listen");
-	}
-
-	return libc_listen(sockfd, backlog);
-}
-
-static int (*libc_read)(int fd, void *buf, size_t count);
-
-static int real_read(int fd, void *buf, size_t count)
-{
-	if (libc_read == NULL) {
-		*(void **)(&libc_read) = libc_dlsym("read");
-	}
-
-	return libc_read(fd, buf, count);
-}
-
-static ssize_t (*libc_readv)(int fd, const struct iovec *iov, int iovcnt);
-
-static ssize_t real_readv(int fd, const struct iovec *iov, int iovcnt)
-{
-	if (libc_readv == NULL) {
-		*(void **)(&libc_readv) = libc_dlsym("readv");
-	}
-
-	return libc_readv(fd, iov, iovcnt);
-}
-
-static int (*libc_recv)(int sockfd, void *buf, size_t len, int flags);
-
-static int real_recv(int sockfd, void *buf, size_t len, int flags)
-{
-	if (libc_recv == NULL) {
-		*(void **)(&libc_recv) = libc_dlsym("recv");
-	}
-
-	return libc_recv(sockfd, buf, len, flags);
-}
-
-static int (*libc_recvfrom)(int sockfd, void *buf, size_t len, int flags,
-			    struct sockaddr *src_addr, socklen_t *addrlen);
-
-static int real_recvfrom(int sockfd, void *buf, size_t len, int flags,
-			 struct sockaddr *src_addr, socklen_t *addrlen)
-{
-	if (libc_recvfrom == NULL) {
-		*(void **)(&libc_recvfrom) = libc_dlsym("recvfrom");
-	}
-
-	return libc_recvfrom(sockfd, buf, len, flags, src_addr, addrlen);
-}
-


-- 
Socket Wrapper Repository


More information about the samba-cvs mailing list