]> The Tcpdump Group git mirrors - tcpdump/blob - print-stp.c
add config.h. From Kevin Steves <[email protected]>
[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.2 2000-06-13 12:19:07 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 #ifdef __STDC__
35 #include <stdlib.h>
36 #endif
37 #include <stdio.h>
38 #include <string.h>
39
40 #include "interface.h"
41 #include "addrtoname.h"
42 #include "extract.h"
43
44 static void
45 stp_print_bridge_id(const u_char *p)
46 {
47 printf("%.2x%.2x.%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
48 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
49 }
50
51 static void
52 stp_print_config_bpdu(const u_char *p, u_int length)
53 {
54 printf("config ");
55 if (p[7] & 1)
56 printf("TOP_CHANGE ");
57 if (p[7] & 0x80)
58 printf("TOP_CHANGE_ACK ");
59
60 stp_print_bridge_id(p+20);
61 printf(".%.2x%.2x ", p[28], p[29]);
62
63 printf("root ");
64 stp_print_bridge_id(p+8);
65
66 printf(" pathcost %i ", (p[16] << 24) | (p[17] << 16) | (p[18] << 8) | p[19]);
67
68 printf("age %i ", p[30]);
69 printf("max %i ", p[32]);
70 printf("hello %i ", p[34]);
71 printf("fdelay %i ", p[36]);
72 }
73
74 static void
75 stp_print_tcn_bpdu(const u_char *p, u_int length)
76 {
77 printf("tcn");
78 }
79
80 /*
81 * Print 802.1d packets.
82 */
83 void
84 stp_print(const u_char *p, u_int length)
85 {
86 if (length < 7)
87 goto trunc;
88
89 printf("802.1d ");
90 if (p[2] != 0x03 || p[3] || p[4] || p[5]) {
91 printf("unknown version");
92 return;
93 }
94
95 switch (p[6])
96 {
97 case 0:
98 if (length < 10)
99 goto trunc;
100 stp_print_config_bpdu(p, length);
101 break;
102
103 case 1:
104 stp_print_tcn_bpdu(p, length);
105 break;
106
107 default:
108 printf("unknown type %i\n", p[6]);
109 break;
110 }
111
112 return;
113 trunc:
114 printf("[|stp %d]", length);
115 }