Clear the Info column before fetching anything from the packet, so that
[obnox/wireshark/wip.git] / packet-ypserv.c
1 /* packet-ypserv.c
2  * Routines for ypserv dissection
3  *
4  * $Id: packet-ypserv.c,v 1.12 2001/01/03 06:55:34 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
32 #ifdef HAVE_SYS_TYPES_H
33 #include <sys/types.h>
34 #endif
35
36
37 #include "packet-rpc.h"
38 #include "packet-ypserv.h"
39
40 static int proto_ypserv = -1;
41 static int hf_ypserv_domain = -1;
42 static int hf_ypserv_servesdomain = -1;
43 static int hf_ypserv_map = -1;
44 static int hf_ypserv_key = -1;
45 static int hf_ypserv_value = -1;
46 static int hf_ypserv_status = -1;
47
48 static gint ett_ypserv = -1;
49
50 /* Dissect a domain call */
51 int dissect_domain_call(const u_char *pd, int offset, frame_data *fd,
52         proto_tree *tree)
53 {
54         if ( tree )
55         {
56                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_domain,NULL);
57         }
58         
59         return offset;
60 }
61
62 int dissect_domain_reply(const u_char *pd, int offset, frame_data *fd,
63         proto_tree *tree)
64 {
65         if ( !BYTES_ARE_IN_FRAME(offset, 4)) return offset;
66
67         if ( tree )
68         {
69                 proto_tree_add_boolean(tree, hf_ypserv_servesdomain, NullTVB,
70                         offset, 4, pntohl(&pd[offset]));
71         }
72
73         offset += 4;    
74         return offset;
75 }
76
77 /* Dissect a next call */
78 int dissect_next_call(const u_char *pd, int offset, frame_data *fd,
79         proto_tree *tree)
80 {
81         if ( tree )
82         {
83                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_domain,NULL);
84                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_map,NULL);
85                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_key,NULL);
86         }
87         
88         return offset;
89 }
90
91 int dissect_first_call(const u_char *pd, int offset, frame_data *fd,
92         proto_tree *tree)
93 {
94         if ( tree )
95         {
96                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_domain,NULL);
97                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_map,NULL);
98         }
99         
100         return offset;
101 }
102
103 int dissect_match_call(const u_char *pd, int offset, frame_data *fd,
104         proto_tree *tree)
105 {
106         if ( tree )
107         {
108                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_domain,NULL);
109                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_map,NULL);
110                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_key,NULL);
111         }
112         
113         return offset;
114 }
115
116 int dissect_match_reply(const u_char *pd, int offset, frame_data *fd,
117         proto_tree *tree)
118 {
119         if ( !BYTES_ARE_IN_FRAME(offset, 4)) return offset;
120
121         if ( tree )
122         {
123                 proto_tree_add_boolean(tree, hf_ypserv_status, NullTVB,
124                         offset, 4, pntohl(&pd[offset]));
125                 offset += 4;
126
127                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_value,NULL);
128         }
129         
130         return offset;
131 }
132
133 int dissect_firstnext_reply(const u_char *pd, int offset, frame_data *fd,
134         proto_tree *tree)
135 {
136         if ( !BYTES_ARE_IN_FRAME(offset, 4)) return offset;
137
138         if ( tree )
139         {
140                 proto_tree_add_boolean(tree, hf_ypserv_status, NullTVB,
141                         offset, 4, pntohl(&pd[offset]));
142                 offset += 4;
143
144                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_value,NULL);
145                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_key,NULL);
146         }
147         
148         return offset;
149 }
150
151
152 /* proc number, "proc name", dissect_request, dissect_reply */
153 /* NULL as function pointer means: take the generic one. */
154
155 /* someone please get me a version 1 trace */
156 const vsff ypserv1_proc[] = {
157     { 0, "NULL", NULL, NULL },
158     { YPPROC_ALL,   "ALL",      
159                 NULL, NULL },
160     { YPPROC_CLEAR, "CLEAR",        
161                 NULL, NULL },
162     { YPPROC_DOMAIN, "DOMAIN",
163                 NULL, NULL },
164     { YPPROC_DOMAIN_NONACK, "DOMAIN_NONACK",
165                 NULL, NULL },
166     { YPPROC_FIRST, "FIRST",        
167                 NULL, NULL },
168     { YPPROC_MAPLIST,   "MAPLIST",      
169                 NULL, NULL },
170     { YPPROC_MASTER,    "MASTER",       
171                 NULL, NULL },
172     { YPPROC_MATCH, "MATCH",        
173                 NULL, NULL },
174     { YPPROC_NEXT,  "NEXT",     
175                 NULL, NULL },
176     { YPPROC_ORDER, "ORDER",        
177                 NULL, NULL },
178     { YPPROC_XFR,   "XFR",      
179                 NULL, NULL },
180     { 0, NULL, NULL, NULL }
181 };
182 /* end of YPServ version 2 */
183
184 const vsff ypserv2_proc[] = {
185     { 0, "NULL", NULL, NULL },
186     { YPPROC_ALL,   "ALL",      
187                 NULL, NULL },
188     { YPPROC_CLEAR, "CLEAR",        
189                 NULL, NULL },
190     { YPPROC_DOMAIN, "DOMAIN",
191                 dissect_domain_call, dissect_domain_reply },
192     { YPPROC_DOMAIN_NONACK, "DOMAIN_NONACK",
193                 dissect_domain_call, dissect_domain_reply },
194     { YPPROC_FIRST, "FIRST",        
195                 dissect_first_call, dissect_firstnext_reply },
196     { YPPROC_MAPLIST,   "MAPLIST",      
197                 NULL, NULL },
198     { YPPROC_MASTER,    "MASTER",       
199                 NULL, NULL },
200     { YPPROC_MATCH, "MATCH",        
201                 dissect_match_call, dissect_match_reply },
202     { YPPROC_NEXT,  "NEXT",     
203                 dissect_next_call, dissect_firstnext_reply },
204     { YPPROC_ORDER, "ORDER",        
205                 NULL, NULL },
206     { YPPROC_XFR,   "XFR",      
207                 NULL, NULL },
208     { 0, NULL, NULL, NULL }
209 };
210 /* end of YPServ version 2 */
211
212
213 void
214 proto_register_ypserv(void)
215 {
216         static struct true_false_string okfailed = { "Ok", "Failed" };
217         static struct true_false_string yesno = { "Yes", "No" };
218                 
219         static hf_register_info hf[] = {
220                 { &hf_ypserv_domain, {
221                         "Domain", "ypserv.domain", FT_STRING, BASE_DEC,
222                         NULL, 0, "Domain" }},
223                 { &hf_ypserv_servesdomain, {
224                         "Serves Domain", "ypserv.servesdomain", FT_BOOLEAN, BASE_DEC,
225                         &yesno, 0, "Serves Domain" }},
226                 { &hf_ypserv_map, {
227                         "Map Name", "ypserv.map", FT_STRING, BASE_DEC,
228                         NULL, 0, "Map Name" }},
229                 { &hf_ypserv_key, {
230                         "Key", "ypserv.key", FT_STRING, BASE_DEC,
231                         NULL, 0, "Key" }},
232                 { &hf_ypserv_value, {
233                         "Value", "ypserv.value", FT_STRING, BASE_DEC,
234                         NULL, 0, "Value" }},
235                 { &hf_ypserv_status, {
236                         "Status", "ypserv.status", FT_BOOLEAN, BASE_DEC,
237                         &okfailed , 0, "Status" }},
238         };
239         static gint *ett[] = {
240                 &ett_ypserv,
241         };
242
243         proto_ypserv = proto_register_protocol("Yellow Pages Service",
244             "YPSERV", "ypserv");
245         proto_register_field_array(proto_ypserv, hf, array_length(hf));
246         proto_register_subtree_array(ett, array_length(ett));
247 }
248
249 void
250 proto_reg_handoff_ypserv(void)
251 {
252         /* Register the protocol as RPC */
253         rpc_init_prog(proto_ypserv, YPSERV_PROGRAM, ett_ypserv);
254         /* Register the procedure tables */
255         rpc_init_proc_table(YPSERV_PROGRAM, 1, ypserv1_proc);
256         rpc_init_proc_table(YPSERV_PROGRAM, 2, ypserv2_proc);
257 }