fa5a0af688556d83e81a6686a912c55f24f254c5
[obnox/wireshark/wip.git] / packet-bootparams.c
1 /* packet-bootparams.c
2  * Routines for bootparams dissection
3  *
4  * $Id: packet-bootparams.c,v 1.9 2000/04/04 06:46:24 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@zing.org>
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
53 static gint ett_bootparams = -1;
54
55 int dissect_bp_address(const u_char *pd, int offset, frame_data *fd,
56         proto_tree *tree, int hfindex)
57 {
58         guint32 type;
59         guint32 ipaddr;
60
61         /* get the address type */
62         if ( !BYTES_ARE_IN_FRAME(offset, 1)) return offset;
63         type = pntohl(&pd[offset]); /* type of address */
64 #if 0
65         proto_tree_add_item(tree, hf_bootparams_addresstype,
66                 offset, 4, type);
67 #endif
68         offset += 4;
69
70         if ( type != 1 ) /* only know how to handle this type of address */
71         {
72                 return offset;
73         }
74
75         /* get the address itself - weird ass format */
76         if ( ! BYTES_ARE_IN_FRAME(offset, 16)) return offset;
77         ipaddr = (pd[offset+3]<<24) + (pd[offset+7]<<16) +
78                 (pd[offset+11]<<8) + (pd[offset+15]);
79         proto_tree_add_item(tree, hfindex, 
80                 offset, 16, ntohl(ipaddr));
81         offset += 16;
82
83         return offset;
84 }
85
86
87 /* Dissect a getfile call */
88 int dissect_getfile_call(const u_char *pd, int offset, frame_data *fd,
89         proto_tree *tree)
90 {
91         if ( tree )
92         {
93                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_bootparams_host,NULL);
94                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_bootparams_fileid,NULL);
95         }
96         
97         return offset;
98 }
99
100 /* Dissect a getfile reply */
101 int dissect_getfile_reply(const u_char *pd, int offset, frame_data *fd,
102         proto_tree *tree)
103 {
104         if ( tree )
105         {
106                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_bootparams_host,NULL);
107                 offset = dissect_bp_address(pd,offset,fd,tree,hf_bootparams_hostaddr);
108                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_bootparams_filepath,NULL);
109         }
110         
111         return offset;
112 }
113
114 /* Dissect a whoami call */
115 int dissect_whoami_call(const u_char *pd, int offset, frame_data *fd,
116         proto_tree *tree)
117 {
118         if ( tree )
119         {
120                 offset = dissect_bp_address(pd,offset,fd,tree,hf_bootparams_hostaddr);
121         }
122         
123         return offset;
124 }
125
126 /* Dissect a whoami reply */
127 int dissect_whoami_reply(const u_char *pd, int offset, frame_data *fd,
128         proto_tree *tree)
129 {
130         if ( tree )
131         {
132                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_bootparams_host,NULL);
133                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_bootparams_domain,NULL);
134                 offset = dissect_bp_address(pd,offset,fd,tree,hf_bootparams_routeraddr);
135         }
136         
137         return offset;
138 }
139
140 /* proc number, "proc name", dissect_request, dissect_reply */
141 /* NULL as function pointer means: take the generic one. */
142 const vsff bootparams1_proc[] = {
143         { BOOTPARAMSPROC_NULL, "NULL",
144                 NULL, NULL },
145         { BOOTPARAMSPROC_WHOAMI, "WHOAMI", 
146                 dissect_whoami_call, dissect_whoami_reply },
147         { BOOTPARAMSPROC_GETFILE, "GETFILE", 
148                 dissect_getfile_call, dissect_getfile_reply },
149         { 0, NULL, NULL, NULL }
150 };
151 /* end of Bootparams version 1 */
152
153
154 void
155 proto_register_bootparams(void)
156 {
157         static hf_register_info hf[] = {
158                 { &hf_bootparams_host, {
159                         "Client Host", "bootparams.host", FT_STRING, BASE_DEC,
160                         NULL, 0, "Client Host" }},
161                 { &hf_bootparams_domain, {
162                         "Client Domain", "bootparams.domain", FT_STRING, BASE_DEC,
163                         NULL, 0, "Client Domain" }},
164                 { &hf_bootparams_fileid, {
165                         "File ID", "bootparams.fileid", FT_STRING, BASE_DEC,
166                         NULL, 0, "File ID" }},
167                 { &hf_bootparams_filepath, {
168                         "File Path", "bootparams.filepath", FT_STRING, BASE_DEC,
169                         NULL, 0, "File Path" }},
170                 { &hf_bootparams_hostaddr, {
171                         "Client Address", "bootparams.hostaddr", FT_IPv4, BASE_DEC,
172                         NULL, 0, "Address" }},
173                 { &hf_bootparams_routeraddr, {
174                         "Router Address", "bootparams.routeraddr", FT_IPv4, BASE_DEC,
175                         NULL, 0, "Router Address" }},
176         };
177         static gint *ett[] = {
178                 &ett_bootparams,
179         };
180
181         proto_bootparams = proto_register_protocol("Boot Parameters", "bootparams");
182         proto_register_field_array(proto_bootparams, hf, array_length(hf));
183         proto_register_subtree_array(ett, array_length(ett));
184 }
185
186 void
187 proto_reg_handoff_bootparams(void)
188 {
189         /* Register the protocol as RPC */
190         rpc_init_prog(proto_bootparams, BOOTPARAMS_PROGRAM, ett_bootparams);
191         /* Register the procedure tables */
192         rpc_init_proc_table(BOOTPARAMS_PROGRAM, 1, bootparams1_proc);
193 }