#include <unistd.h>
#include <pcap/pcap.h>
#include "packet_priv.h"
static void packet_handler(u_char *user, const struct pcap_pkthdr *h, const u_char *bytes)
{
struct packet pkt;
packet_parse(&pkt, (const char *)bytes, h->caplen);
packet_print_table(&pkt);
}
static void usage(char *cmd)
printf("Usage: %s\n", cmd);
printf("Options:\n");
printf(" -f <pcap file> pcap file\n");
printf(" -h print help\n");
printf("\n");
int main(int argc, char **argv)
int opt = 0;
char *file = NULL;
while ((opt = getopt(argc, argv, "f:h")) != -1)
switch (opt)
case 'f':
file = optarg;
break;
case 'h':
usage(argv[0]);
return 0;
default:
return -1;
if (file == NULL)
pcap_t *pcap = pcap_open_offline(file, NULL);
if (pcap == NULL)
printf("pcap_open_offline() failed\n");
pcap_loop(pcap, -1, packet_handler, NULL);
pcap_close(pcap);