diff options
author | assar <assar> | 2000-06-10 20:57:55 +0000 |
---|---|---|
committer | assar <assar> | 2000-06-10 20:57:55 +0000 |
commit | 954bc7f13e79df48ad456f0adb524b996e86be96 (patch) | |
tree | fe07a711d12138dac4ddc4c9b2e4a8b62c268415 /print-stp.c | |
parent | e445d503676ded25fe46aa6cfef2fa63ebdd71ae (diff) | |
download | tcpdump-954bc7f13e79df48ad456f0adb524b996e86be96.tar.gz |
add IEEE8021.d printer contributed by Lennert Buytenhek <buytenh@gnu.org>
Diffstat (limited to 'print-stp.c')
-rw-r--r-- | print-stp.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/print-stp.c b/print-stp.c new file mode 100644 index 00000000..f2615fd7 --- /dev/null +++ b/print-stp.c @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2000 Lennert Buytenhek + * + * This software may be distributed either under the terms of the + * BSD-style license that accompanies tcpdump or the GNU General + * Public License + * + * Format and print IEEE 802.1d spanning tree protocol packets. + * Contributed by Lennert Buytenhek <buytenh@gnu.org> + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-stp.c,v 1.1 2000-06-10 20:57:57 assar Exp $"; +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/socket.h> + +#include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_var.h> +#include <netinet/udp.h> +#include <netinet/udp_var.h> +#include <netinet/tcp.h> +#include <netinet/tcpip.h> + +#ifdef __STDC__ +#include <stdlib.h> +#endif +#include <stdio.h> +#include <string.h> + +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" + +static void +stp_print_bridge_id(const u_char *p) +{ + printf("%.2x%.2x.%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", + p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); +} + +static void +stp_print_config_bpdu(const u_char *p, u_int length) +{ + printf("config "); + if (p[7] & 1) + printf("TOP_CHANGE "); + if (p[7] & 0x80) + printf("TOP_CHANGE_ACK "); + + stp_print_bridge_id(p+20); + printf(".%.2x%.2x ", p[28], p[29]); + + printf("root "); + stp_print_bridge_id(p+8); + + printf(" pathcost %i ", (p[16] << 24) | (p[17] << 16) | (p[18] << 8) | p[19]); + + printf("age %i ", p[30]); + printf("max %i ", p[32]); + printf("hello %i ", p[34]); + printf("fdelay %i ", p[36]); +} + +static void +stp_print_tcn_bpdu(const u_char *p, u_int length) +{ + printf("tcn"); +} + +/* + * Print 802.1d packets. + */ +void +stp_print(const u_char *p, u_int length) +{ + if (length < 7) + goto trunc; + + printf("802.1d "); + if (p[2] != 0x03 || p[3] || p[4] || p[5]) { + printf("unknown version"); + return; + } + + switch (p[6]) + { + case 0: + if (length < 10) + goto trunc; + stp_print_config_bpdu(p, length); + break; + + case 1: + stp_print_tcn_bpdu(p, length); + break; + + default: + printf("unknown type %i\n", p[6]); + break; + } + + return; +trunc: + printf("[|stp %d]", length); +} |