2 * Routines for the disassembly of the "Cisco Discovery Protocol"
3 * (c) Copyright Hannes R. Boehm <hannes@boehm.org>
5 * $Id: packet-cdp.c,v 1.8 1999/03/23 03:14:36 gram Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@zing.org>
9 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #ifdef HAVE_SYS_TYPES_H
30 #include <sys/types.h>
39 /* Offsets in TLV structure. */
44 add_multi_line_string_to_tree(proto_tree *tree, gint start, gint len,
45 const gchar *prefix, const gchar *string);
48 dissect_cdp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
49 proto_tree *cdp_tree = NULL;
52 typedef struct _e_cdp_hdr{
63 if (check_col(fd, COL_PROTOCOL))
64 col_add_str(fd, COL_PROTOCOL, "CDP");
65 if (check_col(fd, COL_INFO))
66 col_add_str(fd, COL_INFO, "Cisco Discovery Protocol");
69 ti = proto_tree_add_item(tree, offset, (fd->cap_len - offset),
70 "Cisco Discovery Protocol");
71 cdp_tree = proto_tree_new();
72 proto_item_add_subtree(ti, cdp_tree, ETT_CDP);
75 cdp_hdr = (e_cdp_hdr *) &pd[offset];
76 proto_tree_add_item(cdp_tree, offset, 1, "Version: %d", cdp_hdr->version);
77 proto_tree_add_item(cdp_tree, offset+1, 1, "Flags (unknown)");
78 proto_tree_add_item(cdp_tree, offset+2, 2, "TTL (unknown)");
82 dissect_data(pd, offset, fd, cdp_tree);
86 while( offset <= fd->cap_len ){
87 type = pntohs(&pd[offset + TLV_TYPE]);
88 length = pntohs(&pd[offset + TLV_LENGTH]);
90 case 0: /* ??? Mgmt Addr */
93 case 1: /* ??? Chassis ID */
94 proto_tree_add_item(cdp_tree, offset + 4,
95 length - 4, "Chassis ID: %s", &pd[offset+4] );
99 /* this is quite strange: this tlv contains no data itself but two tlvs which
100 * calculate the length without the 2 byte type and 2 byte length field
104 case 3: /* ??? Port */
105 proto_tree_add_item(cdp_tree, offset + 4,
106 length - 4, "Sent through Interface: %s", &pd[offset+4] );
109 case 5: /* ??? IOS Version */
110 add_multi_line_string_to_tree(cdp_tree,
111 offset + 4, length - 4, "Software Version: ",
115 case 6: /* ??? platform */
117 stringmem = malloc(length);
118 memset(stringmem, '\0', length);
119 memcpy(stringmem, &pd[offset+4], length - 4 );
120 proto_tree_add_item(cdp_tree, offset + 4, length - 4,
121 "Platform: %s", stringmem );
125 case 0x01cc: /* ??? Mgmt Addr */
126 proto_tree_add_item(cdp_tree, offset + 4, length,
128 ip_to_str(&pd[offset+4]) );
134 dissect_data(pd, offset, fd, cdp_tree);
139 proto_tree_add_item(cdp_tree, offset + TLV_TYPE,
140 2, "Type: %d", type);
141 proto_tree_add_item(cdp_tree, offset + TLV_LENGTH,
142 2, "Length: %d", length);
143 proto_tree_add_item(cdp_tree, offset + 4,
151 dissect_data(pd, offset, fd, cdp_tree);
156 add_multi_line_string_to_tree(proto_tree *tree, gint start, gint len,
157 const gchar *prefix, const gchar *string)
166 prefix_len = strlen(prefix);
169 for (i = 0; i < prefix_len; i++)
177 data_len = line_len + 1;
179 line_len = strlen(p);
182 proto_tree_add_item(tree, start, data_len, "%s%.*s", prefix,