View Full Version : how to override a linux function

06-18-2004, 02:46 PM
what i wan't to do is to perform some code of my own before a new tcp connection is opened in my linux box.

so waht i want to know is if there is any way that i can design a function and have it run for example, whenever a connect command is issue by any program in the system...

i hope i explained myself well


06-18-2004, 05:00 PM
Well I suppose you could recreate the shared libraries to do whatever you wanted to, then any application which used those shared libraries would also run your code.

As for anything which is statically linked, then your only choice is to rebuild those applications.

06-18-2004, 06:42 PM
If the shared libraries call a system call, you are going ot make a module that alters that sysltem call. For more information on altering system calls, you might want to look here
there is something in there in how they change what the open() system calls.
An example is here

06-20-2004, 06:07 AM
that second page you left was pretyt interesting but i the first module (hello-1.c) a simple hello world, compiles I can't insert it into the kernel, it complains that it couldn't find the kernel version the module was compiled for.... do you know whats the problem?

06-20-2004, 06:12 AM
i read the first chapters and it says my problem might be that my kernel is compiled with modversioning turned on, so i have to turn it off... boring... i'll try this

06-20-2004, 10:08 AM
What kernel version are you using, if you are using 2.6, you have to compile the driver differently. Here is an article explaining the differences in the 2.4 and 2.6 kernels: http://linuxdevices.com/articles/AT4389927951.html.

06-21-2004, 06:58 AM
actualy i'm using a 2.4 kernel

Linux asdsad.asdasd 2.4.20-8 #1 Thu Mar 13 17:18:24 EST 2003 i686 atlhon GNU/Linux

06-21-2004, 05:30 PM
check that you are including the kernel header files for the current build of your kernel. They should be here:
/lib/modules/uname -r/build/
Where uname -r is what the command uname passed with the parameter -r to it prints.