2 * Common CLV decode routines.
4 * $Id: packet-isis-clv.c,v 1.2 1999/12/15 22:52:04 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>
37 #ifdef NEED_SNPRINTF_H
43 # include "snprintf.h"
50 #include "packet-isis.h"
51 #include "packet-isis-clv.h"
55 * Name: isis_dissect_area_address_clv()
58 * Take an area address CLV and display it pieces. An area address
59 * CLV is n, x byte hex strings.
62 * u_char * : packet data
63 * int : offset into packet data where we are.
64 * guint : length of clv we are decoding
65 * frame_data * : frame data (complete frame)
66 * proto_tree * : protocol display tree to fill out. May be NULL
69 * void, but we will add to proto tree if !NULL.
72 isis_dissect_area_address_clv(const u_char *pd, int offset,
73 guint length, frame_data *fd, proto_tree *tree ) {
77 while ( length > 0 ) {
81 isis_dissect_unknown( offset, length, tree, fd,
82 "short address (no length for payload)");
85 if ( mylen > length) {
86 isis_dissect_unknown(offset, length, tree, fd,
87 "short address, packet say %d, we have %d left",
93 * Lets turn the area address into "standard" 0000.0000.etc
96 sbuf = isis_address_to_string ( pd, offset + 1, mylen );
99 proto_tree_add_text ( tree, offset, mylen + 1,
100 "Area address (%d): %s", mylen, sbuf );
103 length -= mylen; /* length already adjusted for len fld*/
109 * Name: isis_dissect_authentication_clv()
112 * Take apart the CLV that hold authentication information. This
113 * is currently 1 octet auth type (which must be 1) and then
114 * the clear text password.
116 * An ISIS password has different meaning depending where it
117 * is found. Thus we support a passed in prefix string to
121 * u_char * : packet data
122 * int : offset into packet data where we are.
123 * guint : length of clv we are decoding
124 * frame_data * : frame data (complete frame)
125 * proto_tree * : protocol display tree to fill out. May be NULL
126 * char * : Password meaning
129 * void, but we will add to proto tree if !NULL.
132 isis_dissect_authentication_clv(const u_char *pd, int offset, guint length,
133 frame_data *fd, proto_tree *tree, char *meaning) {
135 char sbuf[300]; /* 255 + header info area */
143 pw_type = pd[offset++];
145 use_cleartext = FALSE;
148 s += sprintf ( s, "type 1, clear text" );
149 use_cleartext = TRUE;
152 s += sprintf ( s, "type 0x%02x, (must be 1)", pw_type );
156 s += sprintf ( s, " (0x%02x): ", length );
158 if ( use_cleartext ) {
160 strncpy(s, &pd[offset], length);
164 strcat(s, "<<no password found!!!>>" );
166 /* NOTE, s no longer valid */
168 proto_tree_add_text ( tree, offset - 1, length + 1,
169 "%s %s", meaning, sbuf );
170 if ( !use_cleartext ) {
172 isis_dissect_unknown(offset, length, tree, fd,
173 "Unknown autheticion type" );
178 * Name: isis_dissect_ip_int_clv()
181 * Take apart the CLV that lists all the IP interfaces. The
182 * meaning of which is slightly different for the different base packet
183 * types, but the display is not different. What we have is n ip
184 * addresses, plain and simple.
187 * u_char * : packet data
188 * int : offset into packet data where we are.
189 * guint : length of clv we are decoding
190 * frame_data * : frame data (complete frame)
191 * proto_tree * : protocol display tree to fill out. May be NULL
192 * gint : tree id to use for proto tree.
195 * void, but we will add to proto tree if !NULL.
198 isis_dissect_ip_int_clv(const u_char *pd, int offset,
199 guint length, frame_data *fd, proto_tree *tree, gint tree_id ) {
205 while ( length > 0 ) {
207 isis_dissect_unknown(offset, length, tree, fd,
208 "Short ip interface address (%d vs 4)",length );
211 memcpy(&addr, &pd[offset], sizeof(addr));
213 proto_tree_add_item(tree, tree_id, offset, 4, addr);
221 * Name: isis_dissect_nlpid_clv()
224 * Take apart a NLPID packet and display it. The NLPID (for intergrated
225 * ISIS, contains n network layer protocol IDs that the box supports.
226 * Our display buffer we use is upto 255 entries, 6 bytes per (0x00, )
227 * plus 1 for zero termination. We just just 256*6 for simplicity.
230 * u_char * : packet data
231 * int : offset into packet data where we are.
232 * guint : length of clv we are decoding
233 * frame_data * : frame data (complete frame)
234 * proto_tree * : protocol display tree to fill out. May be NULL
237 * void, but we will add to proto tree if !NULL.
240 isis_dissect_nlpid_clv(const u_char *pd, int offset,
241 guint length, frame_data *fd, proto_tree *tree ) {
245 int old_offset = offset;
247 if ( !tree ) return; /* nothing to do! */
249 while ( length-- > 0 ) {
251 s += sprintf ( s, ", " );
253 s += sprintf ( s, "0x%02x", pd[offset++] );
256 sprintf ( sbuf, "--none--" );
259 proto_tree_add_text ( tree, old_offset, hlen,
264 * Name: isis_dissect_clvs()
267 * Dispatch routine to shred all the CLVs in a packet. We just
268 * walk through the clv entries in the packet. For each one, we
269 * search the passed in valid clv's for this protocol (opts) for
270 * a matching code. If found, we add to the display tree and
271 * then call the dissector. If it is not, we just post an
272 * "unknown" clv entrie using the passed in unknown clv tree id.
275 * isis_clv_handle_t * : NULL dissector terminated array of codes
276 * and handlers (along with tree text and tree id's).
277 * int : length of CLV area.
278 * u_char * : packet data
279 * int : offset into packet data where we are.
280 * guint : length of clv we are decoding
281 * frame_data * : frame data (complete frame)
282 * proto_tree * : protocol display tree to fill out. May be NULL
283 * gint : unknown clv tree id
286 * void, but we will add to proto tree if !NULL.
289 isis_dissect_clvs(const isis_clv_handle_t *opts, int len,
290 const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
291 gint unknown_tree_id ) {
296 proto_tree *clv_tree;
302 length = pd[offset++];
303 adj = (sizeof(code) + sizeof(length) + length);
306 isis_dissect_unknown(offset, adj, tree, fd,
307 "Short CLV header (%d vs %d)",
312 while ((opts[q].dissect != NULL )&&( opts[q].optcode != code )){
315 if ( opts[q].dissect ) {
317 /* adjust by 2 for code/len octets */
318 snprintf ( sbuf, sizeof(sbuf), "%s (%d)",
319 opts[q].tree_text, length );
320 ti = proto_tree_add_text(tree, offset - 2,
322 clv_tree = proto_item_add_subtree(ti,
327 opts[q].dissect(pd, offset, length, fd, clv_tree );
330 snprintf ( sbuf, sizeof(sbuf),
331 "Unknown code (%d:%d)", code, length );
332 ti = proto_tree_add_text(tree, offset - 2,
334 clv_tree = proto_item_add_subtree(ti,