]> The Tcpdump Group git mirrors - tcpdump/blob - print-stp.c
repair ID payload protocol # decoding. we shouln't check DOI,
[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.3 2000-07-01 03:39:10 assar Exp $";
15 #endif
16
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20
21 #include <sys/param.h>
22 #include <sys/time.h>
23 #include <sys/socket.h>
24
25 #include <netinet/in.h>
26 #include <netinet/in_systm.h>
27 #include <netinet/ip.h>
28 #include <netinet/ip_var.h>
29 #include <netinet/udp.h>
30 #include <netinet/udp_var.h>
31 #include <netinet/tcp.h>
32 #include <netinet/tcpip.h>
33
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <string.h>
37
38 #include "interface.h"
39 #include "addrtoname.h"
40 #include "extract.h"
41
42 static void
43 stp_print_bridge_id(const u_char *p)
44 {
45 printf("%.2x%.2x.%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
46 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
47 }
48
49 static void
50 stp_print_config_bpdu(const u_char *p, u_int length)
51 {
52 printf("config ");
53 if (p[7] & 1)
54 printf("TOP_CHANGE ");
55 if (p[7] & 0x80)
56 printf("TOP_CHANGE_ACK ");
57
58 stp_print_bridge_id(p+20);
59 printf(".%.2x%.2x ", p[28], p[29]);
60
61 printf("root ");
62 stp_print_bridge_id(p+8);
63
64 printf(" pathcost %i ", (p[16] << 24) | (p[17] << 16) | (p[18] << 8) | p[19]);
65
66 printf("age %i ", p[30]);
67 printf("max %i ", p[32]);
68 printf("hello %i ", p[34]);
69 printf("fdelay %i ", p[36]);
70 }
71
72 static void
73 stp_print_tcn_bpdu(const u_char *p, u_int length)
74 {
75 printf("tcn");
76 }
77
78 /*
79 * Print 802.1d packets.
80 */
81 void
82 stp_print(const u_char *p, u_int length)
83 {
84 if (length < 7)
85 goto trunc;
86
87 printf("802.1d ");
88 if (p[2] != 0x03 || p[3] || p[4] || p[5]) {
89 printf("unknown version");
90 return;
91 }
92
93 switch (p[6])
94 {
95 case 0:
96 if (length < 10)
97 goto trunc;
98 stp_print_config_bpdu(p, length);
99 break;
100
101 case 1:
102 stp_print_tcn_bpdu(p, length);
103 break;
104
105 default:
106 printf("unknown type %i\n", p[6]);
107 break;
108 }
109
110 return;
111 trunc:
112 printf("[|stp %d]", length);
113 }