login
Header Space

 
 

kernel module to intercept socket creation

November 19, 2008 - 6:00pm
Submitted by Anonymous on November 19, 2008 - 6:00pm.
Linux

Dear All,

I am trying to create a module that will intercept all socket creation (locally) and will print (or log) the process id of the process that created the socket.
Any ideas how to do the linking between the socket system call and the process id of the process that created it ?

Thanks to all

sock_register()

November 19, 2008 - 6:55pm

Hi,

Use sock_register() in your module_init function to register a socket family (or I guess in your case multiple socket families).

As a parameter you will need to pass in a pointer to a code>struct net_proto_family

. When you define this struct you will specify the .create handler, which will be called everytime a user opens a socket of the socket family in question.

As for how to get the pid, I am not exactly sure. I needed to do the same thing, but ended up having the process actually pass in its process id (inside sk_protinfo). If you find a way, please share :).

Cheers,
ib

Zdrasti :) Isn't getting the

November 20, 2008 - 6:19am
gat3way (not verified)

Zdrasti :)

Isn't getting the current->pid in that case safe?

hi

November 26, 2008 - 10:13am

hi,

its a good idea to do that, could you plz let me know more about teh thoughts and idea as i am new to it.

i appreciate your help and response in advance.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
speck-geostationary