Use libcap. It uses Berkeley packet filter
Code:
#include <pcap.h>
#include <net/if.h>
#include <netinet/in.h>
Use
pcap_lookupdev to choose the interface
Use
pcap_open_live to get a packet capture descriptor
Use
pcap_lookupnet to get network information from interface
Use
pcap_compile to transform your filter text into a BPF filter
Use
pcap_setfilter to apply the filter
Use
pcap_loop to set a function that will be called on every packet matching the filter
Compile with
-lpcap
man pcap will give you more information
The other solution would be to redo everything but I don't think its interesting to reinvent the wheel..
Have fun