Reduce the CinemaScope-like proportions of the preferences dialog by
[obnox/wireshark/wip.git] / packet-ypserv.c
1 /* packet-ypserv.c
2  * Routines for ypserv dissection
3  *
4  * $Id: packet-ypserv.c,v 1.17 2001/06/18 02:17:58 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  * 2001 Ronnie Sahlberg <rsahlber@bigpond.net.au>
13  *   Added all remaining dissectors for this protocol
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28  */
29
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33
34
35 #ifdef HAVE_SYS_TYPES_H
36 #include <sys/types.h>
37 #endif
38
39
40 #include "packet-rpc.h"
41 #include "packet-ypserv.h"
42
43 static int proto_ypserv = -1;
44 static int hf_ypserv_domain = -1;
45 static int hf_ypserv_servesdomain = -1;
46 static int hf_ypserv_map = -1;
47 static int hf_ypserv_key = -1;
48 static int hf_ypserv_peer = -1;
49 static int hf_ypserv_more = -1;
50 static int hf_ypserv_ordernum = -1;
51 static int hf_ypserv_transid = -1;
52 static int hf_ypserv_prog = -1;
53 static int hf_ypserv_port = -1;
54 static int hf_ypserv_value = -1;
55 static int hf_ypserv_status = -1;
56 static int hf_ypserv_map_parms = -1;
57 static int hf_ypserv_xfrstat = -1;
58
59 static gint ett_ypserv = -1;
60 static gint ett_ypserv_map_parms = -1;
61
62 static const value_string ypstat[] =
63 {
64         {       1,      "YP_TRUE"       },
65         {       2,      "YP_NOMORE"     },
66         {       0,      "YP_FALSE"      },
67         {       -1,     "YP_NOMAP"      },
68         {       -2,     "YP_NODOM"      },
69         {       -3,     "YP_NOKEY"      },
70         {       -4,     "YP_BADOP"      },
71         {       -5,     "YP_BADDB"      },
72         {       -6,     "YP_YPERR"      },
73         {       -7,     "YP_BADARGS"    },
74         {       -8,     "YP_VERS"       },
75         {       0,      NULL    },
76 };
77
78 static const value_string xfrstat[] =
79 {
80         {       1,      "YPXFR_SUCC"    },
81         {       2,      "YPXFR_AGE"     },
82         {       -1,     "YPXFR_NOMAP"   },
83         {       -2,     "YPXFR_NODOM"   },
84         {       -3,     "YPXFR_RSRC"    },
85         {       -4,     "YPXFR_RPC"     },
86         {       -5,     "YPXFR_MADDR"   },
87         {       -6,     "YPXFR_YPERR"   },
88         {       -7,     "YPXFR_BADARGS" },
89         {       -8,     "YPXFR_DBM"     },
90         {       -9,     "YPXFR_FILE"    },
91         {       -10,    "YPXFR_SKEW"    },
92         {       -11,    "YPXFR_CLEAR"   },
93         {       -12,    "YPXFR_FORCE"   },
94         {       -13,    "YPXFR_XFRERR"  },
95         {       -14,    "YPXFR_REFUSED" },
96         {       0,      NULL    },
97 };
98
99 static int
100 dissect_domain_call(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
101 {
102         if ( tree )
103         {
104                 offset = dissect_rpc_string(tvb,pinfo,tree,hf_ypserv_domain,offset,NULL);
105         }
106         
107         return offset;
108 }
109
110 static int
111 dissect_domain_reply(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
112 {
113         if ( tree )
114         {
115                 proto_tree_add_boolean(tree, hf_ypserv_servesdomain, tvb,
116                         offset, 4, tvb_get_ntohl(tvb,offset));
117         }
118
119         offset += 4;    
120         return offset;
121 }
122
123 static int
124 dissect_match_call(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
125 {
126         if ( tree )
127         {
128                 offset = dissect_rpc_string(tvb, pinfo, tree, hf_ypserv_domain, offset, NULL);
129                 offset = dissect_rpc_string(tvb, pinfo, tree, hf_ypserv_map, offset, NULL);
130                 offset = dissect_rpc_string(tvb, pinfo, tree, hf_ypserv_key, offset, NULL);
131         }
132         
133         return offset;
134 }
135
136 static int
137 dissect_match_reply(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
138 {
139         if ( tree )
140         {
141                 offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_ypserv_status, offset);
142
143                 offset = dissect_rpc_string(tvb, pinfo, tree, hf_ypserv_value,offset, NULL);
144         }
145         
146         return offset;
147 }
148
149
150 static int
151 dissect_first_call(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
152 {
153         if ( tree )
154         {
155                 offset = dissect_rpc_string(tvb, pinfo, tree, hf_ypserv_domain, offset, NULL);
156                 offset = dissect_rpc_string(tvb, pinfo, tree, hf_ypserv_map, offset, NULL);
157                 offset = dissect_rpc_string(tvb, pinfo, tree, hf_ypserv_key, offset, NULL);
158         }
159         
160         return offset;
161 }
162
163
164 static int
165 dissect_firstnext_reply(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
166 {
167         if ( tree )
168         {
169                 offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_ypserv_status, offset);
170
171                 offset = dissect_rpc_string(tvb, pinfo, tree, hf_ypserv_value, offset, NULL);
172                 offset = dissect_rpc_string(tvb, pinfo, tree, hf_ypserv_key, offset, NULL);
173         }
174         
175         return offset;
176 }
177
178
179 static int
180 dissect_next_call(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
181 {
182         if ( tree )
183         {
184                 offset = dissect_rpc_string(tvb, pinfo, tree, hf_ypserv_domain, offset, NULL);
185                 offset = dissect_rpc_string(tvb, pinfo, tree, hf_ypserv_map, offset, NULL);
186                 offset = dissect_rpc_string(tvb, pinfo, tree, hf_ypserv_key, offset, NULL);
187         }
188         
189         return offset;
190 }
191
192 static int
193 dissect_xfr_call(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
194 {
195         proto_item *lock_item=NULL;
196         proto_tree *lock_tree=NULL;
197         guint32 tid;
198
199         if(tree){
200                 lock_item = proto_tree_add_item(tree, hf_ypserv_map_parms, tvb,
201                                 offset, tvb_length_remaining(tvb, offset)-12, FALSE);
202                 if(lock_item)
203                         lock_tree = proto_item_add_subtree(lock_item, ett_ypserv_map_parms);
204         }
205
206         offset = dissect_rpc_string(tvb, pinfo, lock_tree, hf_ypserv_domain, offset, NULL);
207         
208         offset = dissect_rpc_string(tvb, pinfo, lock_tree, hf_ypserv_map, offset, NULL);
209
210         offset = dissect_rpc_uint32(tvb, pinfo, lock_tree, hf_ypserv_ordernum, offset);
211
212         offset = dissect_rpc_string(tvb, pinfo, lock_tree, hf_ypserv_peer, offset, NULL);
213
214
215         tid=tvb_get_ntohl(tvb,offset);
216         tid=((tid&0x000000ff)<<24)|((tid&0x0000ff00)<<8)|((tid&0x00ff0000)>>8)|((tid&0xff000000)>>24);
217         proto_tree_add_ipv4(tree, hf_ypserv_transid, tvb, offset, 4, tid);
218         offset += 4;
219
220         offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_ypserv_prog, offset);
221         offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_ypserv_port, offset);
222
223         return offset;
224 }
225
226 static int
227 dissect_xfr_reply(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
228 {
229         guint32 tid;
230
231         tid=tvb_get_ntohl(tvb,offset);
232         tid=((tid&0x000000ff)<<24)|((tid&0x0000ff00)<<8)|((tid&0x00ff0000)>>8)|((tid&0xff000000)>>24);
233         proto_tree_add_ipv4(tree, hf_ypserv_transid, tvb, offset, 4, tid);
234         offset += 4;
235
236         offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_ypserv_xfrstat, offset);
237
238         return offset;
239 }
240
241 static int
242 dissect_ypreq_nokey(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
243 {
244
245         offset = dissect_rpc_string(tvb, pinfo, tree, hf_ypserv_domain, offset, NULL);
246         
247         offset = dissect_rpc_string(tvb, pinfo, tree, hf_ypserv_map, offset, NULL);
248
249         return offset;
250 }
251
252 static int
253 dissect_ypresp_all(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
254 {
255         gint32  more;
256
257         more = tvb_get_ntohl(tvb, offset);
258
259         offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_ypserv_more, offset);
260         if (more) {
261                 offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_ypserv_status, offset);
262                 offset = dissect_rpc_string(tvb, pinfo, tree, hf_ypserv_value, offset, NULL);
263                 offset = dissect_rpc_string(tvb, pinfo, tree, hf_ypserv_key, offset, NULL);
264         }
265
266         return offset;
267 }
268
269 static int
270 dissect_ypresp_master(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
271 {
272
273         offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_ypserv_status, offset);
274
275         offset = dissect_rpc_string(tvb, pinfo, tree, hf_ypserv_peer, offset, NULL);
276
277         return offset;
278 }
279
280
281 static int
282 dissect_ypresp_order(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
283 {
284
285         offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_ypserv_status, offset);
286
287         offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_ypserv_ordernum, offset);
288
289         return offset;
290 }
291
292
293 static int
294 dissect_ypresp_maplist(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
295 {
296         offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_ypserv_status, offset);
297         while(tvb_get_ntohl(tvb,offset)){
298                 offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_ypserv_more, offset);
299                 offset = dissect_rpc_string(tvb, pinfo, tree, hf_ypserv_map, offset, NULL);
300
301         }
302         offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_ypserv_more, offset);
303         return offset;
304 }
305
306
307 /* proc number, "proc name", dissect_request, dissect_reply */
308 /* NULL as function pointer means: type of arguments is "void". */
309
310 /* someone please get me a version 1 trace */
311 static const vsff ypserv1_proc[] = {
312     { 0, "NULL", NULL, NULL },
313     { YPPROC_DOMAIN, "DOMAIN",
314                 NULL, NULL },
315     { YPPROC_DOMAIN_NONACK, "DOMAIN_NONACK",
316                 NULL, NULL },
317     { YPPROC_MATCH, "MATCH",        
318                 NULL, NULL },
319     { YPPROC_FIRST, "FIRST",        
320                 NULL, NULL },
321     { YPPROC_NEXT,  "NEXT",     
322                 NULL, NULL },
323     { YPPROC_XFR,   "XFR",      
324                 NULL, NULL },
325     { YPPROC_CLEAR, "CLEAR",        
326                 NULL, NULL },
327     { YPPROC_ALL,   "ALL",      
328                 NULL, NULL },
329     { YPPROC_MASTER,    "MASTER",       
330                 NULL, NULL },
331     { YPPROC_ORDER, "ORDER",        
332                 NULL, NULL },
333     { YPPROC_MAPLIST,   "MAPLIST",      
334                 NULL, NULL },
335     { 0, NULL, NULL, NULL }
336 };
337 /* end of YPServ version 2 */
338
339 static const vsff ypserv2_proc[] = {
340     { 0, "NULL", NULL, NULL },
341     { YPPROC_DOMAIN, "DOMAIN",
342                 dissect_domain_call, dissect_domain_reply },
343     { YPPROC_DOMAIN_NONACK, "DOMAIN_NONACK",
344                 dissect_domain_call, dissect_domain_reply },
345     { YPPROC_MATCH, "MATCH",        
346                 dissect_match_call, dissect_match_reply },
347     { YPPROC_FIRST, "FIRST",        
348                 dissect_first_call, dissect_firstnext_reply },
349     { YPPROC_NEXT,  "NEXT",     
350                 dissect_next_call, dissect_firstnext_reply },
351     { YPPROC_XFR,   "XFR",      
352                 dissect_xfr_call, dissect_xfr_reply },
353     { YPPROC_CLEAR, "CLEAR",        
354                 NULL, NULL },
355     { YPPROC_ALL,   "ALL",      
356                 dissect_ypreq_nokey, dissect_ypresp_all },
357     { YPPROC_MASTER,    "MASTER",       
358                 dissect_ypreq_nokey, dissect_ypresp_master },
359     { YPPROC_ORDER, "ORDER",        
360                 dissect_ypreq_nokey, dissect_ypresp_order },
361     { YPPROC_MAPLIST,   "MAPLIST",      
362                 dissect_domain_call, dissect_ypresp_maplist },
363     { 0, NULL, NULL, NULL }
364 };
365 /* end of YPServ version 2 */
366
367
368 void
369 proto_register_ypserv(void)
370 {
371         /*static struct true_false_string okfailed = { "Ok", "Failed" };*/
372         static struct true_false_string yesno = { "Yes", "No" };
373                 
374         static hf_register_info hf[] = {
375                 { &hf_ypserv_domain, {
376                         "Domain", "ypserv.domain", FT_STRING, BASE_DEC,
377                         NULL, 0, "Domain", HFILL }},
378                 { &hf_ypserv_servesdomain, {
379                         "Serves Domain", "ypserv.servesdomain", FT_BOOLEAN, BASE_DEC,
380                         &yesno, 0, "Serves Domain", HFILL }},
381                 { &hf_ypserv_map, {
382                         "Map Name", "ypserv.map", FT_STRING, BASE_DEC,
383                         NULL, 0, "Map Name", HFILL }},
384                 { &hf_ypserv_peer, {
385                         "Peer Name", "ypserv.peer", FT_STRING, BASE_DEC,
386                         NULL, 0, "Peer Name", HFILL }},
387                 { &hf_ypserv_more, {
388                         "More", "ypserv.more", FT_BOOLEAN, BASE_NONE,
389                         &yesno, 0, "More", HFILL }},
390                 { &hf_ypserv_ordernum, {
391                         "Order Number", "ypserv.ordernum", FT_UINT32, BASE_DEC,
392                         NULL, 0, "Order Number for XFR", HFILL }},
393                 { &hf_ypserv_transid, {
394                         "Host Transport ID", "ypserv.transid", FT_IPv4, BASE_DEC,
395                         NULL, 0, "Host Transport ID to use for XFR Callback", HFILL }},
396                 { &hf_ypserv_prog, {
397                         "Program Number", "ypserv.prog", FT_UINT32, BASE_DEC,
398                         NULL, 0, "Program Number to use for XFR Callback", HFILL }},
399                 { &hf_ypserv_port, {
400                         "Port", "ypserv.port", FT_UINT32, BASE_DEC,
401                         NULL, 0, "Port to use for XFR Callback", HFILL }},
402                 { &hf_ypserv_key, {
403                         "Key", "ypserv.key", FT_STRING, BASE_DEC,
404                         NULL, 0, "Key", HFILL }},
405                 { &hf_ypserv_value, {
406                         "Value", "ypserv.value", FT_STRING, BASE_DEC,
407                         NULL, 0, "Value", HFILL }},
408                 { &hf_ypserv_status, {
409                         "Status", "ypserv.status", FT_INT32, BASE_DEC,
410                         VALS(ypstat) , 0, "Status", HFILL }},
411                 { &hf_ypserv_map_parms, {
412                         "YP Map Parameters", "ypserv.map_parms", FT_NONE, BASE_DEC,
413                         NULL, 0, "YP Map Parameters", HFILL }},
414                 { &hf_ypserv_xfrstat, {
415                         "Xfrstat", "ypserv.xfrstat", FT_INT32, BASE_DEC,
416                         VALS(xfrstat), 0, "Xfrstat", HFILL }},
417         };
418         static gint *ett[] = {
419                 &ett_ypserv,
420                 &ett_ypserv_map_parms,
421         };
422
423         proto_ypserv = proto_register_protocol("Yellow Pages Service",
424             "YPSERV", "ypserv");
425         proto_register_field_array(proto_ypserv, hf, array_length(hf));
426         proto_register_subtree_array(ett, array_length(ett));
427 }
428
429 void
430 proto_reg_handoff_ypserv(void)
431 {
432         /* Register the protocol as RPC */
433         rpc_init_prog(proto_ypserv, YPSERV_PROGRAM, ett_ypserv);
434         /* Register the procedure tables */
435         rpc_init_proc_table(YPSERV_PROGRAM, 1, ypserv1_proc);
436         rpc_init_proc_table(YPSERV_PROGRAM, 2, ypserv2_proc);
437 }