My goal is to track sockets and associate them with the applications that created them.I know netstat, ss, lsof etc. And that they can list all the sockets with their application.And I also know that I can parse /proc/net/tcp to get sockets and associate them with applications with /proc/(PID) , which is exactly what these tools do, or they use netlink sockets.
/proc/net/tcp
/proc/(PID)
My research led me to an article that explains how to get all sockets from the kernel using netlink via the inet_diag protocol. The user space program installs a netlink socket of type inet_diag and sends the request to the kernel. The response consists of several messages containing sockets and additional relevant information. This is really neat, but, unfortunately, the kernel sends this information only once per request. Therefore, I must constantly โinterrogateโ.
Further research led me to another article which constantly monitors IP interface changes using netlink network routes. A socket is bound to a multicast group, and then messages are read from it in an endless loop.
So, I investigated if there is such a possibility with inet_diag sockets. Unfortunately, I cannot understand the kernel code. But as far as I can tell, there are no multicast groups for this socket family.
At this moment I am stuck and I need to know how much this is possible, or someone knows any other hints.
You can try dtrace if all the tools you mentioned cannot satisfy your requirements.
dtrace
Source: https://habr.com/ru/post/1499873/More articles:sdk request: how to get all headers? - firefoxSemi-automatic argumentation for R functions - validationUse WinPython distribution in Eclipse + Pydev? - pythonAnimation without jquery, slide left and right - javascriptmoving li from one ul to another jQuery - javascriptHow to check if type is mpl :: apply-able? - c ++How do you compress a directory in Squeak Smalltalk? - smalltalkUnderstanding the in keyword in Javascript - javascriptUnfoldable instance for cofree comonad - haskellThe smartest way to initialize an array in CoffeeScript - syntaxAll Articles