you can go to winpcap site and take a look at several sample codes...

or download wireshark source code and try to understand the whole working application