From 26ef6a9a79da53c67b2759f772c01195eed084e4 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 7 Feb 2013 17:08:40 +0100 Subject: Add socket() wrapper. --- src/socket_wrapper.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index 0876de5..2ce5100 100644 --- a/src/socket_wrapper.c +++ b/src/socket_wrapper.c @@ -124,6 +124,10 @@ * without changing the format above */ #define MAX_WRAPPED_INTERFACES 40 +/********************************************************* + * SWRAP LOADING LIBC FUNCTIONS + *********************************************************/ + #include #define LIBC_NAME "libc.so.6" @@ -206,6 +210,21 @@ static int real_getsockname(int sockfd, return libc_getsockname(sockfd, addr, addrlen); } +static int (*libc_socket)(int domain, int type, int protocol); + +static int real_socket(int domain, int type, int protocol) +{ + if (libc_socket == NULL) { + *(void **)(&libc_socket) = libc_dlsym("socket"); + } + + return libc_socket(domain, type, protocol); +} + +/********************************************************* + * SWRAP HELPER FUNCTIONS + *********************************************************/ + #ifdef HAVE_IPV6 /* * FD00::5357:5FXX @@ -1461,8 +1480,7 @@ static void swrap_dump_packet(struct socket_info *si, free(packet); } -#if 0 -_PUBLIC_ int swrap_socket(int family, int type, int protocol) +int socket(int family, int type, int protocol) { struct socket_info *si; struct socket_info_fd *fi; @@ -1553,7 +1571,6 @@ _PUBLIC_ int swrap_socket(int family, int type, int protocol) return fd; } -#endif int accept(int s, struct sockaddr *addr, socklen_t *addrlen) { -- cgit