I have a user space application that creates several raw sockets (of AF_INET & AF_PACKET families with different protocols). To aid in debugging, I need to programmatically display details of these sockets (e.g. the number of bytes/packets queued at these sockets).
I tried using the FIONREAD ioctl, and recv with MSG_PEEK flag, but both these give me only the number of bytes of the first packet queued in a socket.
So it appears that I need to read the "/proc/PID/net/raw" file to get the details I need. Q1: is there a better way?
The Linux kernel only adds sockets of the AF_INET family to its raw sockets hash table, but not sockets of the AF_PACKET family. As a result, only sockets of the AF_INET family are listed in the "/proc/PID/net/raw" file. Q2: is there any way to get details of sockets of the AF_PACKET family?
By reading the "/proc/PID/net/raw" file, I can get the number of bytes in the kernel's send & receive queues. Q3: Can I somehow get the number of packets queued?
Any help would be highly appreciated.
p.s: my program is in C, but I'll be happy to look at snippets of code in other languages as well.