Re: getting fd from pointer to sock

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

 



* Amit Shah (shahamit@gmx.net) wrote:
> Hi,
> 
> I wanted a mapping from the scok struct to the fd... I know the mapping from
> the task_struct to the sock... I just want the reverse.

You can't definitively do it.  You can get filp from
struct sock -> struct socket -> struct file

And the forward lookup path you can get filp from
fd -> struct task_struct -> struct files_struct -> struct file

You can compare the filp's and see which match.  However multiple fd's
can point to the same filp (as in dup(2)), so you are never guaranteed a
1:1 mapping.  At best you can tell which fd(s) -- note possibly plural --
are pointing to the socket (or file).

cheers,
-chris
-- 
Linux Security Modules     http://lsm.immunix.org     http://lsm.bkbits.net
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[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