aboutsummaryrefslogtreecommitdiffstats
path: root/wlantest/readpcap.c
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2010-11-06 14:20:45 (GMT)
committerJouni Malinen <j@w1.fi>2010-11-07 21:29:00 (GMT)
commita149fcc77d3322bf23d1f53c2cd9fc84a1097c31 (patch)
tree50869affc977d98c872265f0493fa28bb10cb0bb /wlantest/readpcap.c
parent6fc58a89e1dc41a315b15c8e067dc50f30dd741e (diff)
downloadhostap-a149fcc77d3322bf23d1f53c2cd9fc84a1097c31.zip
hostap-a149fcc77d3322bf23d1f53c2cd9fc84a1097c31.tar.gz
hostap-a149fcc77d3322bf23d1f53c2cd9fc84a1097c31.tar.bz2
wlantest: Add preliminary version of IEEE 802.11 protocol testing tool
This tool can be used to capture IEEE 802.11 frames either from a monitor interface for realtime capturing or from pcap files for offline analysis. This version is only adding basic infrastructure for going through the frames and parsing their headers.
Diffstat (limited to 'wlantest/readpcap.c')
-rw-r--r--wlantest/readpcap.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/wlantest/readpcap.c b/wlantest/readpcap.c
new file mode 100644
index 0000000..d96345c
--- /dev/null
+++ b/wlantest/readpcap.c
@@ -0,0 +1,73 @@
+/*
+ * PCAP capture file reader
+ * Copyright (c) 2010, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+#include <pcap/pcap.h>
+
+#include "utils/common.h"
+#include "wlantest.h"
+
+
+int read_cap_file(struct wlantest *wt, const char *fname)
+{
+ char errbuf[PCAP_ERRBUF_SIZE];
+ pcap_t *pcap;
+ unsigned int count = 0;
+ struct pcap_pkthdr *hdr;
+ const u_char *data;
+ int res;
+
+ pcap = pcap_open_offline(fname, errbuf);
+ if (pcap == NULL) {
+ wpa_printf(MSG_ERROR, "Failed to read pcap file '%s': %s",
+ fname, errbuf);
+ return -1;
+ }
+
+ for (;;) {
+ res = pcap_next_ex(pcap, &hdr, &data);
+ if (res == -2)
+ break; /* No more packets */
+ if (res == -1) {
+ wpa_printf(MSG_INFO, "pcap_next_ex failure: %s",
+ pcap_geterr(pcap));
+ break;
+ }
+ if (res != 1) {
+ wpa_printf(MSG_INFO, "Unexpected pcap_next_ex return "
+ "value %d", res);
+ break;
+ }
+
+ /* Packet was read without problems */
+ wpa_printf(MSG_EXCESSIVE, "pcap hdr: ts=%d.%06d "
+ "len=%u/%u",
+ (int) hdr->ts.tv_sec, (int) hdr->ts.tv_usec,
+ hdr->caplen, hdr->len);
+ if (hdr->caplen < hdr->len) {
+ wpa_printf(MSG_DEBUG, "pcap: Dropped incomplete frame "
+ "(%u/%u captured)",
+ hdr->caplen, hdr->len);
+ continue;
+ }
+ count++;
+ wlantest_process(wt, data, hdr->caplen);
+ }
+
+ pcap_close(pcap);
+
+ wpa_printf(MSG_DEBUG, "Read %s: %u packets", fname, count);
+
+ return 0;
+}