Obtaining a list of open sockets from "struct task_struct"

Vimal j.vimal at gmail.com
Sat Nov 12 22:20:42 EST 2011


Hi,

On 11 November 2011 09:42, Nuno Martins <nuno.m.g.martins at gmail.com> wrote:
> If you are sure that that file descriptor is a socket then you can
> cast to struct socket, the field "void * private_data"  in struct file
> [1] .

Thanks!   That helped.

>
> But not all file descriptors are sockets so you have a way to be sure
> that you are dealing with a socket, you have a macro
>
> #define S_ISSOCK(m)     (((m) & S_IFMT) == S_IFSOCK)
>
> that macro is in [2] .

That's an explicit way.   But can instead of looking up this from the
inode information, I think you can also deduce whether the file
pointer is a socket by checking if "file.f_op == &socket_file_ops".
:)


>
> Glad to help, i have searched all that because i had a project that i
> needed to know which file descriptors were sockets, so i had to search
> this information, i hope it's now a little be clear to you.
>


Yes, it's much clear now.  Thanks a lot!

-- 
Vimal



More information about the Kernelnewbies mailing list