Basic Work With libpcap - The main Function

#include <pcap.h>

/* for some error messages. */
char err_buf[PCAP_ERRBUF_SIZE];
int rc;

/* open the device for capturing - read first 40 bytes of each packet. */
pcap_t* pc = pcap_open_live("ppp0", 40, 0 /* not promiscuous */,
                            50 /* read timeout, in milli-seconds. */
                            err_buf);
if (!pc) {
    fprintf(stderr, "error in pcap_open_line: %s\n", err_buf);
    exit(1);
}

/* capture 10 packets. 'pcap_packet_cb' is our per-packet callback.         */
/* 'pc' will be passed to the callback, along with the packet, for context. */
rc = pcap_loop(pc, 10, pcap_packet_cb, (u_char*)pc);
if (rc == -1)
    pcap_error(pc, "pcap failed:");

/* cleanup - close the device. */
pcap_close(pc);
Originally written by Valid HTML 4.01!guy keren