Make the Zebra dissector, and a routine it uses, static, as they're not
[obnox/wireshark/wip.git] / packet-smb-common.c
1 /* packet-smb-common.c
2  * Common routines for smb packet dissection
3  * Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
4  *
5  * $Id: packet-smb-common.c,v 1.4 2000/05/11 08:15:44 gram Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@zing.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * Copied from packet-pop.c
12  * 
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.
17  * 
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.
22  * 
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.
26  */
27
28
29
30 #include "packet-smb-common.h"
31
32
33
34 int display_ms_value( char *Name, int len, const u_char *pd, int offset,
35                 frame_data *fd, proto_tree *tree)
36
37 {/* display an entry from the tree and return the length */
38
39   guint32  Temp32;
40   
41         if( len == 1)
42                 Temp32 = GBYTE(pd, offset);
43         else if( len == 2)
44                 Temp32 = GSHORT(pd, offset);
45         else if( len == 4)
46                 Temp32 = GWORD(pd, offset);
47         
48 /* this is an error if we didn't hit one of those three */
49         else 
50                 return 0;
51
52         proto_tree_add_text( tree, NullTVB, offset, len, "%s: %u", Name, Temp32);
53         
54         return len;
55 }       
56
57 int display_ms_string( char *Name, const u_char *pd, int offset,
58                 frame_data *fd, proto_tree *tree)
59
60 {/* display a string from the tree and return the amount to move offset */
61         
62         proto_tree_add_text( tree, NullTVB, offset, strlen( &pd[offset]) + 1, "%s: %s ",
63                         Name, &pd[offset]);
64         
65         return  strlen( &pd[offset]) + 1;
66 }
67
68
69 int display_unicode_string( char *Name, const u_char *pd, int offset,
70                 frame_data *fd, proto_tree *tree){
71
72 /* display a unicode string from the tree and return amount to move offset */
73
74         char Temp[100], *OutPtr;
75         const char *InPtr;
76         
77         InPtr = &pd[ offset];           /* point to unicode string */
78         OutPtr = Temp;                  /* point to temp space */
79         
80         while ( *InPtr){                /* copy every other byte */ 
81                 *OutPtr++ = *InPtr;
82                 InPtr += 2;
83         } 
84         *OutPtr = 0;                    /* terminate out string */      
85                 
86         proto_tree_add_text( tree, NullTVB, offset, strlen( Temp) * 2 + 2, "%s: %s ",
87                         Name, Temp);
88         
89         return  strlen( Temp) * 2 + 2;
90 }
91
92
93 void
94 dissect_smb_unknown( const u_char *pd, int offset, frame_data *fd,
95                 proto_tree *tree){
96
97 /* display data as unknown */
98         
99     proto_tree_add_text(tree, NullTVB, offset, END_OF_FRAME, "Data (%u bytes)",
100                         END_OF_FRAME);
101
102 }
103
104
105
106 void
107 display_flags( struct flag_array_type *flag_array, int length,
108         const u_char *pd, int offset, proto_tree *tree){
109
110 /* Display a bit fields using the flag_array information.               */
111 /* See packet-smb-common.h for definition of the flag_array structure   */
112
113
114 /*** NOTE: currently only handles values that are 1, 2, or 4 octets wide.*/
115 /***    This should be expanded to handle any bit width.                 */
116
117 /* NOTE: the last entry must have the mask value = 0, this is the end of */
118 /*      array flag                                                       */
119
120
121         struct flag_array_type *array_ptr = flag_array;
122
123         guint32 flags;
124         
125         switch (length) {
126
127         case 1:
128                 flags = GBYTE( pd, offset);
129                 break;
130
131         case 2:
132                 flags = GSHORT( pd, offset);
133                 break;
134
135         case 4:
136                 flags = GWORD( pd, offset);
137                 break;
138
139         default:
140                 g_assert_not_reached();
141                 return;
142         }
143
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,
147                                 length * 8, "",""),
148                         array_ptr->pre_string,
149                         ((flags & array_ptr->mask) ? array_ptr->true_string :
150                                 array_ptr->false_string),
151                         array_ptr->post_string);
152         
153                 ++array_ptr;
154         }
155 }