X-Git-Url: http://git.onelab.eu/?p=vsys-wrappers.git;a=blobdiff_plain;f=packetseer%2Fpacketseer.c;fp=packetseer%2Fpacketseer.c;h=8ab785d8d6f417bb19ee51aed2fd7ce63b9c563b;hp=0000000000000000000000000000000000000000;hb=b6722e77a5298d30624ce01c9ab311b75624f37e;hpb=959343899a38dd5bf2b2efb8de41eba15e078e22 diff --git a/packetseer/packetseer.c b/packetseer/packetseer.c new file mode 100644 index 0000000..8ab785d --- /dev/null +++ b/packetseer/packetseer.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include "fdpass.h" +#include + +#define VSYS_PACKETSEER "/vsys/fd_packetseer.control" + +int (*socket_orig)(int f, int p, int s); + +int _init_pslib() { + socket_orig = &socket; + printf("Stored value of socket"); +} + +int socket(int f, int p, int s) +{ + if (!socket_orig) { + void *handle = dlopen("/lib/libc.so.6",RTLD_LAZY); + if (!handle) { + fprintf(stderr,"Error loading libc.so.6\n"); + return -1; + } + socket_orig = dlsym(handle, "socket"); + if (!socket_orig) { + fprintf(stderr,"Error loading socket symbol"); + return -1; + } + fprintf(stderr,"Socket call: %x",socket_orig); + } + + if (f == PF_PACKET) { + int sfd; + struct sockaddr_un addr; + int remotefd; + + sfd = socket(AF_UNIX, SOCK_STREAM, 0); + if (sfd == -1) { + perror("Could not create UNIX socket\n"); + exit(-1); + } + + memset(&addr, 0, sizeof(struct sockaddr_un)); + /* Clear structure */ + addr.sun_family = AF_UNIX; + strncpy(addr.sun_path, VSYS_PACKETSEER, + sizeof(addr.sun_path) - 1); + + if (connect(sfd, (struct sockaddr *) &addr, + sizeof(struct sockaddr_un)) == -1) { + perror("Could not connect to Vsys control socket"); + exit(-1); + } + + remotefd = receive_fd(sfd); + return remotefd; + } + else + return (*socket_orig)(f, p, s); +} +