I don't know if there is a library to do this. May very well be. If you don't find one, here's how you could do it yourself in a program:
* read /proc/net/tcp (or udp) and look at the last column of the line concerning the port you want to check (the one that says inode)
* check every /proc/<pid>/fd directory for symlinks pointing to "socket:[<inode>]" where <inode> is this number
I'm not sure if there is an alternative to iterating over all those directories...
Good luck finding a library!