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.4 2000/07/29 07:27:54 assar 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 void cdp_print_addr( const u_char * p, int l );
51 static void cdp_print_prefixes( const u_char * p, int l );
54 * Returns non-zero IFF it succeeds in printing the header
57 cdp_print(const u_char *p, u_int length, u_int caplen,
58 const u_char *esrc, const u_char *edst)
63 /* Cisco Discovery Protocol */
67 (void)printf("[|cdp]");
71 i=8; /* CDP data starts at offset 8 */
72 printf ("CDP v%d, ttl=%ds", p[i], p[i+1] );
73 i+=4; /* skip version, TTL and chksum */
80 type = (p[i]<<8) + p[i+1];
81 len = (p[i+2]<<8) + p[i+3];
84 printf( "\n\t%02x/%02x", type, len );
88 if ( i+len > caplen ) {
96 printf( " DevID '%.*s'", len-4, p+i+4 );
100 cdp_print_addr( p+i+4, len-4 );
103 printf( " PortID '%.*s'", len-4, p+i+4 );
106 printf( " CAP 0x%02x", (unsigned) p[i+7] );
110 printf( " Version:\n%.*s", len-4, p+i+4 );
112 printf( " Version: (suppressed)" );
115 printf( " Platform: '%.*s'", len-4, p+i+4 );
118 cdp_print_prefixes( p+i+4, len-4 );
120 case 0x09: /* guess - not documented */
121 printf( " VTP Management Domain: '%.*s'", len-4, p+i+4 );
123 case 0x0a: /* guess - not documented */
124 printf( " Native VLAN ID: %d", (p[i+4]<<8) + p[i+4+1] - 1 );
126 case 0x0b: /* guess - not documented */
127 printf( " Duplex: %s", p[i+4] ? "full": "half" );
130 printf( " unknown field type %02x, len %d", type, len );
133 /* avoid infinite loop */
141 cdp_print_addr( const u_char * p, int l )
144 const u_char * endp = p+l;
146 num = (p[0] << 24) + (p[1]<<16) + (p[2]<<8)+ p[3];
149 printf(" (%d): ", num );
151 while( p < endp && num >= 0) {
155 /* special case: IPv4, protocol type=0xcc, addr. length=4 */
156 if ( pl == 1 && *p == 0xcc &&
157 p[1] == 0 && p[2] == 4 ) {
160 printf( "IPv4 %d.%d.%d.%d ", p[0], p[1], p[2], p[3] );
162 } else { /* generic case: just print raw data */
163 printf("pt=0x%02x, pl=%d, pb=", *(p-2), pl);
165 printf( " %02x", *p++);
166 al=(*p << 8) + *(p+1);
167 printf( ", al=%d, a=", al );
170 printf( " %02x", *p++);
179 cdp_print_prefixes( const u_char * p, int l )
181 printf( " IPv4 Prefixes (%d):", l/5 );
184 printf( " %d.%d.%d.%d/%d", p[0], p[1], p[2], p[3], p[4] );