aboutsummaryrefslogtreecommitdiffstats
path: root/wlantest/readpcap.c
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2010-11-07 15:59:50 (GMT)
committerJouni Malinen <j@w1.fi>2010-11-07 21:29:02 (GMT)
commit3215df77eeaf4fee01d03b1a164b1329cfdcfb52 (patch)
tree2dedfedacae216eac162822702e987c33f8cf44f /wlantest/readpcap.c
parent4bc82fc7ae6294c4b1ca6dc537adbd25301f793f (diff)
downloadhostap-3215df77eeaf4fee01d03b1a164b1329cfdcfb52.zip
hostap-3215df77eeaf4fee01d03b1a164b1329cfdcfb52.tar.gz
hostap-3215df77eeaf4fee01d03b1a164b1329cfdcfb52.tar.bz2
wlantest: Add capturing and parsing of RADIUS messages
Another interface (-I) or pcap file (-R) can now be specified as a source of RADIUS packets. These packets are now parsed, but the MSK is not yet derived for PMK use.
Diffstat (limited to 'wlantest/readpcap.c')
-rw-r--r--wlantest/readpcap.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/wlantest/readpcap.c b/wlantest/readpcap.c
index d96345c..dfb7ac0 100644
--- a/wlantest/readpcap.c
+++ b/wlantest/readpcap.c
@@ -71,3 +71,57 @@ int read_cap_file(struct wlantest *wt, const char *fname)
return 0;
}
+
+
+int read_wired_cap_file(struct wlantest *wt, const char *fname)
+{
+ char errbuf[PCAP_ERRBUF_SIZE];
+ pcap_t *pcap;
+ unsigned int count = 0;
+ struct pcap_pkthdr *hdr;
+ const u_char *data;
+ int res;
+
+ pcap = pcap_open_offline(fname, errbuf);
+ if (pcap == NULL) {
+ wpa_printf(MSG_ERROR, "Failed to read pcap file '%s': %s",
+ fname, errbuf);
+ return -1;
+ }
+
+ for (;;) {
+ res = pcap_next_ex(pcap, &hdr, &data);
+ if (res == -2)
+ break; /* No more packets */
+ if (res == -1) {
+ wpa_printf(MSG_INFO, "pcap_next_ex failure: %s",
+ pcap_geterr(pcap));
+ break;
+ }
+ if (res != 1) {
+ wpa_printf(MSG_INFO, "Unexpected pcap_next_ex return "
+ "value %d", res);
+ break;
+ }
+
+ /* Packet was read without problems */
+ wpa_printf(MSG_EXCESSIVE, "pcap hdr: ts=%d.%06d "
+ "len=%u/%u",
+ (int) hdr->ts.tv_sec, (int) hdr->ts.tv_usec,
+ hdr->caplen, hdr->len);
+ if (hdr->caplen < hdr->len) {
+ wpa_printf(MSG_DEBUG, "pcap: Dropped incomplete frame "
+ "(%u/%u captured)",
+ hdr->caplen, hdr->len);
+ continue;
+ }
+ count++;
+ wlantest_process_wired(wt, data, hdr->caplen);
+ }
+
+ pcap_close(pcap);
+
+ wpa_printf(MSG_DEBUG, "Read %s: %u packets", fname, count);
+
+ return 0;
+}