Hi,
I am attempting to access all sockets for every process from a Linux
module. The goal being to be able to modify the socket's IP address. I
am running this module with root privileges. I am unsure how to do this
and any suggestions would be very much appreciated.
I have looked at source code from netstat and lsof. Both adopt an
approach where they sort through the /proc directory structure and
simply grep on the word 'socket' or '[12345]'. Old versions of the lsof
project used to adopt a /dev/kmem approach similar to what I suggest in
the next paragraph.
From what I learned concerning kernel structures, I can use the
for_each_task macro to access each process (task_struct). Then, I would
need to access the corresponding inode by traversing the following
structures:
struct task_struct (sched.h)
-> struct files_struct *files (sched.h)
-> struct file ** fd *//* current fd array *//* (fs.h)
-> struct dentry *f_dentry; (dcache.h)
-> struct inode * d_inode; *//* Where the name belongs to - NULL
is negative *//* (fs.h)
-> umode_t i_mode; (or unsigned char i_sock;)
And then, I can know whether the inode is a socket or not by loking at
i_mode. If it is a socket, I can access the socket structure:
struct socket socket_i;
Is this correct? Or is there a better way?
Thank you for your help,
David Gordon
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
This archive was generated by hypermail 2b29 : Fri Nov 15 2002 - 22:00:01 EST