Basic Work With libpcap - The Callback Function

#include <pcap.h>

/* A callback function invoked for each captured packet. */
void pcap_packet_cb(u_char* uparam,
                    const struct pcap_pkthdr* hdr,
                    const u_char* p_data)    /* <-- the actual packet's data. */
    /* we passed this to pcap_loop() */
    pcap_t* pc = (pcap_t*)uparam;
    struct pcap_stat ps;

    /* we'll just collect packet counts for now. */
    int rc = pcap_stats(pc, &ps);
    if (rc == -1)
        pcap_perror(pc, "");
        printf("packets captured: %u, packets dropped: %u\n",
               ps.ps_recv, ps.ps_drop);
Originally written by Valid HTML 4.01!guy keren