2 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 * Code by Gert Doering, SpaceNet GmbH, gert@space.net
23 * Reference documentation:
24 * http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm
28 static const char rcsid
[] _U_
=
29 "@(#) $Header: /tcpdump/master/tcpdump/print-cdp.c,v 1.19.2.3 2003-12-29 22:42:22 hannes Exp $";
36 #include <tcpdump-stdinc.h>
41 #include "interface.h"
42 #include "addrtoname.h"
43 #include "extract.h" /* must come after interface.h */
45 #define CDP_HEADER_LEN 4
47 static struct tok cdp_tlv_values
[] = {
51 { 0x04, "Capability"},
52 { 0x05, "Version String"},
55 { 0x08, "Protocol-Hello option"},
56 { 0x09, "VTP Management Domain"},
57 { 0x0a, "Native VLAN ID"},
59 { 0x0e, "ATA-186 VoIP VLAN request"},
60 { 0x0f, "ATA-186 VoIP VLAN assignment"},
61 { 0x10, "power consumption"},
63 { 0x12, "AVVID trust bitmap"},
64 { 0x13, "AVVID untrusted ports CoS"},
65 { 0x14, "System Name"},
66 { 0x15, "System Object ID (not decoded)"},
67 { 0x16, "Management Addresses"},
68 { 0x17, "Physical Location"},
72 static struct tok cdp_capability_values
[] = {
74 { 0x02, "Transparent Bridge" },
75 { 0x04, "Source Route Bridge" },
76 { 0x08, "L2 Switch" },
77 { 0x10, "L3 capable" },
78 { 0x20, "IGMP snooping" },
79 { 0x40, "L1 capable" },
83 static int cdp_print_addr(const u_char
*, int);
84 static int cdp_print_prefixes(const u_char
*, int);
85 static unsigned long cdp_get_number(const u_char
*, int);
88 cdp_print(const u_char
*pptr
, u_int length
, u_int caplen
)
93 if (caplen
< CDP_HEADER_LEN
) {
94 (void)printf("[|cdp]");
98 tptr
= pptr
; /* temporary pointer */
100 if (!TTEST2(*tptr
, CDP_HEADER_LEN
))
102 printf("CDPv%u, ttl: %us", *tptr
, *(tptr
+1));
104 printf(", checksum: %u (unverified), length %u", EXTRACT_16BITS(tptr
), length
);
105 tptr
+= CDP_HEADER_LEN
;
107 while (tptr
< (pptr
+length
)) {
109 if (!TTEST2(*tptr
, 4)) /* read out Type and Length */
111 type
= EXTRACT_16BITS(tptr
);
112 len
= EXTRACT_16BITS(tptr
+2); /* object length includes the 4 bytes header length */
116 if (!TTEST2(*tptr
, len
))
119 if (vflag
|| type
== 1) { /* in non-verbose mode just print Device-ID */
122 printf("\n\t%s (0x%02x), length: %u byte%s: ",
123 tok2str(cdp_tlv_values
,"unknown field type", type
),
126 len
>1 ? "s" : ""); /* plural */
130 case 0x01: /* Device-ID */
132 printf(", Device-ID '%.*s'", len
, tptr
);
134 printf("'%.*s'", len
, tptr
);
136 case 0x02: /* Address */
137 if (cdp_print_addr(tptr
, len
) < 0)
140 case 0x03: /* Port-ID */
141 printf("'%.*s'", len
, tptr
);
143 case 0x04: /* Capabilities */
144 printf("(0x%08x): %s",
145 EXTRACT_32BITS(tptr
),
146 bittok2str(cdp_capability_values
, "none",EXTRACT_32BITS(tptr
)));
148 case 0x05: /* Version */
150 for (i
=0;i
<len
;i
++) {
153 if (j
== 0x0a) /* lets rework the version string to get a nice identation */
157 case 0x06: /* Platform */
158 printf("'%.*s'", len
, tptr
);
160 case 0x07: /* Prefixes */
161 if (cdp_print_prefixes(tptr
, len
) < 0)
164 case 0x08: /* Protocol Hello Option - not documented */
166 case 0x09: /* VTP Mgmt Domain - not documented */
167 printf("'%.*s'", len
,tptr
);
169 case 0x0a: /* Native VLAN ID - not documented */
170 printf("%d",EXTRACT_16BITS(tptr
));
172 case 0x0b: /* Duplex - not documented */
173 printf("%s", *(tptr
) ? "full": "half");
176 /* http://www.cisco.com/univercd/cc/td/doc/product/voice/ata/atarn/186rn21m.htm
177 * plus more details from other sources
179 case 0x0e: /* ATA-186 VoIP VLAN request - incomplete doc. */
180 printf("app %d, vlan %d",
181 *(tptr
), EXTRACT_16BITS(tptr
+1));
183 case 0x10: /* ATA-186 VoIP VLAN assignment - incomplete doc. */
185 cdp_get_number(tptr
, len
)/1000.0 );
187 case 0x11: /* MTU - not documented */
188 printf("%u bytes", EXTRACT_32BITS(tptr
));
190 case 0x12: /* AVVID trust bitmap - not documented */
191 printf("0x%02x", *(tptr
) );
193 case 0x13: /* AVVID untrusted port CoS - not documented */
194 printf("0x%02x", *(tptr
));
196 case 0x14: /* System Name - not documented */
197 printf("'%.*s'", len
, tptr
);
199 case 0x16: /* System Object ID - not documented */
200 if (cdp_print_addr(tptr
, len
) < 0)
203 case 0x17: /* Physical Location - not documented */
204 printf("0x%02x/%.*s", *(tptr
), len
- 1, tptr
+ 1 );
207 print_unknown_data(tptr
,"\n\t ",len
);
211 /* avoid infinite loop */
217 printf(", length %u",caplen
);
225 * Protocol type values.
227 * PT_NLPID means that the protocol type field contains an OSI NLPID.
229 * PT_IEEE_802_2 means that the protocol type field contains an IEEE 802.2
230 * LLC header that specifies that the payload is for that protocol.
232 #define PT_NLPID 1 /* OSI NLPID */
233 #define PT_IEEE_802_2 2 /* IEEE 802.2 LLC header */
236 cdp_print_addr(const u_char
* p
, int l
)
239 const u_char
*endp
= p
+ l
;
241 static u_char prot_ipv6
[] = {
242 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x86, 0xdd
246 num
= EXTRACT_32BITS(p
);
249 while (p
< endp
&& num
>= 0) {
252 pt
= p
[0]; /* type of "protocol" field */
253 pl
= p
[1]; /* length of "protocol" field */
256 if (p
+ pl
+ 2 > endp
)
258 al
= EXTRACT_16BITS(&p
[pl
]); /* address length */
260 if (pt
== PT_NLPID
&& pl
== 1 && *p
== 0xcc && al
== 4) {
262 * IPv4: protocol type = NLPID, protocol length = 1
263 * (1-byte NLPID), protocol = 0xcc (NLPID for IPv4),
270 printf("IPv4 (%u) %s",
276 else if (pt
== PT_IEEE_802_2
&& pl
== 8 &&
277 memcmp(p
, prot_ipv6
, 8) == 0 && al
== 16) {
279 * IPv6: protocol type = IEEE 802.2 header,
280 * protocol length = 8 (size of LLC+SNAP header),
281 * protocol = LLC+SNAP header with the IPv6
282 * Ethertype, address length = 16
288 printf("IPv6 (%u) %s",
296 * Generic case: just print raw data
300 printf("pt=0x%02x, pl=%d, pb=", *(p
- 2), pl
);
302 printf(" %02x", *p
++);
305 al
= (*p
<< 8) + *(p
+ 1);
306 printf(", al=%d, a=", al
);
311 printf(" %02x", *p
++);
326 cdp_print_prefixes(const u_char
* p
, int l
)
331 printf(" IPv4 Prefixes (%d):", l
/ 5);
334 printf(" %u.%u.%u.%u/%u", p
[0], p
[1], p
[2], p
[3], p
[4]);
345 /* read in a <n>-byte number, MSB first
346 * (of course this can handle max sizeof(long))
348 static unsigned long cdp_get_number(const u_char
* p
, int l
)