Thread: how to override a linux function

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    10

    how to override a linux function

    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


    thank's

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    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
    http://www.xml.com/ldd/chapter/book/
    there is something in there in how they change what the open() system calls.
    An example is here
    http://tldp.org/LDP/lkmpg/x931.html
    Last edited by chrismiceli; 06-19-2004 at 06:21 PM.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  4. #4
    Registered User
    Join Date
    Jun 2004
    Posts
    10
    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?

  5. #5
    Registered User
    Join Date
    Jun 2004
    Posts
    10
    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

  6. #6
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    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.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  7. #7
    Registered User
    Join Date
    Jun 2004
    Posts
    10
    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

  8. #8
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    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.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to override a function in binary from outside?
    By abhishekchauhan in forum C++ Programming
    Replies: 2
    Last Post: 01-29-2009, 11:14 AM
  2. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM