Make various "value_string" tables "const"; this allows the compiler to
[obnox/wireshark/wip.git] / packet-mount.c
1 /* packet-mount.c
2  * Routines for mount dissection
3  *
4  * $Id: packet-mount.c,v 1.6 1999/11/19 23:23:41 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@unicom.net>
8  * Copyright 1998 Gerald Combs
9  *
10  * Copied from packet-smb.c
11  *
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.
16  *
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.
21  *
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.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31
32 #ifdef HAVE_SYS_TYPES_H
33 #include <sys/types.h>
34 #endif
35
36
37 #include "packet-rpc.h"
38 #include "packet-mount.h"
39 #include "packet-nfs.h"
40
41
42 static int proto_mount = -1;
43 static int hf_mount_path = -1;
44 static int hf_mount_status = -1;
45 static int hf_mount_flavors = -1;
46 static int hf_mount_flavor = -1;
47
48 static gint ett_mount = -1;
49
50 int dissect_mount_dirpath_call(const u_char *pd, int offset, frame_data *fd,
51         proto_tree *tree)
52 {
53         if ( tree )
54         {
55                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_mount_path);
56         }
57         
58         return offset;
59 }
60
61
62 /* proc number, "proc name", dissect_request, dissect_reply */
63 /* NULL as function pointer means: take the generic one. */
64 /* Mount protocol version 1, RFC 1094 */
65 const vsff mount1_proc[] = {
66     { 0, "NULL", NULL, NULL },
67     { MOUNTPROC_MNT,   "MNT",      
68                 dissect_mount_dirpath_call, NULL },
69     { MOUNTPROC_DUMP,    "DUMP",
70                 NULL, NULL },
71     { MOUNTPROC_UMNT, "UMNT",        
72                 dissect_mount_dirpath_call, NULL },
73     { MOUNTPROC_UMNTALL, "UMNTALL",
74                 NULL, NULL },
75     { MOUNTPROC_EXPORT, "EXPORT",
76                 NULL, NULL },
77     { 0, NULL, NULL, NULL }
78 };
79 /* end of mount version 1 */
80
81
82 /* RFC 1813, Page 107 */
83 static const value_string mount3_mountstat3[] = 
84 {
85         {       0,      "OK" },
86         {       1,      "ERR_PERM" },
87         {       2,      "ERR_NOENT" },
88         {       5,      "ERR_IO" },
89         {       13,     "ERR_ACCESS" },
90         {       20,     "ERR_NOTDIR" },
91         {       22,     "ERR_INVAL" },
92         {       63,     "ERR_NAMETOOLONG" },
93         {       10004,  "ERR_NOTSUPP" },
94         {       10006,  "ERR_SERVERFAULT" },
95         {       0,      NULL }
96 };
97
98
99 /* RFC 1813, Page 107 */
100 int
101 dissect_mountstat3(const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
102         int hfindex, guint32* status)
103 {
104         guint32 mountstat3;
105
106         if (!BYTES_ARE_IN_FRAME(offset,4)) return offset;
107         mountstat3 = EXTRACT_UINT(pd, offset+0);
108
109         if (tree) {
110                 proto_tree_add_item(tree, hfindex, offset, 4, mountstat3);
111         }
112         
113         offset += 4;
114         *status = mountstat3;
115         return offset;
116 }
117
118
119 /* RFC 1831, Page 109 */
120 int dissect_mount3_mnt_reply(const u_char *pd, int offset, frame_data *fd,
121         proto_tree *tree)
122 {
123         guint32 status;
124         guint32 auth_flavors;
125         guint32 auth_flavor;
126         guint32 auth_flavor_i;
127         
128         offset = dissect_mountstat3(pd, offset, fd, tree, hf_mount_status, &status);
129         switch (status) {
130                 case 0:
131                         offset = dissect_nfs_fh3(pd,offset,fd,tree,"fhandle");
132                         if (!BYTES_ARE_IN_FRAME(offset,4)) return offset;
133                         auth_flavors = EXTRACT_UINT(pd,offset+0);
134                         proto_tree_add_item(tree,hf_mount_flavors,
135                                 offset, 4, auth_flavors);
136                         offset += 4;
137                         for (auth_flavor_i = 0 ; auth_flavor_i < hf_mount_flavors ; auth_flavor_i++) {
138                                 if (!BYTES_ARE_IN_FRAME(offset,4)) return offset;
139                                 auth_flavor = EXTRACT_UINT(pd,offset+0);
140                                 proto_tree_add_item(tree,hf_mount_flavor,
141                                         offset, 4, auth_flavor);
142                                 offset += 4;
143                         }
144                 break;
145                 default:
146                         /* void */
147                 break;
148         }
149         
150         return offset;
151 }
152
153 /* Mount protocol version 3, RFC 1813 */
154 const vsff mount3_proc[] = {
155         { 0, "NULL", NULL, NULL },
156         { MOUNTPROC_MNT, "MNT",
157                 dissect_mount_dirpath_call, dissect_mount3_mnt_reply },
158         { MOUNTPROC_DUMP, "DUMP",
159                 NULL, NULL },
160         { MOUNTPROC_UMNT, "UMNT",
161                 dissect_mount_dirpath_call, NULL },
162         { MOUNTPROC_UMNTALL, "UMNTALL",
163                 NULL, NULL },
164         { MOUNTPROC_EXPORT, "EXPORT",
165                 NULL, NULL },
166         { 0, NULL, NULL, NULL }
167 };
168 /* end of Mount protocol version 3 */
169
170
171 void
172 proto_register_mount(void)
173 {
174         static hf_register_info hf[] = {
175                 { &hf_mount_path, {
176                         "Path", "mount.path", FT_STRING, BASE_DEC,
177                         NULL, 0, "Path" }},
178                 { &hf_mount_status, {
179                         "Status", "mount.status", FT_UINT32, BASE_DEC,
180                         VALS(mount3_mountstat3), 0, "Status" }},
181                 { &hf_mount_flavors, {
182                         "Flavors", "mount.flavors", FT_UINT32, BASE_DEC,
183                         NULL, 0, "Flavors" }},
184                 { &hf_mount_flavor, {
185                         "Flavor", "mount.flavor", FT_UINT32, BASE_DEC,
186                         VALS(rpc_auth_flavor), 0, "Flavor" }},
187         };
188         static gint *ett[] = {
189                 &ett_mount,
190         };
191
192         proto_mount = proto_register_protocol("Mount Service", "mount");
193         proto_register_field_array(proto_mount, hf, array_length(hf));
194         proto_register_subtree_array(ett, array_length(ett));
195
196         /* Register the protocol as RPC */
197         rpc_init_prog(proto_mount, MOUNT_PROGRAM, ett_mount);
198         /* Register the procedure tables */
199         rpc_init_proc_table(MOUNT_PROGRAM, 1, mount1_proc);
200         rpc_init_proc_table(MOUNT_PROGRAM, 3, mount3_proc);
201 }