aboutsummaryrefslogtreecommitdiffstats
path: root/packet-smb-common.c
blob: 067f401ead4de595597a5d136b332177a11f1047 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* packet-smb-common.c
 * Common routines for smb packet dissection
 * Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
 *
 * $Id: packet-smb-common.c,v 1.3 2000/02/14 04:22:22 guy Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@zing.org>
 * Copyright 1998 Gerald Combs
 *
 * Copied from packet-pop.c
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */



#include "packet-smb-common.h"



int display_ms_value( char *Name, int len, const u_char *pd, int offset,
		frame_data *fd, proto_tree *tree)

{/* display an entry from the tree and return the length */

  guint32  Temp32;
  
	if( len == 1)
  		Temp32 = GBYTE(pd, offset);
	else if( len == 2)
  		Temp32 = GSHORT(pd, offset);
	else if( len == 4)
  		Temp32 = GWORD(pd, offset);
  	
/* this is an error if we didn't hit one of those three */
  	else 
		return 0;

	proto_tree_add_text( tree, offset, len, "%s: %u", Name, Temp32);
	
	return len;
}	

int display_ms_string( char *Name, const u_char *pd, int offset,
		frame_data *fd, proto_tree *tree)

{/* display a string from the tree and return the amount to move offset */
  	
	proto_tree_add_text( tree, offset, strlen( &pd[offset]) + 1, "%s: %s ",
			Name, &pd[offset]);
	
	return 	strlen( &pd[offset]) + 1;
}


int display_unicode_string( char *Name, const u_char *pd, int offset,
		frame_data *fd, proto_tree *tree){

/* display a unicode string from the tree and return amount to move offset */

	char Temp[100], *OutPtr;
	const char *InPtr;
	
	InPtr = &pd[ offset];		/* point to unicode string */
	OutPtr = Temp;			/* point to temp space */
	
	while ( *InPtr){		/* copy every other byte */ 
		*OutPtr++ = *InPtr;
		InPtr += 2;
	} 
	*OutPtr = 0;			/* terminate out string */	
	  	
	proto_tree_add_text( tree, offset, strlen( Temp) * 2 + 2, "%s: %s ",
			Name, Temp);
	
	return 	strlen( Temp) * 2 + 2;
}


void
dissect_smb_unknown( const u_char *pd, int offset, frame_data *fd,
		proto_tree *tree){

/* display data as unknown */
  	
    proto_tree_add_text(tree, offset, END_OF_FRAME, "Data (%u bytes)",
                        END_OF_FRAME);

}



void
display_flags( struct flag_array_type *flag_array, int length,
	const u_char *pd, int offset, proto_tree *tree){

/* Display a bit fields using the flag_array information.  		*/
/* See packet-smb-common.h for definition of the flag_array structure 	*/


/*** NOTE: currently only handles values that are 1, 2, or 4 octets wide.*/
/***	This should be expanded to handle any bit width. 		 */

/* NOTE: the last entry must have the mask value = 0, this is the end of */
/*	array flag 							 */


	struct flag_array_type *array_ptr = flag_array;

	guint32 flags;
	
	switch (length) {

	case 1:
		flags = GBYTE( pd, offset);
		break;

	case 2:
		flags = GSHORT( pd, offset);
		break;

	case 4:
		flags = GWORD( pd, offset);
		break;

	default:
		g_assert_not_reached();
		return;
	}

	while( array_ptr->mask) {
		proto_tree_add_text( tree, offset, 2, "%s%s%s%s",
			decode_boolean_bitfield( flags, array_ptr->mask,
				length * 8, "",""),
			array_ptr->pre_string,
			((flags & array_ptr->mask) ? array_ptr->true_string :
				array_ptr->false_string),
			array_ptr->post_string);
	
		++array_ptr;
	}
}