Sockets and the owner process
Justin Walker
justin at mac.com
Sun Feb 29 14:41:23 PST 2004
On Saturday, February 28, 2004, at 09:52 AM, grinder wrote:
> I want to create a small kernel module which logs the socket
> operations.
>
> So in my module i have a socket structure, and i want to know
> which process (thread) owns it. But the socket structure isn't
> contains any reference to the process structure. If i walk through
> the vnode table i can find my socket by the so_gencnt "unique id",
> but the vnode structure isn't have any variables back to the proc
> structure.
>
> Is it possible to get the owner proc structure for a socket?
Not really. Socket descriptors, like other file-descriptors, can be
handed off by the fork/exec process, and via local domain sockets to
unrelated processes, so by the time that the socket is actually used,
there can be no relation to the process that created it (e.g.,
inetd/xinetd creates it, waits for a connection, accepts the
connection, and then passes the descriptor to the service process via
fork/exec, and closes its version of that socket).
The best you can hope for is to determine processes that are actually
using the socket, and that can vary during the socket's lifetime. You
would have to scour the file descriptor tables in all process
structures to determine which processes had a handle on each socket you
have an interest in.
There is no real "ownership" of anything accessed via file descriptors.
Regards,
Justin
--
Justin C. Walker, Curmudgeon-At-Large *
Institute for General Semantics | It's not whether you win or
lose...
| It's whether *I* win or lose.
*--------------------------------------*-------------------------------*
More information about the freebsd-hackers
mailing list