[complement-svn] SF.net SVN: complement: [1532] trunk/complement/explore/inquiry/shades/ juniper/st
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-02-21 17:57:08
|
Revision: 1532 http://svn.sourceforge.net/complement/?rev=1532&view=rev Author: complement Date: 2007-02-21 09:57:04 -0800 (Wed, 21 Feb 2007) Log Message: ----------- more funcs Modified Paths: -------------- trunk/complement/explore/inquiry/shades/juniper/str_interposer.c Modified: trunk/complement/explore/inquiry/shades/juniper/str_interposer.c =================================================================== --- trunk/complement/explore/inquiry/shades/juniper/str_interposer.c 2007-02-21 13:03:16 UTC (rev 1531) +++ trunk/complement/explore/inquiry/shades/juniper/str_interposer.c 2007-02-21 17:57:04 UTC (rev 1532) @@ -2,18 +2,19 @@ * */ -/* Example of a library interposer: interpose on - * malloc(). - * Build and use this interposer as following: - * cc -o malloc_interposer.so -G -Kpic malloc_interposer.c - * setenv LD_PRELOAD $cwd/malloc_interposer.so +/* library interposer: interpose on + * str...(). + * export LD_PRELOAD=$cwd/libtest.so.0.0 * run the app - * unsetenv LD_PRELOAD + * unset LD_PRELOAD */ #include <stdio.h> #include <dlfcn.h> +#include <sys/socket.h> +#include <netinet/in.h> + #if 0 void *malloc(size_t size) { @@ -30,7 +31,7 @@ { static void * (*func)(); - if(!func) + if (!func) func = (void *(*)()) dlsym(RTLD_NEXT, "strcpy"); printf( "strcpy: '%s'\n", s2 ); @@ -42,7 +43,7 @@ { static void * (*func)(); - if(!func) + if (!func) func = (void *(*)()) dlsym(RTLD_NEXT, "strdup"); printf( "strdup: '%s'\n", s1 ); @@ -55,7 +56,7 @@ static void * (*func)(); char *r; - if(!func) + if (!func) func = (void *(*)()) dlsym(RTLD_NEXT, "strncat"); r = func( s1, s2, n ); @@ -68,7 +69,7 @@ { static void * (*func)(); - if(!func) + if (!func) func = (void *(*)()) dlsym(RTLD_NEXT, "strtok"); printf( "strtok: '%s'\n", s1 ); @@ -76,3 +77,50 @@ return func( s1, s2 ); } +ssize_t sendto(int socket, const void *message, size_t length, int flags, const struct sockaddr *dest_addr, socklen_t dest_len) +{ + static ssize_t (*func)(); + int i; + + if (!func) + func = (ssize_t (*)()) dlsym(RTLD_NEXT, "sendto"); + + printf( "sendto: (%d) '", length ); + for ( i = 0; i < length; ++i ) { + printf( "%c", (const char *)message + i ); + } + printf( "'\n" ); + return func( socket, message, length, flags, dest_addr, dest_len ); +} + +ssize_t recvfrom(int socket, void *buffer, size_t length, int flags, struct sockaddr *address, socklen_t *address_len) +{ + static ssize_t (*func)(); + int i; + ssize_t s; + + if (!func) + func = (ssize_t (*)()) dlsym(RTLD_NEXT, "recvfrom"); + + s = func( socket, buffer, length, flags, address, address_len ); + printf( "recvfrom: (%d) '", length ); + for ( i = 0; i < length; ++i ) { + printf( "%c", (const char *)buffer + i ); + } + printf( "'\n" ); + return s; +} + +int connect(int socket, const struct sockaddr *address, socklen_t address_len) +{ + static int (*func)(); + + if (!func) + func = (int (*)()) dlsym(RTLD_NEXT, "connect"); + + printf( "connect: " ); + printf( "%x", *(((unsigned *)&((struct sockaddr_in *)address)->sin_addr)) ); + printf( ":%d\n", ntohs(((struct sockaddr_in *)address)->sin_port) ); + + return func( socket, address, address_len ); +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |