aboutsummaryrefslogtreecommitdiffstats
path: root/wlantest/wlantest.c
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2013-05-26 16:39:48 (GMT)
committerJouni Malinen <j@w1.fi>2013-05-26 17:58:42 (GMT)
commitba2beacc974c2ab9576e86707a0d3ccfb5f93c1b (patch)
treeae67dcd4d96be224105241cf15f08c987f559b85 /wlantest/wlantest.c
parenteb4737f6df53079ded33825323fb3217bd625f57 (diff)
downloadhostap-ba2beacc974c2ab9576e86707a0d3ccfb5f93c1b.zip
hostap-ba2beacc974c2ab9576e86707a0d3ccfb5f93c1b.tar.gz
hostap-ba2beacc974c2ab9576e86707a0d3ccfb5f93c1b.tar.bz2
wlantest: Add support for writing pcapng files
The new -n<file> command line argument can be used to request wlantest to write all read or captured frames into a pcapng file. This is similar to the -w argument, but with pcapng allowing per-frame comments to be embedded in the file. Signed-hostap: Jouni Malinen <j@w1.fi>
Diffstat (limited to 'wlantest/wlantest.c')
-rw-r--r--wlantest/wlantest.c70
1 files changed, 67 insertions, 3 deletions
diff --git a/wlantest/wlantest.c b/wlantest/wlantest.c
index 9856d6b..5b691fa 100644
--- a/wlantest/wlantest.c
+++ b/wlantest/wlantest.c
@@ -27,9 +27,10 @@ static void usage(void)
{
printf("wlantest [-cddhqqF] [-i<ifname>] [-r<pcap file>] "
"[-p<passphrase>]\n"
- " [-I<wired ifname>] [-R<wired pcap file>] "
+ " [-I<wired ifname>] [-R<wired pcap file>] "
"[-P<RADIUS shared secret>]\n"
- " [-w<write pcap file>] [-f<MSK/PMK file>]\n");
+ " [-n<write pcapng file>]\n"
+ " [-w<write pcap file>] [-f<MSK/PMK file>]\n");
}
@@ -97,6 +98,10 @@ static void wlantest_deinit(struct wlantest *wt)
dl_list_for_each_safe(wep, nw, &wt->wep, struct wlantest_wep, list)
os_free(wep);
write_pcap_deinit(wt);
+ write_pcapng_deinit(wt);
+ clear_notes(wt);
+ os_free(wt->decrypted);
+ wt->decrypted = NULL;
}
@@ -188,6 +193,58 @@ int add_wep(struct wlantest *wt, const char *key)
}
+void add_note(struct wlantest *wt, int level, const char *fmt, ...)
+{
+ va_list ap;
+ size_t len = 1000;
+ int wlen;
+
+ if (wt->num_notes == MAX_NOTES)
+ return;
+
+ wt->notes[wt->num_notes] = os_malloc(len);
+ if (wt->notes[wt->num_notes] == NULL)
+ return;
+ va_start(ap, fmt);
+ wlen = vsnprintf(wt->notes[wt->num_notes], len, fmt, ap);
+ va_end(ap);
+ if (wlen < 0) {
+ os_free(wt->notes[wt->num_notes]);
+ wt->notes[wt->num_notes] = NULL;
+ return;
+ }
+ if (wlen >= len)
+ wt->notes[wt->num_notes][len - 1] = '\0';
+ wpa_printf(level, "%s", wt->notes[wt->num_notes]);
+ wt->num_notes++;
+}
+
+
+void clear_notes(struct wlantest *wt)
+{
+ size_t i;
+
+ for (i = 0; i < wt->num_notes; i++) {
+ os_free(wt->notes[i]);
+ wt->notes[i] = NULL;
+ }
+
+ wt->num_notes = 0;
+}
+
+
+size_t notes_len(struct wlantest *wt, size_t hdrlen)
+{
+ size_t i;
+ size_t len = wt->num_notes * hdrlen;
+
+ for (i = 0; i < wt->num_notes; i++)
+ len += os_strlen(wt->notes[i]);
+
+ return len;
+}
+
+
int main(int argc, char *argv[])
{
int c;
@@ -196,6 +253,7 @@ int main(int argc, char *argv[])
const char *write_file = NULL;
const char *ifname = NULL;
const char *ifname_wired = NULL;
+ const char *pcapng_file = NULL;
struct wlantest wt;
int ctrl_iface = 0;
@@ -208,7 +266,7 @@ int main(int argc, char *argv[])
wlantest_init(&wt);
for (;;) {
- c = getopt(argc, argv, "cdf:Fhi:I:p:P:qr:R:w:W:");
+ c = getopt(argc, argv, "cdf:Fhi:I:n:p:P:qr:R:w:W:");
if (c < 0)
break;
switch (c) {
@@ -235,6 +293,9 @@ int main(int argc, char *argv[])
case 'I':
ifname_wired = optarg;
break;
+ case 'n':
+ pcapng_file = optarg;
+ break;
case 'p':
add_passphrase(&wt, optarg);
break;
@@ -275,6 +336,9 @@ int main(int argc, char *argv[])
if (write_file && write_pcap_init(&wt, write_file) < 0)
return -1;
+ if (pcapng_file && write_pcapng_init(&wt, pcapng_file) < 0)
+ return -1;
+
if (read_wired_file && read_wired_cap_file(&wt, read_wired_file) < 0)
return -1;