2 * Common CLV decode routines.
4 * $Id: packet-isis-clv.c,v 1.6 2000/06/19 08:33:47 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-osi.h"
51 #include "packet-isis.h"
52 #include "packet-isis-clv.h"
56 * Name: isis_dissect_area_address_clv()
59 * Take an area address CLV and display it pieces. An area address
60 * CLV is n, x byte hex strings.
63 * u_char * : packet data
64 * int : offset into packet data where we are.
65 * guint : length of clv we are decoding
66 * frame_data * : frame data (complete frame)
67 * proto_tree * : protocol display tree to fill out. May be NULL
70 * void, but we will add to proto tree if !NULL.
73 isis_dissect_area_address_clv(const u_char *pd, int offset,
74 guint length, frame_data *fd, proto_tree *tree ) {
78 while ( length > 0 ) {
82 isis_dissect_unknown( offset, length, tree, fd,
83 "short address (no length for payload)");
86 if ( mylen > length) {
87 isis_dissect_unknown(offset, length, tree, fd,
88 "short address, packet say %d, we have %d left",
94 * Lets turn the area address into "standard" 0000.0000.etc
97 /* sbuf = isis_address_to_string ( pd, offset + 1, mylen );*/
98 sbuf = print_nsap_net( pd + offset + 1, mylen );
101 proto_tree_add_text ( tree, NullTVB, offset, mylen + 1,
102 "Area address (%d): %s", mylen, sbuf );
105 length -= mylen; /* length already adjusted for len fld*/
111 * Name: isis_dissect_authentication_clv()
114 * Take apart the CLV that hold authentication information. This
115 * is currently 1 octet auth type (which must be 1) and then
116 * the clear text password.
118 * An ISIS password has different meaning depending where it
119 * is found. Thus we support a passed in prefix string to
123 * u_char * : packet data
124 * int : offset into packet data where we are.
125 * guint : length of clv we are decoding
126 * frame_data * : frame data (complete frame)
127 * proto_tree * : protocol display tree to fill out. May be NULL
128 * char * : Password meaning
131 * void, but we will add to proto tree if !NULL.
134 isis_dissect_authentication_clv(const u_char *pd, int offset, guint length,
135 frame_data *fd, proto_tree *tree, char *meaning) {
137 char sbuf[300]; /* 255 + header info area */
145 pw_type = pd[offset++];
147 use_cleartext = FALSE;
150 s += sprintf ( s, "type 1, clear text" );
151 use_cleartext = TRUE;
154 s += sprintf ( s, "type 0x%02x, (must be 1)", pw_type );
158 s += sprintf ( s, " (0x%02x): ", length );
160 if ( use_cleartext ) {
162 strncpy(s, &pd[offset], length);
166 strcat(s, "<<no password found!!!>>" );
168 /* NOTE, s no longer valid */
170 proto_tree_add_text ( tree, NullTVB, offset - 1, length + 1,
171 "%s %s", meaning, sbuf );
172 if ( !use_cleartext ) {
174 isis_dissect_unknown(offset, length, tree, fd,
175 "Unknown autheticion type" );
180 * Name: isis_dissect_ip_int_clv()
183 * Take apart the CLV that lists all the IP interfaces. The
184 * meaning of which is slightly different for the different base packet
185 * types, but the display is not different. What we have is n ip
186 * addresses, plain and simple.
189 * u_char * : packet data
190 * int : offset into packet data where we are.
191 * guint : length of clv we are decoding
192 * frame_data * : frame data (complete frame)
193 * proto_tree * : protocol display tree to fill out. May be NULL
194 * gint : tree id to use for proto tree.
197 * void, but we will add to proto tree if !NULL.
200 isis_dissect_ip_int_clv(const u_char *pd, int offset,
201 guint length, frame_data *fd, proto_tree *tree, gint tree_id ) {
207 while ( length > 0 ) {
209 isis_dissect_unknown(offset, length, tree, fd,
210 "Short ip interface address (%d vs 4)",length );
213 memcpy(&addr, &pd[offset], sizeof(addr));
215 proto_tree_add_ipv4(tree, tree_id, NullTVB, offset, 4, addr);
223 * Name: isis_dissect_nlpid_clv()
226 * Take apart a NLPID packet and display it. The NLPID (for intergrated
227 * ISIS, contains n network layer protocol IDs that the box supports.
228 * Our display buffer we use is upto 255 entries, 6 bytes per (0x00, )
229 * plus 1 for zero termination. We just just 256*6 for simplicity.
232 * u_char * : packet data
233 * int : offset into packet data where we are.
234 * guint : length of clv we are decoding
235 * frame_data * : frame data (complete frame)
236 * proto_tree * : protocol display tree to fill out. May be NULL
239 * void, but we will add to proto tree if !NULL.
242 isis_dissect_nlpid_clv(const u_char *pd, int offset,
243 guint length, frame_data *fd, proto_tree *tree ) {
247 int old_offset = offset;
249 if ( !tree ) return; /* nothing to do! */
251 while ( length-- > 0 ) {
253 s += sprintf ( s, ", " );
255 s += sprintf ( s, "0x%02x", pd[offset++] );
258 sprintf ( sbuf, "--none--" );
261 proto_tree_add_text ( tree, NullTVB, old_offset, hlen,
266 * Name: isis_dissect_clvs()
269 * Dispatch routine to shred all the CLVs in a packet. We just
270 * walk through the clv entries in the packet. For each one, we
271 * search the passed in valid clv's for this protocol (opts) for
272 * a matching code. If found, we add to the display tree and
273 * then call the dissector. If it is not, we just post an
274 * "unknown" clv entrie using the passed in unknown clv tree id.
277 * isis_clv_handle_t * : NULL dissector terminated array of codes
278 * and handlers (along with tree text and tree id's).
279 * int : length of CLV area.
280 * u_char * : packet data
281 * int : offset into packet data where we are.
282 * guint : length of clv we are decoding
283 * frame_data * : frame data (complete frame)
284 * proto_tree * : protocol display tree to fill out. May be NULL
285 * gint : unknown clv tree id
288 * void, but we will add to proto tree if !NULL.
291 isis_dissect_clvs(const isis_clv_handle_t *opts, int len, int id_length,
292 const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
293 gint unknown_tree_id ) {
298 proto_tree *clv_tree;
304 length = pd[offset++];
305 adj = (sizeof(code) + sizeof(length) + length);
308 isis_dissect_unknown(offset, adj, tree, fd,
309 "Short CLV header (%d vs %d)",
314 while ((opts[q].dissect != NULL )&&( opts[q].optcode != code )){
317 if ( opts[q].dissect ) {
319 /* adjust by 2 for code/len octets */
320 snprintf ( sbuf, sizeof(sbuf), "%s (%d)",
321 opts[q].tree_text, length );
322 ti = proto_tree_add_text(tree, NullTVB, offset - 2,
324 clv_tree = proto_item_add_subtree(ti,
329 opts[q].dissect(pd, offset, length, id_length, fd,
333 snprintf ( sbuf, sizeof(sbuf),
334 "Unknown code (%d:%d)", code, length );
335 ti = proto_tree_add_text(tree, NullTVB, offset - 2,
337 clv_tree = proto_item_add_subtree(ti,