]>
The Tcpdump Group git mirrors - tcpdump/blob - print-cdp.c
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
[] =
29 "@(#) $Header: /tcpdump/master/tcpdump/print-cdp.c,v 1.17 2002-09-05 21:25:38 guy Exp $";
36 #include <tcpdump-stdinc.h>
41 #include "interface.h"
42 #include "addrtoname.h"
43 #include "extract.h" /* must come after interface.h */
45 static int cdp_print_addr(const u_char
*, int);
46 static int cdp_print_prefixes(const u_char
*, int);
47 static unsigned long cdp_get_number(const u_char
*, int);
50 cdp_print(const u_char
*p
, u_int length
, u_int caplen
)
55 /* Cisco Discovery Protocol */
58 (void)printf("[|cdp]");
62 i
= 0; /* CDP data starts at offset 0 */
63 printf("CDP v%u, ttl=%us", p
[i
], p
[i
+ 1]);
64 i
+= 4; /* skip version, TTL and chksum */
69 type
= (p
[i
] << 8) + p
[i
+ 1];
70 len
= (p
[i
+ 2] << 8) + p
[i
+ 3];
76 printf(" %02x/%02x", type
, len
);
86 printf(" DevID '%.*s'", len
- 4, p
+ i
+ 4);
90 if (cdp_print_addr(p
+ i
+ 4, len
- 4) < 0)
94 printf(" PortID '%.*s'", len
- 4, p
+ i
+ 4);
97 printf(" CAP 0x%02x", (unsigned) p
[i
+ 7]);
101 printf(" Version:\n%.*s", len
- 4, p
+ i
+ 4);
103 printf(" Version: (suppressed)");
106 printf(" Platform: '%.*s'", len
- 4, p
+ i
+ 4);
109 if (cdp_print_prefixes(p
+ i
+ 4, len
- 4) < 0)
112 case 0x08: /* guess - not documented */
113 printf(" Protocol-Hello option" );
115 case 0x09: /* guess - not documented */
116 printf(" VTP Management Domain: '%.*s'", len
- 4,
119 case 0x0a: /* guess - not documented */
120 printf(" Native VLAN ID: %d",
121 (p
[i
+ 4] << 8) + p
[i
+ 4 + 1] );
123 case 0x0b: /* guess - not documented */
124 printf(" Duplex: %s", p
[i
+ 4] ? "full": "half");
126 /* http://www.cisco.com/univercd/cc/td/doc/product/voice/ata/atarn/186rn21m.htm
127 * plus more details from other sources
129 case 0x0e: /* incomplete doc. */
130 printf(" ATA-186 VoIP VLAN request, app %d, vlan %d",
131 p
[i
+ 4], EXTRACT_16BITS(&p
[i
+4+1]));
133 case 0x0f: /* incomplete doc. */
134 printf(" ATA-186 VoIP VLAN assignment" );
136 case 0x10: /* incomplete doc. */
137 printf(" power consumption: %1.2fW",
138 cdp_get_number(p
+i
+4, len
-4)/1000.0 );
140 case 0x11: /* guess - not documented */
141 printf(" MTU %u bytes", EXTRACT_32BITS(&p
[i
+4]));
143 case 0x12: /* guess - not documented */
144 printf(" AVVID trust bitmap 0x%02x", p
[i
+4] );
146 case 0x13: /* guess - not documented */
147 printf(" AVVID untrusted ports CoS: 0x%02x", p
[i
+4]);
149 case 0x14: /* guess - not documented */
150 printf(" System Name: '%.*s'", len
- 4,
153 case 0x15: /* guess - not documented */
154 printf(" System Object ID (not decoded) "); /* TODO */
156 case 0x16: /* guess - not documented */
157 printf(" Management Addresses: ");
158 if (cdp_print_addr(p
+ i
+ 4, len
- 4) < 0)
161 case 0x17: /* guess - not documented */
162 printf(" Physical Location: 0x%02x/%.*s",
163 p
[i
+4], len
- 5, p
+ i
+ 5 );
166 printf(" unknown field type %02x, len %d", type
, len
);
170 /* avoid infinite loop */
183 * Protocol type values.
185 * PT_NLPID means that the protocol type field contains an OSI NLPID.
187 * PT_IEEE_802_2 means that the protocol type field contains an IEEE 802.2
188 * LLC header that specifies that the payload is for that protocol.
190 #define PT_NLPID 1 /* OSI NLPID */
191 #define PT_IEEE_802_2 2 /* IEEE 802.2 LLC header */
194 cdp_print_addr(const u_char
* p
, int l
)
197 const u_char
*endp
= p
+ l
;
199 static u_char prot_ipv6
[] = {
200 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x86, 0xdd
204 num
= EXTRACT_32BITS(p
);
207 printf(" (%d): ", num
);
209 while (p
< endp
&& num
>= 0) {
212 pt
= p
[0]; /* type of "protocol" field */
213 pl
= p
[1]; /* length of "protocol" field */
216 if (p
+ pl
+ 2 > endp
)
218 al
= EXTRACT_16BITS(&p
[pl
]); /* address length */
220 if (pt
== PT_NLPID
&& pl
== 1 && *p
== 0xcc && al
== 4) {
222 * IPv4: protocol type = NLPID, protocol length = 1
223 * (1-byte NLPID), protocol = 0xcc (NLPID for IPv4),
230 printf("IPv4 %u.%u.%u.%u", p
[0], p
[1], p
[2], p
[3]);
234 else if (pt
== PT_IEEE_802_2
&& pl
== 8 &&
235 memcmp(p
, prot_ipv6
, 8) == 0 && al
== 16) {
237 * IPv6: protocol type = IEEE 802.2 header,
238 * protocol length = 8 (size of LLC+SNAP header),
239 * protocol = LLC+SNAP header with the IPv6
240 * Ethertype, address length = 16
246 printf("IPv6 %s", ip6addr_string(p
));
252 * Generic case: just print raw data
256 printf("pt=0x%02x, pl=%d, pb=", *(p
- 2), pl
);
258 printf(" %02x", *p
++);
261 al
= (*p
<< 8) + *(p
+ 1);
262 printf(", al=%d, a=", al
);
267 printf(" %02x", *p
++);
282 cdp_print_prefixes(const u_char
* p
, int l
)
287 printf(" IPv4 Prefixes (%d):", l
/ 5);
290 printf(" %u.%u.%u.%u/%u", p
[0], p
[1], p
[2], p
[3], p
[4]);
301 /* read in a <n>-byte number, MSB first
302 * (of course this can handle max sizeof(long))
304 static unsigned long cdp_get_number(const u_char
* p
, int l
)