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