Basic Work With libpcap - Printing The Raw Data

#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. */
{
    int i;
    static int packet_count = 0;

    /* increase the packet's counter. */
    packet_count++;

    /* lets dump the packet's data on screen.            */
    /* we print as many bytes as were actually captured. */
    printf("PACKET %d:\n", packet_count);
    for (i = 0; i < hdr->caplen; ++i) {
        printf(" 0x%x", *(p_data+i));
    }
    printf("\n\n");
}
Originally written by Valid HTML 4.01!guy keren