What direction should I go in(libraries, documents)?
UPDATE
Can someone illustrate how to use winpcap to do the job?
You may want to look at the source code of tcpdump to see how it works. tcpdump is a Linux command-line utility that monitors and prints network activity. You need root access to the machine to use it, though.
tcpdump