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 (wt->write_pcap_dumper) {
59 wt->write_pcap_time = hdr->ts;
60 pcap_dump(wt->write_pcap_dumper, hdr, data);
62 if (hdr->caplen < hdr->len) {
63 wpa_printf(MSG_DEBUG, "pcap: Dropped incomplete frame "
65 hdr->caplen, hdr->len);
69 wlantest_process(wt, data, hdr->caplen);
74 wpa_printf(MSG_DEBUG, "Read %s: %u packets", fname, count);
80 int read_wired_cap_file(struct wlantest *wt, const char *fname)
82 char errbuf[PCAP_ERRBUF_SIZE];
84 unsigned int count = 0;
85 struct pcap_pkthdr *hdr;
89 pcap = pcap_open_offline(fname, errbuf);
91 wpa_printf(MSG_ERROR, "Failed to read pcap file '%s': %s",
97 res = pcap_next_ex(pcap, &hdr, &data);
99 break; /* No more packets */
101 wpa_printf(MSG_INFO, "pcap_next_ex failure: %s",
106 wpa_printf(MSG_INFO, "Unexpected pcap_next_ex return "
111 /* Packet was read without problems */
112 wpa_printf(MSG_EXCESSIVE, "pcap hdr: ts=%d.%06d "
114 (int) hdr->ts.tv_sec, (int) hdr->ts.tv_usec,
115 hdr->caplen, hdr->len);
116 if (hdr->caplen < hdr->len) {
117 wpa_printf(MSG_DEBUG, "pcap: Dropped incomplete frame "
119 hdr->caplen, hdr->len);
123 wlantest_process_wired(wt, data, hdr->caplen);
128 wpa_printf(MSG_DEBUG, "Read %s: %u packets", fname, count);