wlantest: Add -N command line argument to remove write buffering

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>
This commit is contained in:
Jouni Malinen 2015-11-27 00:10:53 +02:00
parent b25f04d44a
commit e929eb39d6
4 changed files with 18 additions and 2 deletions

View 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 "

View 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;

View 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;

View 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);