For monitoring network connections there is always the ss command (socket statistics), which is a part of the iproute2 package. Faster than netstat. Simple to use. It gets all of its information directly from the kernel.
By using ss in a script you should be able to get a list of all open network connections and then filter them by using some of the ss commands options in combination with standard unix tools (grep, ag, sed, awk, less, more etc). That should allow you filter out any connections that you aren't interested in seeing.
That would probably be the simplest solution.
There is a tutorial on the ss command here:
As for writing a program to monitor network connections in C - I haven't dealt with any networking related code in the last 10 years, so I'm more than a little rusty with it. So I'm not sure what to suggest offhand!