CyberPsychotic wrote:
>
> I am trying to write a library, which shall be loaded via LD_PRELOAD and
> replace several original libc functions. (for example, I want to have my
> fopen function, which would make some additional checks/logs).
>
> Now the problem is how would I call the original routine within my
> library?
#include <dlfcn.h> // dlsym
// Pointers to the original libc functions. Initialized in _init().
static int (*org_setsockopt)(int s, int level, int optname, const void *optval, int
optlen);
// Setup everything, or exit() if an error occurs.
int _init( void )
{
// find the address of the original libc function.
org_setsockopt = dlsym( RTLD_NEXT, "setsockopt" );
if ( !org_setsockopt )
fatalerr( "Original 'setsockopt()' not found.\n" );
return 0;
}
int setsockopt( int s, int level, int optname, const void *optval, int optlen )
{
{ ...your code... }
return org_setsockopt( s, level, optname, optval, optlen );
}