]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
wlantest: Ethernet interface capture
authorJouni Malinen <j@w1.fi>
Fri, 27 Dec 2019 21:15:14 +0000 (23:15 +0200)
committerJouni Malinen <j@w1.fi>
Fri, 27 Dec 2019 21:16:45 +0000 (23:16 +0200)
Allow option (command line argument -e) to capture Ethernet headers
instead of IEEE 802.11 so that wlantest can be used as a replacement for
tcpdump/dumpcap for capturing.

Signed-off-by: Jouni Malinen <j@w1.fi>
wlantest/process.c
wlantest/wlantest.c
wlantest/wlantest.h
wlantest/writepcap.c

index c496e0d5a911ecf5bdb566303256576238cef069..4d174bada947c5402f7ce720d283b89a6e899984 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Received frame processing
- * Copyright (c) 2010, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2010-2019, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -278,6 +278,9 @@ void wlantest_process(struct wlantest *wt, const u8 *data, size_t len)
        const u8 *frame, *fcspos;
        size_t frame_len;
 
+       if (wt->ethernet)
+               return;
+
        wpa_hexdump(MSG_EXCESSIVE, "Process data", data, len);
 
        if (ieee80211_radiotap_iterator_init(&iter, (void *) data, len, NULL)) {
index e46850aef2c2f96ea28d5e21e97bd1ca2351bb63..1b8d7147edbdb4d0286c3b0730ee4f098d7b32f2 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * wlantest - IEEE 802.11 protocol monitoring and testing tool
- * Copyright (c) 2010-2015, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2010-2019, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -21,7 +21,7 @@ static void wlantest_terminate(int sig, void *signal_ctx)
 
 static void usage(void)
 {
-       printf("wlantest [-cddhqqFNt] [-i<ifname>] [-r<pcap file>] "
+       printf("wlantest [-cddehqqFNt] [-i<ifname>] [-r<pcap file>] "
               "[-p<passphrase>]\n"
               "         [-I<wired ifname>] [-R<wired pcap file>] "
               "[-P<RADIUS shared secret>]\n"
@@ -367,7 +367,7 @@ int main(int argc, char *argv[])
        wlantest_init(&wt);
 
        for (;;) {
-               c = getopt(argc, argv, "cdf:Fhi:I:L:n:Np:P:qr:R:tT:w:W:");
+               c = getopt(argc, argv, "cdef:Fhi:I:L:n:Np:P:qr:R:tT:w:W:");
                if (c < 0)
                        break;
                switch (c) {
@@ -378,6 +378,9 @@ int main(int argc, char *argv[])
                        if (wpa_debug_level > 0)
                                wpa_debug_level--;
                        break;
+               case 'e':
+                       wt.ethernet = 1;
+                       break;
                case 'f':
                        if (add_pmk_file(&wt, optarg) < 0)
                                return -1;
index 9324aa9d5322431f6744cfca5cedc198ea5663f6..4f90b20e2a8f9985d71d4b3ccd33a29edddacab5 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * wlantest - IEEE 802.11 protocol monitoring and testing tool
- * Copyright (c) 2010-2013, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2010-2019, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -208,6 +208,7 @@ struct wlantest {
 
        unsigned int assume_fcs:1;
        unsigned int pcap_no_buffer:1;
+       unsigned int ethernet:1;
 
        char *notes[MAX_NOTES];
        size_t num_notes;
index abd889fcd737777dc41fe7050e129036a7c2f65f..fee2c40dc4787586fa26ef78543d4041fb918713 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * PCAP capture file writer
- * Copyright (c) 2010, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2010-2019, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -17,7 +17,9 @@
 
 int write_pcap_init(struct wlantest *wt, const char *fname)
 {
-       wt->write_pcap = pcap_open_dead(DLT_IEEE802_11_RADIO, 4000);
+       int linktype = wt->ethernet ? DLT_EN10MB : DLT_IEEE802_11_RADIO;
+
+       wt->write_pcap = pcap_open_dead(linktype, 4000);
        if (wt->write_pcap == NULL)
                return -1;
        wt->write_pcap_dumper = pcap_dump_open(wt->write_pcap, fname);
@@ -182,7 +184,7 @@ int write_pcapng_init(struct wlantest *wt, const char *fname)
        desc.block_type = PCAPNG_BLOCK_IFACE_DESC;
        desc.block_total_len = sizeof(desc);
        desc.block_total_len2 = desc.block_total_len;
-       desc.link_type = LINKTYPE_IEEE802_11_RADIO;
+       desc.link_type = wt->ethernet ? DLT_EN10MB : LINKTYPE_IEEE802_11_RADIO;
        desc.snap_len = 65535;
        fwrite(&desc, sizeof(desc), 1, wt->pcapng);
        if (wt->pcap_no_buffer)
@@ -317,6 +319,7 @@ void write_pcapng_write_read(struct wlantest *wt, int dlt,
        pos = (u8 *) (pkt + 1);
 
        switch (dlt) {
+       case DLT_EN10MB:
        case DLT_IEEE802_11_RADIO:
                break;
        case DLT_PRISM_HEADER:
@@ -365,5 +368,6 @@ void write_pcapng_captured(struct wlantest *wt, const u8 *buf, size_t len)
        gettimeofday(&h.ts, NULL);
        h.caplen = len;
        h.len = len;
-       write_pcapng_write_read(wt, DLT_IEEE802_11_RADIO, &h, buf);
+       write_pcapng_write_read(wt, wt->ethernet ? DLT_EN10MB :
+                               DLT_IEEE802_11_RADIO, &h, buf);
 }