Is there a Linux library that will enable me to tell what IP sockets are owned by what processes? I guess I'm looking for the programmatic equivalent of lsof -i
. Ultimately, I want to correlate packets seen through libpcap
to processes.
UPDATE: A couple of people have suggested using /proc/<pid>/net/tcp
and udp
, but on my system, the same data is shown for every process, so it doesn't help.
To determine sockets owned by a process you can just use
netstat
. Here's an example w/output (shortened) ofnetstat
with options that will do what you want.Make sure you run netstat as root otherwise you'll get this message:
An explanation of the
-apeen
options from the netstat manpage: