Re: Obtaining a list of open sockets from "struct task_struct"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 11 November 2011 09:42, Nuno Martins <nuno.m.g.martins@xxxxxxxxx> 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

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux