]> The Tcpdump Group git mirrors - tcpdump/blob - print-stp.c
f2615fd7ec30584c4cf673e486d67d8b6316b01d
[tcpdump] / print-stp.c
1 /*
2 * Copyright (c) 2000 Lennert Buytenhek
3 *
4 * This software may be distributed either under the terms of the
5 * BSD-style license that accompanies tcpdump or the GNU General
6 * Public License
7 *
8 * Format and print IEEE 802.1d spanning tree protocol packets.
9 * Contributed by Lennert Buytenhek <buytenh@gnu.org>
10 */
11
12 #ifndef lint
13 static const char rcsid[] =
14 "@(#) $Header: /tcpdump/master/tcpdump/print-stp.c,v 1.1 2000-06-10 20:57:57 assar Exp $";
15 #endif
16
17 #include <sys/param.h>
18 #include <sys/time.h>
19 #include <sys/socket.h>
20
21 #include <netinet/in.h>
22 #include <netinet/in_systm.h>
23 #include <netinet/ip.h>
24 #include <netinet/ip_var.h>
25 #include <netinet/udp.h>
26 #include <netinet/udp_var.h>
27 #include <netinet/tcp.h>
28 #include <netinet/tcpip.h>
29
30 #ifdef __STDC__
31 #include <stdlib.h>
32 #endif
33 #include <stdio.h>
34 #include <string.h>
35
36 #include "interface.h"
37 #include "addrtoname.h"
38 #include "extract.h"
39
40 static void
41 stp_print_bridge_id(const u_char *p)
42 {
43 printf("%.2x%.2x.%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
44 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
45 }
46
47 static void
48 stp_print_config_bpdu(const u_char *p, u_int length)
49 {
50 printf("config ");
51 if (p[7] & 1)
52 printf("TOP_CHANGE ");
53 if (p[7] & 0x80)
54 printf("TOP_CHANGE_ACK ");
55
56 stp_print_bridge_id(p+20);
57 printf(".%.2x%.2x ", p[28], p[29]);
58
59 printf("root ");
60 stp_print_bridge_id(p+8);
61
62 printf(" pathcost %i ", (p[16] << 24) | (p[17] << 16) | (p[18] << 8) | p[19]);
63
64 printf("age %i ", p[30]);
65 printf("max %i ", p[32]);
66 printf("hello %i ", p[34]);
67 printf("fdelay %i ", p[36]);
68 }
69
70 static void
71 stp_print_tcn_bpdu(const u_char *p, u_int length)
72 {
73 printf("tcn");
74 }
75
76 /*
77 * Print 802.1d packets.
78 */
79 void
80 stp_print(const u_char *p, u_int length)
81 {
82 if (length < 7)
83 goto trunc;
84
85 printf("802.1d ");
86 if (p[2] != 0x03 || p[3] || p[4] || p[5]) {
87 printf("unknown version");
88 return;
89 }
90
91 switch (p[6])
92 {
93 case 0:
94 if (length < 10)
95 goto trunc;
96 stp_print_config_bpdu(p, length);
97 break;
98
99 case 1:
100 stp_print_tcn_bpdu(p, length);
101 break;
102
103 default:
104 printf("unknown type %i\n", p[6]);
105 break;
106 }
107
108 return;
109 trunc:
110 printf("[|stp %d]", length);
111 }