2 * Common CLV decode routines.
4 * $Id: packet-isis-clv.c,v 1.1 1999/12/15 04:34:17 guy Exp $
5 * Stuart Stanley <stuarts@mxmail.net>
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.
33 #ifdef HAVE_SYS_TYPES_H
34 # include <sys/types.h>
41 #include "packet-isis.h"
42 #include "packet-isis-clv.h"
46 * Name: isis_dissect_area_address_clv()
49 * Take an area address CLV and display it pieces. An area address
50 * CLV is n, x byte hex strings.
53 * u_char * : packet data
54 * int : offset into packet data where we are.
55 * guint : length of clv we are decoding
56 * frame_data * : frame data (complete frame)
57 * proto_tree * : protocol display tree to fill out. May be NULL
60 * void, but we will add to proto tree if !NULL.
63 isis_dissect_area_address_clv(const u_char *pd, int offset,
64 guint length, frame_data *fd, proto_tree *tree ) {
68 while ( length > 0 ) {
72 isis_dissect_unknown( offset, length, tree, fd,
73 "short address (no length for payload)");
76 if ( mylen > length) {
77 isis_dissect_unknown(offset, length, tree, fd,
78 "short address, packet say %d, we have %d left",
84 * Lets turn the area address into "standard" 0000.0000.etc
87 sbuf = isis_address_to_string ( pd, offset + 1, mylen );
90 proto_tree_add_text ( tree, offset, mylen + 1,
91 "Area address (%d): %s", mylen, sbuf );
94 length -= mylen; /* length already adjusted for len fld*/
100 * Name: isis_dissect_authentication_clv()
103 * Take apart the CLV that hold authentication information. This
104 * is currently 1 octet auth type (which must be 1) and then
105 * the clear text password.
107 * An ISIS password has different meaning depending where it
108 * is found. Thus we support a passed in prefix string to
112 * u_char * : packet data
113 * int : offset into packet data where we are.
114 * guint : length of clv we are decoding
115 * frame_data * : frame data (complete frame)
116 * proto_tree * : protocol display tree to fill out. May be NULL
117 * char * : Password meaning
120 * void, but we will add to proto tree if !NULL.
123 isis_dissect_authentication_clv(const u_char *pd, int offset, guint length,
124 frame_data *fd, proto_tree *tree, char *meaning) {
126 char sbuf[300]; /* 255 + header info area */
134 pw_type = pd[offset++];
136 use_cleartext = FALSE;
139 s += sprintf ( s, "type 1, clear text" );
140 use_cleartext = TRUE;
143 s += sprintf ( s, "type 0x%02x, (must be 1)", pw_type );
147 s += sprintf ( s, " (0x%02x): ", length );
149 if ( use_cleartext ) {
151 strncpy(s, &pd[offset], length);
155 strcat(s, "<<no password found!!!>>" );
157 /* NOTE, s no longer valid */
159 proto_tree_add_text ( tree, offset - 1, length + 1,
160 "%s %s", meaning, sbuf );
161 if ( !use_cleartext ) {
163 isis_dissect_unknown(offset, length, tree, fd,
164 "Unknown autheticion type" );
169 * Name: isis_dissect_ip_int_clv()
172 * Take apart the CLV that lists all the IP interfaces. The
173 * meaning of which is slightly different for the different base packet
174 * types, but the display is not different. What we have is n ip
175 * addresses, plain and simple.
178 * u_char * : packet data
179 * int : offset into packet data where we are.
180 * guint : length of clv we are decoding
181 * frame_data * : frame data (complete frame)
182 * proto_tree * : protocol display tree to fill out. May be NULL
183 * gint : tree id to use for proto tree.
186 * void, but we will add to proto tree if !NULL.
189 isis_dissect_ip_int_clv(const u_char *pd, int offset,
190 guint length, frame_data *fd, proto_tree *tree, gint tree_id ) {
196 while ( length > 0 ) {
198 isis_dissect_unknown(offset, length, tree, fd,
199 "Short ip interface address (%d vs 4)",length );
202 memcpy(&addr, &pd[offset], sizeof(addr));
204 proto_tree_add_item(tree, tree_id, offset, 4, addr);
212 * Name: isis_dissect_nlpid_clv()
215 * Take apart a NLPID packet and display it. The NLPID (for intergrated
216 * ISIS, contains n network layer protocol IDs that the box supports.
217 * Our display buffer we use is upto 255 entries, 6 bytes per (0x00, )
218 * plus 1 for zero termination. We just just 256*6 for simplicity.
221 * u_char * : packet data
222 * int : offset into packet data where we are.
223 * guint : length of clv we are decoding
224 * frame_data * : frame data (complete frame)
225 * proto_tree * : protocol display tree to fill out. May be NULL
228 * void, but we will add to proto tree if !NULL.
231 isis_dissect_nlpid_clv(const u_char *pd, int offset,
232 guint length, frame_data *fd, proto_tree *tree ) {
236 int old_offset = offset;
238 if ( !tree ) return; /* nothing to do! */
240 while ( length-- > 0 ) {
242 s += sprintf ( s, ", " );
244 s += sprintf ( s, "0x%02x", pd[offset++] );
247 sprintf ( sbuf, "--none--" );
250 proto_tree_add_text ( tree, old_offset, hlen,
255 * Name: isis_dissect_clvs()
258 * Dispatch routine to shred all the CLVs in a packet. We just
259 * walk through the clv entries in the packet. For each one, we
260 * search the passed in valid clv's for this protocol (opts) for
261 * a matching code. If found, we add to the display tree and
262 * then call the dissector. If it is not, we just post an
263 * "unknown" clv entrie using the passed in unknown clv tree id.
266 * isis_clv_handle_t * : NULL dissector terminated array of codes
267 * and handlers (along with tree text and tree id's).
268 * int : length of CLV area.
269 * u_char * : packet data
270 * int : offset into packet data where we are.
271 * guint : length of clv we are decoding
272 * frame_data * : frame data (complete frame)
273 * proto_tree * : protocol display tree to fill out. May be NULL
274 * gint : unknown clv tree id
277 * void, but we will add to proto tree if !NULL.
280 isis_dissect_clvs(const isis_clv_handle_t *opts, int len,
281 const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
282 gint unknown_tree_id ) {
287 proto_tree *clv_tree;
293 length = pd[offset++];
294 adj = (sizeof(code) + sizeof(length) + length);
297 isis_dissect_unknown(offset, adj, tree, fd,
298 "Short CLV header (%d vs %d)",
303 while ((opts[q].dissect != NULL )&&( opts[q].optcode != code )){
306 if ( opts[q].dissect ) {
308 /* adjust by 2 for code/len octets */
309 snprintf ( sbuf, sizeof(sbuf), "%s (%d)",
310 opts[q].tree_text, length );
311 ti = proto_tree_add_text(tree, offset - 2,
313 clv_tree = proto_item_add_subtree(ti,
318 opts[q].dissect(pd, offset, length, fd, clv_tree );
321 snprintf ( sbuf, sizeof(sbuf),
322 "Unknown code (%d:%d)", code, length );
323 ti = proto_tree_add_text(tree, offset - 2,
325 clv_tree = proto_item_add_subtree(ti,