Reputation: 1259
How can I get used ports and their states on Linux? Basically, everything that netstat
can do, but in C?
Upvotes: 3
Views: 1198
Reputation: 27222
Running strace on a run of netstat will show you the system calls it makes and their arguments.
$ strace netstat
...
open("/proc/net/tcp6", O_RDONLY) = 3
open("/proc/net/udp", O_RDONLY) = 3
...
This is often a good way to find out what a program is doing or the calls it makes and can sometimes be easier than looking at the source if all you need is to find out which call to look up on a man page.
Upvotes: 3
Reputation: 13914
Well, for “everything that netstat can do,” you could start with netstat
itself. The source code is here:
It should be noted that most of what netstat
does, it obtains from the /proc
filesystem; it looks like the *_do_one
routines hold most of the "interesting" guts.
Upvotes: 1