title: Linux API to determine sockets owned by a process
body: <p>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 <code>lsof -i</code>. Ultimately, I want to correlate packets seen through <code>libpcap</code> to processes.</p>
  
  <p><strong>UPDATE:</strong> A couple of people have suggested using <code>/proc/&lt;pid&gt;/net/tcp</code> and <code>udp</code>, but on my system, the same data is shown for every process, so it doesn't help.</p>