summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2013-02-07 16:59:12 +0100
committerAndreas Schneider <asn@cryptomilk.org>2013-02-07 16:59:12 +0100
commitb390b16d43c46fd6acc20ee6eee0aec9f22cec68 (patch)
tree1976f890fd395dc02ffad75665c25781eac9b573 /src
parent2b4acc824ef61f6468be31b83344f5ac4e45a41f (diff)
downloadsocket_wrapper-b390b16d43c46fd6acc20ee6eee0aec9f22cec68.tar.gz
socket_wrapper-b390b16d43c46fd6acc20ee6eee0aec9f22cec68.tar.xz
socket_wrapper-b390b16d43c46fd6acc20ee6eee0aec9f22cec68.zip
Add accept() wrapper.
Diffstat (limited to 'src')
-rw-r--r--src/socket_wrapper.c90
1 files changed, 64 insertions, 26 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index c35e1d0..127b130 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -132,44 +132,78 @@ static void *libc_hnd;
static int libc_dlopen(void)
{
- if (libc_hnd != NULL) {
- return 0;
- }
- libc_hnd = dlopen(LIBC_NAME, RTLD_LAZY);
- if (libc_hnd == NULL) {
- printf("Failed to dlopen %s: %s\n", LIBC_NAME, dlerror());
- exit(-1);
- }
-
- return 0;
+ if (libc_hnd != NULL) {
+ return 0;
+ }
+ libc_hnd = dlopen(LIBC_NAME, RTLD_LAZY);
+ if (libc_hnd == NULL) {
+ printf("Failed to dlopen %s: %s\n", LIBC_NAME, dlerror());
+ exit(-1);
+ }
+
+ return 0;
}
static void *libc_dlsym(const char *name)
{
- void *func;
+ void *func;
+
+ libc_dlopen();
+
+ func = dlsym(libc_hnd, name);
+
+ if (func == NULL) {
+ printf("Failed to find %s in %s: %s\n",
+ name, LIBC_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)
+{
+ if (libc_accept == NULL) {
+ *(void **)(&libc_accept) = libc_dlsym("accept");
+ }
- libc_dlopen();
+ return libc_accept(sockfd, addr, addrlen);
+}
- func = dlsym(libc_hnd, name);
+static int (*libc_bind)(int sockfd,
+ const struct sockaddr *addr,
+ socklen_t addrlen);
- if (func == NULL) {
- printf("Failed to find %s in %s: %s\n",
- name, LIBC_NAME, dlerror());
- exit(-1);
- }
+static int real_bind(int sockfd,
+ const struct sockaddr *addr,
+ socklen_t addrlen)
+{
+ if (libc_bind == NULL) {
+ *(void **)(&libc_bind) = libc_dlsym("bind");
+ }
- return func;
+ return libc_bind(sockfd, addr, addrlen);
}
-static int (*libc_accept)(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
+static int (*libc_getsockname)(int sockfd,
+ struct sockaddr *addr,
+ socklen_t *addrlen);
-static int real_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
+static int real_getsockname(int sockfd,
+ struct sockaddr *addr,
+ socklen_t *addrlen)
{
- if (libc_accept == NULL) {
- *(void **)(&libc_accept) = libc_dlsym("accept");
- }
+ if (libc_getsockname == NULL) {
+ *(void **)(&libc_getsockname) = libc_dlsym("getsockname");
+ }
- return libc_accept(sockfd, addr, addrlen);
+ return libc_getsockname(sockfd, addr, addrlen);
}
#ifdef HAVE_IPV6
@@ -1427,6 +1461,7 @@ static void swrap_dump_packet(struct socket_info *si,
free(packet);
}
+#if 0
_PUBLIC_ int swrap_socket(int family, int type, int protocol)
{
struct socket_info *si;
@@ -1518,8 +1553,9 @@ _PUBLIC_ int swrap_socket(int family, int type, int protocol)
return fd;
}
+#endif
-_PUBLIC_ int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
+int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
{
struct socket_info *parent_si, *child_si;
struct socket_info_fd *child_fi;
@@ -1757,6 +1793,7 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family)
return 0;
}
+#if 0
_PUBLIC_ int swrap_connect(int s, const struct sockaddr *serv_addr, socklen_t addrlen)
{
@@ -2668,3 +2705,4 @@ _PUBLIC_ int swrap_dup2(int fd, int newfd)
SWRAP_DLIST_ADD(si->fds, fi);
return fi->fd;
}
+#endif /* 0 */