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