2 * PCAP capture file reader
3 * Copyright (c) 2010, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
15 #include "utils/includes.h"
16 #include <pcap/pcap.h>
18 #include "utils/common.h"
22 int read_cap_file(struct wlantest *wt, const char *fname)
24 char errbuf[PCAP_ERRBUF_SIZE];
26 unsigned int count = 0;
27 struct pcap_pkthdr *hdr;
31 pcap = pcap_open_offline(fname, errbuf);
33 wpa_printf(MSG_ERROR, "Failed to read pcap file '%s': %s",
39 res = pcap_next_ex(pcap, &hdr, &data);
41 break; /* No more packets */
43 wpa_printf(MSG_INFO, "pcap_next_ex failure: %s",
48 wpa_printf(MSG_INFO, "Unexpected pcap_next_ex return "
53 /* Packet was read without problems */
54 wpa_printf(MSG_EXCESSIVE, "pcap hdr: ts=%d.%06d "
56 (int) hdr->ts.tv_sec, (int) hdr->ts.tv_usec,
57 hdr->caplen, hdr->len);
58 if (hdr->caplen < hdr->len) {
59 wpa_printf(MSG_DEBUG, "pcap: Dropped incomplete frame "
61 hdr->caplen, hdr->len);
65 wlantest_process(wt, data, hdr->caplen);
70 wpa_printf(MSG_DEBUG, "Read %s: %u packets", fname, count);