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.5 1999/01/06 23:07:42 guy 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.
34 #ifdef HAVE_SYS_TYPES_H
35 #include <sys/types.h>
38 #ifdef HAVE_NETINET_IN_H
39 #include <netinet/in.h>
45 /* Offsets in TLV structure. */
50 add_multi_line_string_to_tree(GtkWidget *tree, gint start, gint len,
51 const gchar *prefix, const gchar *string);
54 dissect_cdp(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
55 GtkWidget *cdp_tree = NULL, *ti;
57 typedef struct _e_cdp_hdr{
68 if (check_col(fd, COL_PROTOCOL))
69 col_add_str(fd, COL_PROTOCOL, "CDP");
70 if (check_col(fd, COL_INFO))
71 col_add_str(fd, COL_INFO, "Cisco Discovery Protocol");
74 ti = add_item_to_tree(GTK_WIDGET(tree), offset, (fd->cap_len - offset),
75 "Cisco Discovery Protocol");
76 cdp_tree = gtk_tree_new();
77 add_subtree(ti, cdp_tree, ETT_CDP);
80 cdp_hdr = (e_cdp_hdr *) &pd[offset];
81 add_item_to_tree(cdp_tree, offset, 0, "under development (hannes@boehm.org)");
82 add_item_to_tree(cdp_tree, offset, 1, "Version: %d", cdp_hdr->version);
83 add_item_to_tree(cdp_tree, offset+1, 1, "Flags (unknown)");
84 add_item_to_tree(cdp_tree, offset+2, 2, "TTL (unknown)");
88 dissect_data(pd, offset, fd, (GtkTree *) cdp_tree);
92 while( offset <= fd->cap_len ){
93 type = pntohs(&pd[offset + TLV_TYPE]);
94 length = pntohs(&pd[offset + TLV_LENGTH]);
96 case 0: /* ??? Mgmt Addr */
99 case 1: /* ??? Chassis ID */
100 add_item_to_tree(cdp_tree, offset + 4,
101 length - 4, "Chassis ID: %s", &pd[offset+4] );
105 /* this is quite strange: this tlv contains no data itself but two tlvs which
106 * calculate the length without the 2 byte type and 2 byte length field
110 case 3: /* ??? Port */
111 add_item_to_tree(cdp_tree, offset + 4,
112 length - 4, "Sent through Interface: %s", &pd[offset+4] );
115 case 5: /* ??? IOS Version */
116 add_multi_line_string_to_tree(cdp_tree,
117 offset + 4, length - 4, "Software Version: ",
121 case 6: /* ??? platform */
123 stringmem = malloc(length);
124 memset(stringmem, '\0', length);
125 memcpy(stringmem, &pd[offset+4], length - 4 );
126 add_item_to_tree(cdp_tree, offset + 4, length - 4,
127 "Platform: %s", stringmem );
131 case 0x01cc: /* ??? Mgmt Addr */
132 add_item_to_tree(cdp_tree, offset + 4, length,
134 ip_to_str(&pd[offset+4]) );
140 dissect_data(pd, offset, fd, (GtkTree *) cdp_tree);
145 add_item_to_tree(cdp_tree, offset + TLV_TYPE,
146 2, "Type: %d", type);
147 add_item_to_tree(cdp_tree, offset + TLV_LENGTH,
148 2, "Length: %d", length);
149 add_item_to_tree(cdp_tree, offset + 4,
157 dissect_data(pd, offset, fd, (GtkTree *) cdp_tree);
162 add_multi_line_string_to_tree(GtkWidget *tree, gint start, gint len,
163 const gchar *prefix, const gchar *string)
172 prefix_len = strlen(prefix);
175 for (i = 0; i < prefix_len; i++)
183 data_len = line_len + 1;
185 line_len = strlen(p);
188 add_item_to_tree(tree, start, data_len, "%s%.*s", prefix,