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.25 2004-10-07 14:53:11 hannes Exp $";
36 #include <tcpdump-stdinc.h>
41 #include "interface.h"
42 #include "addrtoname.h"
43 #include "extract.h" /* must come after interface.h */
46 static const char tstr
[] = "[|cdp]";
48 #define CDP_HEADER_LEN 4
50 static const struct tok cdp_tlv_values
[] = {
54 { 0x04, "Capability"},
55 { 0x05, "Version String"},
58 { 0x08, "Protocol-Hello option"},
59 { 0x09, "VTP Management Domain"},
60 { 0x0a, "Native VLAN ID"},
62 { 0x0e, "ATA-186 VoIP VLAN request"},
63 { 0x0f, "ATA-186 VoIP VLAN assignment"},
64 { 0x10, "power consumption"},
66 { 0x12, "AVVID trust bitmap"},
67 { 0x13, "AVVID untrusted ports CoS"},
68 { 0x14, "System Name"},
69 { 0x15, "System Object ID (not decoded)"},
70 { 0x16, "Management Addresses"},
71 { 0x17, "Physical Location"},
75 static const struct tok cdp_capability_values
[] = {
77 { 0x02, "Transparent Bridge" },
78 { 0x04, "Source Route Bridge" },
79 { 0x08, "L2 Switch" },
80 { 0x10, "L3 capable" },
81 { 0x20, "IGMP snooping" },
82 { 0x40, "L1 capable" },
86 static int cdp_print_addr(const u_char
*, int);
87 static int cdp_print_prefixes(const u_char
*, int);
88 static unsigned long cdp_get_number(const u_char
*, int);
91 cdp_print(const u_char
*pptr
, u_int length
, u_int caplen
)
96 if (caplen
< CDP_HEADER_LEN
) {
101 tptr
= pptr
; /* temporary pointer */
103 if (!TTEST2(*tptr
, CDP_HEADER_LEN
))
105 printf("CDPv%u, ttl: %us", *tptr
, *(tptr
+1));
107 printf(", checksum: %u (unverified), length %u", EXTRACT_16BITS(tptr
), length
);
108 tptr
+= CDP_HEADER_LEN
;
110 while (tptr
< (pptr
+length
)) {
112 if (!TTEST2(*tptr
, 4)) /* read out Type and Length */
114 type
= EXTRACT_16BITS(tptr
);
115 len
= EXTRACT_16BITS(tptr
+2); /* object length includes the 4 bytes header length */
119 if (!TTEST2(*tptr
, len
))
122 if (vflag
|| type
== 1) { /* in non-verbose mode just print Device-ID */
125 printf("\n\t%s (0x%02x), length: %u byte%s: ",
126 tok2str(cdp_tlv_values
,"unknown field type", type
),
129 PLURAL_SUFFIX(len
)); /* plural */
133 case 0x01: /* Device-ID */
135 printf(", Device-ID ");
137 fn_printn(tptr
, len
, NULL
);
140 case 0x02: /* Address */
141 if (cdp_print_addr(tptr
, len
) < 0)
144 case 0x03: /* Port-ID */
146 fn_printn(tptr
, len
, NULL
);
149 case 0x04: /* Capabilities */
150 printf("(0x%08x): %s",
151 EXTRACT_32BITS(tptr
),
152 bittok2str(cdp_capability_values
, "none",EXTRACT_32BITS(tptr
)));
154 case 0x05: /* Version */
156 for (i
=0;i
<len
;i
++) {
159 if (j
== 0x0a) /* lets rework the version string to get a nice identation */
163 case 0x06: /* Platform */
165 fn_printn(tptr
, len
, NULL
);
168 case 0x07: /* Prefixes */
169 if (cdp_print_prefixes(tptr
, len
) < 0)
172 case 0x08: /* Protocol Hello Option - not documented */
174 case 0x09: /* VTP Mgmt Domain - not documented */
176 fn_printn(tptr
, len
, NULL
);
179 case 0x0a: /* Native VLAN ID - not documented */
180 printf("%d",EXTRACT_16BITS(tptr
));
182 case 0x0b: /* Duplex - not documented */
183 printf("%s", *(tptr
) ? "full": "half");
186 /* http://www.cisco.com/univercd/cc/td/doc/product/voice/ata/atarn/186rn21m.htm
187 * plus more details from other sources
189 case 0x0e: /* ATA-186 VoIP VLAN request - incomplete doc. */
190 printf("app %d, vlan %d",
191 *(tptr
), EXTRACT_16BITS(tptr
+1));
193 case 0x10: /* ATA-186 VoIP VLAN assignment - incomplete doc. */
195 cdp_get_number(tptr
, len
)/1000.0 );
197 case 0x11: /* MTU - not documented */
198 printf("%u bytes", EXTRACT_32BITS(tptr
));
200 case 0x12: /* AVVID trust bitmap - not documented */
201 printf("0x%02x", *(tptr
) );
203 case 0x13: /* AVVID untrusted port CoS - not documented */
204 printf("0x%02x", *(tptr
));
206 case 0x14: /* System Name - not documented */
208 fn_printn(tptr
, len
, NULL
);
211 case 0x16: /* System Object ID - not documented */
212 if (cdp_print_addr(tptr
, len
) < 0)
215 case 0x17: /* Physical Location - not documented */
216 printf("0x%02x", *(tptr
));
219 fn_printn(tptr
+ 1, len
- 1, NULL
);
223 print_unknown_data(tptr
,"\n\t ",len
);
227 /* avoid infinite loop */
233 printf(", length %u",caplen
);
241 * Protocol type values.
243 * PT_NLPID means that the protocol type field contains an OSI NLPID.
245 * PT_IEEE_802_2 means that the protocol type field contains an IEEE 802.2
246 * LLC header that specifies that the payload is for that protocol.
248 #define PT_NLPID 1 /* OSI NLPID */
249 #define PT_IEEE_802_2 2 /* IEEE 802.2 LLC header */
252 cdp_print_addr(const u_char
* p
, int l
)
255 const u_char
*endp
= p
+ l
;
257 static const u_char prot_ipv6
[] = {
258 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x86, 0xdd
263 num
= EXTRACT_32BITS(p
);
266 while (p
< endp
&& num
>= 0) {
270 pt
= p
[0]; /* type of "protocol" field */
271 pl
= p
[1]; /* length of "protocol" field */
275 if (p
+ pl
+ 2 > endp
)
277 al
= EXTRACT_16BITS(&p
[pl
]); /* address length */
279 if (pt
== PT_NLPID
&& pl
== 1 && *p
== NLPID_IP
&& al
== 4) {
281 * IPv4: protocol type = NLPID, protocol length = 1
282 * (1-byte NLPID), protocol = 0xcc (NLPID for IPv4),
290 printf("IPv4 (%u) %s",
296 else if (pt
== PT_IEEE_802_2
&& pl
== 8 &&
297 memcmp(p
, prot_ipv6
, 8) == 0 && al
== 16) {
299 * IPv6: protocol type = IEEE 802.2 header,
300 * protocol length = 8 (size of LLC+SNAP header),
301 * protocol = LLC+SNAP header with the IPv6
302 * Ethertype, address length = 16
309 printf("IPv6 (%u) %s",
317 * Generic case: just print raw data
322 printf("pt=0x%02x, pl=%d, pb=", *(p
- 2), pl
);
324 printf(" %02x", *p
++);
328 al
= (*p
<< 8) + *(p
+ 1);
329 printf(", al=%d, a=", al
);
335 printf(" %02x", *p
++);
350 cdp_print_prefixes(const u_char
* p
, int l
)
355 printf(" IPv4 Prefixes (%d):", l
/ 5);
358 printf(" %u.%u.%u.%u/%u", p
[0], p
[1], p
[2], p
[3], p
[4]);
369 /* read in a <n>-byte number, MSB first
370 * (of course this can handle max sizeof(long))
372 static unsigned long cdp_get_number(const u_char
* p
, int l
)