Is there a way to get a list of all open sockets ( socket address or socket descriptor ) in Linux using C in user-space or kernel?
Thank you
In directory /proc/self/fd there are fake symlinks giving you all your open file descriptors - sockets give something like:
lrwx------ 1 root root 64 2009-05-08 07:45 4 -> socket:[4921]
lrwx------ 1 root root 64 2009-05-08 07:45 5 -> socket:[4918]
lrwx------ 1 root root 64 2009-05-08 07:45 6 -> socket:[5395]
Iterate them using opendir, readdir() and then interrogate them using readlink()
If you know that FD 4 is a socket, you can then call getsockname() on it to get the local address family, address etc, if bound.