diff options
author | Reyk Floeter <reyk@cvs.openbsd.org> | 2005-11-22 11:36:13 +0000 |
---|---|---|
committer | Reyk Floeter <reyk@cvs.openbsd.org> | 2005-11-22 11:36:13 +0000 |
commit | bb76f74956fe60e8ce58011926a3848c10f71890 (patch) | |
tree | 69ef41d74e90182d74d72011d09e3c508d10c444 /usr.sbin/tcpdump | |
parent | a02d75045e483f60b8fea1479ebf4bcd44ace3d3 (diff) |
add printer for IAPP and hostapd(8) messages
ok canacar@, tested by aanriot@ and others
Diffstat (limited to 'usr.sbin/tcpdump')
-rw-r--r-- | usr.sbin/tcpdump/Makefile | 6 | ||||
-rw-r--r-- | usr.sbin/tcpdump/interface.h | 5 | ||||
-rw-r--r-- | usr.sbin/tcpdump/print-802_11.c | 29 | ||||
-rw-r--r-- | usr.sbin/tcpdump/print-iapp.c | 107 | ||||
-rw-r--r-- | usr.sbin/tcpdump/print-udp.c | 9 |
5 files changed, 138 insertions, 18 deletions
diff --git a/usr.sbin/tcpdump/Makefile b/usr.sbin/tcpdump/Makefile index 4c137f35820..4591c373097 100644 --- a/usr.sbin/tcpdump/Makefile +++ b/usr.sbin/tcpdump/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.48 2005/10/08 19:45:15 canacar Exp $ +# $OpenBSD: Makefile,v 1.49 2005/11/22 11:36:12 reyk Exp $ # # Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 # The Regents of the University of California. All rights reserved. @@ -23,7 +23,7 @@ PROG= tcpdump MAN= tcpdump.8 -CFLAGS+=-Wall -I${.CURDIR}/../../sbin/pfctl +CFLAGS+=-Wall -I${.CURDIR}/../../sbin/pfctl -I${.CURDIR}/../hostapd CFLAGS+=-DCSLIP -DPPP -DHAVE_FDDI -DETHER_SERVICE -DRETSIGTYPE=void -DHAVE_NET_SLIP_H -DHAVE_ETHER_NTOHOST -DINET6 @@ -46,7 +46,7 @@ SRCS= tcpdump.c addrtoname.c privsep.c privsep_fdpass.c privsep_pcap.c \ print-etherip.c print-lwres.c print-cdp.c print-pflog.c \ print-pfsync.c pf_print_state.c \ print-udpencap.c print-carp.c \ - print-802_11.c print-mpls.c \ + print-802_11.c print-iapp.c print-mpls.c \ gmt2local.c savestr.c setsignal.c # TCP OS Fingerprinting diff --git a/usr.sbin/tcpdump/interface.h b/usr.sbin/tcpdump/interface.h index fc0272393d3..97608a95140 100644 --- a/usr.sbin/tcpdump/interface.h +++ b/usr.sbin/tcpdump/interface.h @@ -1,4 +1,4 @@ -/* $OpenBSD: interface.h,v 1.50 2005/10/08 19:45:15 canacar Exp $ */ +/* $OpenBSD: interface.h,v 1.51 2005/11/22 11:36:12 reyk Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 @@ -20,7 +20,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/interface.h,v 1.50 2005/10/08 19:45:15 canacar Exp $ (LBL) + * @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/interface.h,v 1.51 2005/11/22 11:36:12 reyk Exp $ (LBL) */ #ifndef tcpdump_interface_h @@ -218,6 +218,7 @@ extern void ieee802_11_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); extern void ieee802_11_radio_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); +extern void iapp_print(const u_char *, u_int); extern void igrp_print(const u_char *, u_int, const u_char *); extern void ip_print(const u_char *, u_int); extern void ipx_print(const u_char *, u_int); diff --git a/usr.sbin/tcpdump/print-802_11.c b/usr.sbin/tcpdump/print-802_11.c index 4008df38a62..10566cac92c 100644 --- a/usr.sbin/tcpdump/print-802_11.c +++ b/usr.sbin/tcpdump/print-802_11.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print-802_11.c,v 1.4 2005/05/28 09:01:52 reyk Exp $ */ +/* $OpenBSD: print-802_11.c,v 1.5 2005/11/22 11:36:12 reyk Exp $ */ /* * Copyright (c) 2005 Reyk Floeter <reyk@vantronix.net> @@ -68,6 +68,8 @@ u_int ieee80211_any2ieee(u_int, u_int); #define TCARR(a) TCHECK2(*a, sizeof(a)) +int ieee80211_encap = 0; + int ieee80211_hdr(struct ieee80211_frame *wh) { @@ -449,7 +451,8 @@ ieee802_11_if_print(u_char *user, const struct pcap_pkthdr *h, { struct ieee80211_frame *wh = (struct ieee80211_frame*)p; - ts_print(&h->ts); + if (!ieee80211_encap) + ts_print(&h->ts); packetp = p; snapend = p + h->caplen; @@ -457,10 +460,11 @@ ieee802_11_if_print(u_char *user, const struct pcap_pkthdr *h, if (ieee80211_print(wh, (u_int)h->caplen) != 0) printf("[|802.11]"); - if (xflag) - default_print(p, (u_int)h->caplen); - - putchar('\n'); + if (!ieee80211_encap) { + if (xflag) + default_print(p, (u_int)h->caplen); + putchar('\n'); + } } void @@ -474,7 +478,8 @@ ieee802_11_radio_if_print(u_char *user, const struct pcap_pkthdr *h, u_int32_t present; u_int len, rh_len; - ts_print(&h->ts); + if (!ieee80211_encap) + ts_print(&h->ts); packetp = p; snapend = p + h->caplen; @@ -484,7 +489,7 @@ ieee802_11_radio_if_print(u_char *user, const struct pcap_pkthdr *h, len = h->caplen; rh_len = letoh16(rh->it_len); if (rh->it_version != 0) { - printf("[?radiotap + 802.11 v:%u]\n", rh->it_version); + printf("[?radiotap + 802.11 v:%u]", rh->it_version); goto out; } @@ -645,7 +650,9 @@ ieee802_11_radio_if_print(u_char *user, const struct pcap_pkthdr *h, printf("[|radiotap + 802.11]"); out: - if (xflag) - default_print(p, h->caplen); - putchar('\n'); + if (!ieee80211_encap) { + if (xflag) + default_print(p, h->caplen); + putchar('\n'); + } } diff --git a/usr.sbin/tcpdump/print-iapp.c b/usr.sbin/tcpdump/print-iapp.c new file mode 100644 index 00000000000..ad96fb991f9 --- /dev/null +++ b/usr.sbin/tcpdump/print-iapp.c @@ -0,0 +1,107 @@ +/* $OpenBSD: print-iapp.c,v 1.1 2005/11/22 11:36:12 reyk Exp $ */ + +/* + * Copyright (c) 2005 Reyk Floeter <reyk@vantronix.net> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/socket.h> +#include <sys/file.h> +#include <sys/ioctl.h> + +#include <net/if.h> + +#include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/if_ether.h> + +#include <net80211/ieee80211.h> + +#include <pcap.h> +#include <stdio.h> +#include <string.h> + +#include "addrtoname.h" +#include "interface.h" +#include "iapp.h" + +const char *ieee80211_iapp_frame_type_name[] = + IEEE80211_IAPP_FRAME_TYPE_NAME; + +extern int ieee80211_encap; + +void +iapp_print(const u_char *p, u_int len) +{ + struct ieee80211_iapp_frame *wf = (struct ieee80211_iapp_frame *)p; + struct ieee80211_iapp_add_notify *add; + struct pcap_pkthdr fakeh; + const u_char *data; + + TCHECK2(*wf, sizeof(struct ieee80211_iapp_frame)); + + /* Print common IAPP information */ + printf(" IAPPv%u ", wf->i_version); + if (wf->i_command & 0xf0) + printf("unknown: 0x%0x", wf->i_command); + else + printf("%s ", ieee80211_iapp_frame_type_name[wf->i_command]); + printf("(id %u) %u: ", wf->i_identifier, wf->i_length); + + + data = p + sizeof(struct ieee80211_iapp_frame); + + switch (wf->i_command) { + case IEEE80211_IAPP_FRAME_ADD_NOTIFY: + /* + * Print details about the IAPP ADD.notify message. + */ + TCHECK2(*data, sizeof(struct ieee80211_iapp_add_notify)); + add = (struct ieee80211_iapp_add_notify *)data; + + printf("octets %u, ", add->a_length); + if (add->a_reserved) + printf("reserved %u, ", add->a_reserved); + if (add->a_length == IEEE80211_ADDR_LEN) + printf("lladdr %s, ", etheraddr_string(add->a_macaddr)); + printf("seq %u", add->a_seqnum); + break; + case IEEE80211_IAPP_FRAME_HOSTAPD_RADIOTAP: + case IEEE80211_IAPP_FRAME_HOSTAPD_PCAP: + /* + * hostapd(8) uses its own subtypes to send IEEE 802.11 + * frame dumps to the IAPP group (either with or without + * radiotap header). Decode it using the IEEE 802.11 + * printer. + */ + bzero(&fakeh, sizeof(fakeh)); + fakeh.len = wf->i_length; + fakeh.caplen = snapend - data; + + ieee80211_encap = 1; + if (wf->i_command == IEEE80211_IAPP_FRAME_HOSTAPD_RADIOTAP) + ieee802_11_radio_if_print(NULL, &fakeh, data); + else + ieee802_11_if_print(NULL, &fakeh, data); + ieee80211_encap = 0; + break; + } + return; + +trunc: + printf(" [|IAPP]"); +} + diff --git a/usr.sbin/tcpdump/print-udp.c b/usr.sbin/tcpdump/print-udp.c index 123df225556..52ee214e675 100644 --- a/usr.sbin/tcpdump/print-udp.c +++ b/usr.sbin/tcpdump/print-udp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print-udp.c,v 1.24 2004/01/28 19:44:55 canacar Exp $ */ +/* $OpenBSD: print-udp.c,v 1.25 2005/11/22 11:36:12 reyk Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996 @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-udp.c,v 1.24 2004/01/28 19:44:55 canacar Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-udp.c,v 1.25 2005/11/22 11:36:12 reyk Exp $ (LBL)"; #endif #include <sys/param.h> @@ -37,6 +37,8 @@ static const char rcsid[] = #include <netinet/udp.h> #include <netinet/udp_var.h> +#include <net80211/ieee80211.h> + #ifdef NOERROR #undef NOERROR /* Solaris sucks */ #endif @@ -64,6 +66,7 @@ static const char rcsid[] = #include "nfsv2.h" #include "bootp.h" +#include "iapp.h" struct rtcphdr { u_short rh_flags; /* T:2 P:1 CNT:5 PT:8 */ @@ -604,6 +607,8 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2) radius_print((const u_char *)(up + 1), length); else if (dport == 3456) vat_print((const void *)(up + 1), length, up); + else if (ISPORT(IAPP_PORT)) + iapp_print((const u_char *)(up + 1), length); #ifdef INET6 else if (ISPORT(RIPNG_PORT)) ripng_print((const u_char *)(up + 1), length); |