From 605034240e0cb94d134c8deb90aec9eef3e43839 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Tue, 8 Aug 2023 11:00:42 +0300 Subject: [PATCH] wlantest: Support multiple input files Allow the -r command line argument to be used multiple times to read more than a single capture file for processing. This reduces need for external tools to be used first to merge capture files for wlantest. Signed-off-by: Jouni Malinen --- wlantest/wlantest.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/wlantest/wlantest.c b/wlantest/wlantest.c index fd6dc2024..b84b4c36b 100644 --- a/wlantest/wlantest.c +++ b/wlantest/wlantest.c @@ -372,7 +372,9 @@ int wlantest_relog(struct wlantest *wt) int main(int argc, char *argv[]) { int c, ret = 0; - const char *read_file = NULL; + const unsigned int MAX_READ_FILE = 20; + const char *read_file[MAX_READ_FILE]; + unsigned int rf, num_read_file = 0; const char *read_wired_file = NULL; const char *ifname = NULL; const char *ifname_wired = NULL; @@ -442,7 +444,13 @@ int main(int argc, char *argv[]) wpa_debug_level++; break; case 'r': - read_file = optarg; + if (num_read_file == MAX_READ_FILE) { + wpa_printf(MSG_INFO, + "Too many read files (-r) - ignored %s", + optarg); + break; + } + read_file[num_read_file++] = optarg; break; case 'R': read_wired_file = optarg; @@ -473,7 +481,7 @@ int main(int argc, char *argv[]) } if (ifname == NULL && ifname_wired == NULL && - read_file == NULL && read_wired_file == NULL) { + num_read_file == 0 && read_wired_file == NULL) { usage(); ret = 0; goto deinit; @@ -491,9 +499,20 @@ int main(int argc, char *argv[]) if ((wt.write_file && write_pcap_init(&wt, wt.write_file) < 0) || (wt.pcapng_file && write_pcapng_init(&wt, wt.pcapng_file) < 0) || (read_wired_file && - read_wired_cap_file(&wt, read_wired_file) < 0) || - (read_file && read_cap_file(&wt, read_file) < 0) || - (ifname && monitor_init(&wt, ifname) < 0) || + read_wired_cap_file(&wt, read_wired_file) < 0)) + { + ret = -1; + goto deinit; + } + + for (rf = 0; rf < num_read_file; rf++) { + if (read_cap_file(&wt, read_file[rf]) < 0) { + ret = -1; + goto deinit; + } + } + + if ((ifname && monitor_init(&wt, ifname) < 0) || (ifname_wired && monitor_init_wired(&wt, ifname_wired) < 0) || (ctrl_iface && ctrl_init(&wt) < 0)) { ret = -1;