Function Interposition in Linux

Hello,

Please I try to apply the mechanism Interposition Function in Linux on the function write (write a socket) as follows:

# include <sys/types.h>
# include <sys/socket.h>
# include <netinet/in.h>
# include <arpa/inet.h>
# include <netdb.h>
# include <stdio.h>
# include <string.h>
int write (int n, char buffer [32], int sb)
{

int nb = write (so, "Ceci est un exemple de socket!!!", 32);
}

I also have the server code and client code, when the client connects to the server, the server sends a message to the client but when running I got the following error:

Erreur de segmentation
Have you an idea please ?

Thank you so much

write is a system call, and you have write as a local function name. At best this becomes a never-ending recursive call.

Call your function mywrite() or something else, do not name your functions the same thing as syscalls, -read write open and so on.

Interposition is acheived by writing a shared library module (call it mylibrary.so as an example), compling it, then creating a special environment variable, LD_PRELOAD=mylibrary.so, and then running your code. But you still cannot do what your code shows.

--> i have done all what you say , i have modified the code like that:

I have a question please :how canget the buffer "const void *buf" because I want to change it before sending ?

Thank you so much for help