Is there any way to get all opened sockets using c++? I know the lsof
command and this is what I'm looking for, but how to use it in a c++ application?
The idea is to get the FD of an opened socket by its port
number and the pid
.
Just open the files in /proc/net, like /proc/net/tcp, /proc/net/udp, etc. No need to slog through the lsof sources. :)