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