]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
wlantest: Add -N command line argument to remove write buffering
authorJouni Malinen <j@w1.fi>
Thu, 26 Nov 2015 22:10:53 +0000 (00:10 +0200)
committerJouni Malinen <j@w1.fi>
Thu, 26 Nov 2015 22:10:53 +0000 (00:10 +0200)
This makes it easier to do live parsing of captured pcap files from
wlantest without having to rename and restart the capture file. Packet
writes are flushed to disk after each packet if -N is included in the
command line.

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

index 7c3ce18fd418c63edeb77b38c3d465291ddb49c9..6c3853b058f59b80cb013a4f7392e62f419c0a4a 100644 (file)
@@ -102,6 +102,8 @@ int read_cap_file(struct wlantest *wt, const char *fname)
                                write_pcap_with_radiotap(wt, data, hdr->caplen);
                        else
                                pcap_dump(wt->write_pcap_dumper, hdr, data);
+                       if (wt->pcap_no_buffer)
+                               pcap_dump_flush(wt->write_pcap_dumper);
                }
                if (hdr->caplen < hdr->len) {
                        add_note(wt, MSG_DEBUG, "pcap: Dropped incomplete "
index ab3b2fc6b6221d8f88d948d8b9da18ef6039bc08..abe97d18fbd0103f9c4b1988a64ade3e0b7d45bd 100644 (file)
@@ -21,7 +21,7 @@ static void wlantest_terminate(int sig, void *signal_ctx)
 
 static void usage(void)
 {
-       printf("wlantest [-cddhqqFt] [-i<ifname>] [-r<pcap file>] "
+       printf("wlantest [-cddhqqFNt] [-i<ifname>] [-r<pcap file>] "
               "[-p<passphrase>]\n"
               "         [-I<wired ifname>] [-R<wired pcap file>] "
               "[-P<RADIUS shared secret>]\n"
@@ -350,7 +350,7 @@ int main(int argc, char *argv[])
        wlantest_init(&wt);
 
        for (;;) {
-               c = getopt(argc, argv, "cdf:Fhi:I:L:n:p:P:qr:R:tT:w:W:");
+               c = getopt(argc, argv, "cdf:Fhi:I:L:n:Np:P:qr:R:tT:w:W:");
                if (c < 0)
                        break;
                switch (c) {
@@ -383,6 +383,9 @@ int main(int argc, char *argv[])
                case 'n':
                        wt.pcapng_file = optarg;
                        break;
+               case 'N':
+                       wt.pcap_no_buffer = 1;
+                       break;
                case 'p':
                        add_passphrase(&wt, optarg);
                        break;
index ced9baa0e32254f2507e77b4ad493b59c18eb483..530accc3b9a764a1139904ad92c2f5be4215a621 100644 (file)
@@ -202,6 +202,7 @@ struct wlantest {
        int last_mgmt_valid;
 
        unsigned int assume_fcs:1;
+       unsigned int pcap_no_buffer:1;
 
        char *notes[MAX_NOTES];
        size_t num_notes;
index 28b306b7a1ac27e4341c4aa4b94cea840fce78d3..abd889fcd737777dc41fe7050e129036a7c2f65f 100644 (file)
@@ -59,6 +59,8 @@ void write_pcap_captured(struct wlantest *wt, const u8 *buf, size_t len)
        h.caplen = len;
        h.len = len;
        pcap_dump(wt->write_pcap_dumper, &h, buf);
+       if (wt->pcap_no_buffer)
+               pcap_dump_flush(wt->write_pcap_dumper);
 }
 
 
@@ -102,6 +104,8 @@ void write_pcap_decrypted(struct wlantest *wt, const u8 *buf1, size_t len1,
        h.caplen = len;
        h.len = len;
        pcap_dump(wt->write_pcap_dumper, &h, buf);
+       if (wt->pcap_no_buffer)
+               pcap_dump_flush(wt->write_pcap_dumper);
 }
 
 
@@ -181,6 +185,8 @@ int write_pcapng_init(struct wlantest *wt, const char *fname)
        desc.link_type = LINKTYPE_IEEE802_11_RADIO;
        desc.snap_len = 65535;
        fwrite(&desc, sizeof(desc), 1, wt->pcapng);
+       if (wt->pcap_no_buffer)
+               fflush(wt->pcapng);
 
        return 0;
 }
@@ -263,6 +269,8 @@ static void write_pcapng_decrypted(struct wlantest *wt)
        *block_len = pkt->block_total_len = pos - (u8 *) pkt;
 
        fwrite(pkt, pos - (u8 *) pkt, 1, wt->pcapng);
+       if (wt->pcap_no_buffer)
+               fflush(wt->pcapng);
 
        os_free(pkt);
 }
@@ -337,6 +345,8 @@ void write_pcapng_write_read(struct wlantest *wt, int dlt,
        *block_len = pkt->block_total_len = pos - (u8 *) pkt;
 
        fwrite(pkt, pos - (u8 *) pkt, 1, wt->pcapng);
+       if (wt->pcap_no_buffer)
+               fflush(wt->pcapng);
 
        os_free(pkt);