C – Gets the port and status used

Gets the port and status used… here is a solution to the problem.

Gets the port and status used

How do I get the used ports and their status on Linux? Basically, netstat can do everything, but in C?

Solution

Running strace running netstat will show you the system calls it makes and their parameters.

$ strace netstat
...
open("/proc/net/tcp6", O_RDONLY)        = 3
open("/proc/net/udp", O_RDONLY)         = 3
...

This is often a good way to know what the program is doing or calling, and if you only need to find which call on the man page, it’s sometimes easier than looking at the source code.

Related Problems and Solutions