How can I get used ports and their states on Linux? Basically, everything that `netstat` can do, but in C?