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.11 2001/09/17 21:57:56 fenner Exp $";
36 #include <sys/param.h>
39 #include <netinet/in.h>
46 #include "interface.h"
47 #include "addrtoname.h"
48 #include "extract.h" /* must come after interface.h */
50 static int cdp_print_addr(const u_char *, int);
51 static int cdp_print_prefixes(const u_char *, int);
54 cdp_print(const u_char *p, u_int length, u_int caplen,
55 const u_char *esrc, const u_char *edst)
60 /* Cisco Discovery Protocol */
63 (void)printf("[|cdp]");
67 i = 0; /* CDP data starts at offset 0 */
68 printf("CDP v%u, ttl=%us", p[i], p[i + 1]);
69 i += 4; /* skip version, TTL and chksum */
74 type = (p[i] << 8) + p[i + 1];
75 len = (p[i + 2] << 8) + p[i + 3];
81 printf(" %02x/%02x", type, len);
91 printf(" DevID '%.*s'", len - 4, p + i + 4);
95 if (cdp_print_addr(p + i + 4, len - 4) < 0)
99 printf(" PortID '%.*s'", len - 4, p + i + 4);
102 printf(" CAP 0x%02x", (unsigned) p[i + 7]);
106 printf(" Version:\n%.*s", len - 4, p + i + 4);
108 printf(" Version: (suppressed)");
111 printf(" Platform: '%.*s'", len - 4, p + i + 4);
114 if (cdp_print_prefixes(p + i + 4, len - 4) < 0)
117 case 0x09: /* guess - not documented */
118 printf(" VTP Management Domain: '%.*s'", len - 4,
121 case 0x0a: /* guess - not documented */
122 printf(" Native VLAN ID: %d",
123 (p[i + 4] << 8) + p[i + 4 + 1] - 1);
125 case 0x0b: /* guess - not documented */
126 printf(" Duplex: %s", p[i + 4] ? "full": "half");
129 printf(" unknown field type %02x, len %d", type, len);
133 /* avoid infinite loop */
146 * Protocol type values.
148 * PT_NLPID means that the protocol type field contains an OSI NLPID.
150 * PT_IEEE_802_2 means that the protocol type field contains an IEEE 802.2
151 * LLC header that specifies that the payload is for that protocol.
153 #define PT_NLPID 1 /* OSI NLPID */
154 #define PT_IEEE_802_2 2 /* IEEE 802.2 LLC header */
157 cdp_print_addr(const u_char * p, int l)
160 const u_char *endp = p + l;
162 static u_char prot_ipv6[] = {
163 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x86, 0xdd
167 num = EXTRACT_32BITS(p);
170 printf(" (%d): ", num);
172 while (p < endp && num >= 0) {
175 pt = p[0]; /* type of "protocol" field */
176 pl = p[1]; /* length of "protocol" field */
179 if (p + pl + 2 > endp)
181 al = EXTRACT_16BITS(&p[pl]); /* address length */
183 if (pt == PT_NLPID && pl == 1 && *p == 0xcc && al == 4) {
185 * IPv4: protocol type = NLPID, protocol length = 1
186 * (1-byte NLPID), protocol = 0xcc (NLPID for IPv4),
193 printf("IPv4 %u.%u.%u.%u", p[0], p[1], p[2], p[3]);
197 else if (pt == PT_IEEE_802_2 && pl == 8 &&
198 memcmp(p, prot_ipv6, 8) == 0 && al == 16) {
200 * IPv6: protocol type = IEEE 802.2 header,
201 * protocol length = 8 (size of LLC+SNAP header),
202 * protocol = LLC+SNAP header with the IPv6
203 * Ethertype, address length = 16
209 printf("IPv6 %s", ip6addr_string(p));
215 * Generic case: just print raw data
219 printf("pt=0x%02x, pl=%d, pb=", *(p - 2), pl);
221 printf(" %02x", *p++);
224 al = (*p << 8) + *(p + 1);
225 printf(", al=%d, a=", al);
230 printf(" %02x", *p++);
245 cdp_print_prefixes(const u_char * p, int l)
250 printf(" IPv4 Prefixes (%d):", l / 5);
253 printf(" %u.%u.%u.%u/%u", p[0], p[1], p[2], p[3], p[4]);