2 * Common routines for smb packet dissection
3 * Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
5 * $Id: packet-smb-common.c,v 1.4 2000/05/11 08:15:44 gram Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@zing.org>
9 * Copyright 1998 Gerald Combs
11 * Copied from packet-pop.c
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #include "packet-smb-common.h"
34 int display_ms_value( char *Name, int len, const u_char *pd, int offset,
35 frame_data *fd, proto_tree *tree)
37 {/* display an entry from the tree and return the length */
42 Temp32 = GBYTE(pd, offset);
44 Temp32 = GSHORT(pd, offset);
46 Temp32 = GWORD(pd, offset);
48 /* this is an error if we didn't hit one of those three */
52 proto_tree_add_text( tree, NullTVB, offset, len, "%s: %u", Name, Temp32);
57 int display_ms_string( char *Name, const u_char *pd, int offset,
58 frame_data *fd, proto_tree *tree)
60 {/* display a string from the tree and return the amount to move offset */
62 proto_tree_add_text( tree, NullTVB, offset, strlen( &pd[offset]) + 1, "%s: %s ",
65 return strlen( &pd[offset]) + 1;
69 int display_unicode_string( char *Name, const u_char *pd, int offset,
70 frame_data *fd, proto_tree *tree){
72 /* display a unicode string from the tree and return amount to move offset */
74 char Temp[100], *OutPtr;
77 InPtr = &pd[ offset]; /* point to unicode string */
78 OutPtr = Temp; /* point to temp space */
80 while ( *InPtr){ /* copy every other byte */
84 *OutPtr = 0; /* terminate out string */
86 proto_tree_add_text( tree, NullTVB, offset, strlen( Temp) * 2 + 2, "%s: %s ",
89 return strlen( Temp) * 2 + 2;
94 dissect_smb_unknown( const u_char *pd, int offset, frame_data *fd,
97 /* display data as unknown */
99 proto_tree_add_text(tree, NullTVB, offset, END_OF_FRAME, "Data (%u bytes)",
107 display_flags( struct flag_array_type *flag_array, int length,
108 const u_char *pd, int offset, proto_tree *tree){
110 /* Display a bit fields using the flag_array information. */
111 /* See packet-smb-common.h for definition of the flag_array structure */
114 /*** NOTE: currently only handles values that are 1, 2, or 4 octets wide.*/
115 /*** This should be expanded to handle any bit width. */
117 /* NOTE: the last entry must have the mask value = 0, this is the end of */
121 struct flag_array_type *array_ptr = flag_array;
128 flags = GBYTE( pd, offset);
132 flags = GSHORT( pd, offset);
136 flags = GWORD( pd, offset);
140 g_assert_not_reached();
144 while( array_ptr->mask) {
145 proto_tree_add_text( tree, NullTVB, offset, 2, "%s%s%s%s",
146 decode_boolean_bitfield( flags, array_ptr->mask,
148 array_ptr->pre_string,
149 ((flags & array_ptr->mask) ? array_ptr->true_string :
150 array_ptr->false_string),
151 array_ptr->post_string);