Use #defines for vtype values, rather than numbers.
[obnox/wireshark/wip.git] / packet-bootparams.c
1 /* packet-bootparams.c
2  * Routines for bootparams dissection
3  *
4  * $Id: packet-bootparams.c,v 1.22 2002/08/28 21:00:08 jmayer Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
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 #include <string.h>
32 #include <glib.h>
33
34 #include "packet-rpc.h"
35 #include "packet-bootparams.h"
36
37 static int proto_bootparams = -1;
38 static int hf_bootparams_host = -1;
39 static int hf_bootparams_domain = -1;
40 static int hf_bootparams_fileid = -1;
41 static int hf_bootparams_filepath = -1;
42 static int hf_bootparams_hostaddr = -1;
43 static int hf_bootparams_routeraddr = -1;
44 static int hf_bootparams_addresstype = -1;
45
46 static gint ett_bootparams = -1;
47
48
49 static const value_string addr_type[] =
50 {
51         {       1,      "IPv4-ADDR"     },
52         {       0,      NULL            }
53 };
54
55 static int
56 dissect_bp_address(tvbuff_t *tvb, int offset, proto_tree *tree, int hfindex)
57 {
58         guint32 type;
59         guint32 ipaddr;
60
61
62         type = tvb_get_ntohl(tvb, offset);
63
64         offset = dissect_rpc_uint32(tvb, tree, hf_bootparams_addresstype, offset);
65
66         switch(type){
67         case 1:
68                 ipaddr = ((tvb_get_guint8(tvb, offset+3 )&0xff)<<24)
69                         |((tvb_get_guint8(tvb, offset+7 )&0xff)<<16)
70                         |((tvb_get_guint8(tvb, offset+11)&0xff)<<8 )
71                         |((tvb_get_guint8(tvb, offset+15)&0xff) );
72                 proto_tree_add_ipv4(tree, hfindex, tvb,
73                         offset, 16, g_ntohl(ipaddr));
74                 offset += 16;
75                 break;
76
77         default:
78                 break;
79         }
80
81         return offset;
82 }
83
84
85 static int
86 dissect_getfile_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
87 {
88         if ( tree )
89         {
90                 offset = dissect_rpc_string(tvb, tree, hf_bootparams_host, offset, NULL);
91                 offset = dissect_rpc_string(tvb, tree, hf_bootparams_fileid, offset, NULL);
92         }
93
94         return offset;
95 }
96
97 static int
98 dissect_getfile_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
99 {
100         if ( tree )
101         {
102                 offset = dissect_rpc_string(tvb, tree, hf_bootparams_host, offset, NULL);
103                 offset = dissect_bp_address(tvb, offset, tree, hf_bootparams_hostaddr);
104                 offset = dissect_rpc_string(tvb, tree, hf_bootparams_filepath, offset, NULL);
105         }
106
107         return offset;
108 }
109
110 static int
111 dissect_whoami_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
112 {
113         if ( tree )
114         {
115                 offset = dissect_bp_address(tvb, offset, tree, hf_bootparams_hostaddr);
116         }
117
118         return offset;
119 }
120
121 static int
122 dissect_whoami_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
123 {
124         if ( tree )
125         {
126                 offset = dissect_rpc_string(tvb, tree, hf_bootparams_host, offset, NULL);
127                 offset = dissect_rpc_string(tvb, tree, hf_bootparams_domain, offset, NULL);
128                 offset = dissect_bp_address(tvb, offset, tree, hf_bootparams_routeraddr);
129         }
130
131         return offset;
132 }
133
134 /* proc number, "proc name", dissect_request, dissect_reply */
135 /* NULL as function pointer means: type of arguments is "void". */
136 static const vsff bootparams1_proc[] = {
137         { BOOTPARAMSPROC_NULL, "NULL",
138                 NULL, NULL },
139         { BOOTPARAMSPROC_WHOAMI, "WHOAMI",
140                 dissect_whoami_call, dissect_whoami_reply },
141         { BOOTPARAMSPROC_GETFILE, "GETFILE",
142                 dissect_getfile_call, dissect_getfile_reply },
143         { 0, NULL, NULL, NULL }
144 };
145 /* end of Bootparams version 1 */
146
147
148 void
149 proto_register_bootparams(void)
150 {
151         static hf_register_info hf[] = {
152                 { &hf_bootparams_host, {
153                         "Client Host", "bootparams.host", FT_STRING, BASE_DEC,
154                         NULL, 0, "Client Host", HFILL }},
155                 { &hf_bootparams_domain, {
156                         "Client Domain", "bootparams.domain", FT_STRING, BASE_DEC,
157                         NULL, 0, "Client Domain", HFILL }},
158                 { &hf_bootparams_fileid, {
159                         "File ID", "bootparams.fileid", FT_STRING, BASE_DEC,
160                         NULL, 0, "File ID", HFILL }},
161                 { &hf_bootparams_filepath, {
162                         "File Path", "bootparams.filepath", FT_STRING, BASE_DEC,
163                         NULL, 0, "File Path", HFILL }},
164                 { &hf_bootparams_hostaddr, {
165                         "Client Address", "bootparams.hostaddr", FT_IPv4, BASE_DEC,
166                         NULL, 0, "Address", HFILL }},
167                 { &hf_bootparams_routeraddr, {
168                         "Router Address", "bootparams.routeraddr", FT_IPv4, BASE_DEC,
169                         NULL, 0, "Router Address", HFILL }},
170                 { &hf_bootparams_addresstype, {
171                         "Address Type", "bootparams.type", FT_UINT32, BASE_DEC,
172                         VALS(addr_type), 0, "Address Type", HFILL }},
173         };
174         static gint *ett[] = {
175                 &ett_bootparams,
176         };
177
178         proto_bootparams = proto_register_protocol("Boot Parameters",
179             "BOOTPARAMS", "bootparams");
180         proto_register_field_array(proto_bootparams, hf, array_length(hf));
181         proto_register_subtree_array(ett, array_length(ett));
182 }
183
184 void
185 proto_reg_handoff_bootparams(void)
186 {
187         /* Register the protocol as RPC */
188         rpc_init_prog(proto_bootparams, BOOTPARAMS_PROGRAM, ett_bootparams);
189         /* Register the procedure tables */
190         rpc_init_proc_table(BOOTPARAMS_PROGRAM, 1, bootparams1_proc);
191 }