Move the routine to get a list of the network interfaces on the system
[obnox/wireshark/wip.git] / packet-ypserv.c
1 /* packet-ypserv.c
2  * Routines for ypserv dissection
3  *
4  * $Id: packet-ypserv.c,v 1.7 2000/01/07 22:05:42 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);
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_item(tree, hf_ypserv_servesdomain,
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);
84                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_map);
85                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_key);
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);
97                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_map);
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);
109                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_map);
110                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_key);
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_item(tree, hf_ypserv_status,
124                         offset, 4, pntohl(&pd[offset]));
125                 offset += 4;
126
127                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_value);
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_item(tree, hf_ypserv_status,
141                         offset, 4, pntohl(&pd[offset]));
142                 offset += 4;
143
144                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_value);
145                 offset = dissect_rpc_string(pd,offset,fd,tree,hf_ypserv_key);   }
146         
147         return offset;
148 }
149
150
151 /* proc number, "proc name", dissect_request, dissect_reply */
152 /* NULL as function pointer means: take the generic one. */
153
154 /* someone please get me a version 1 trace */
155 const vsff ypserv1_proc[] = {
156     { 0, "NULL", NULL, NULL },
157     { YPPROC_ALL,   "ALL",      
158                 NULL, NULL },
159     { YPPROC_CLEAR, "CLEAR",        
160                 NULL, NULL },
161     { YPPROC_DOMAIN, "DOMAIN",
162                 NULL, NULL },
163     { YPPROC_DOMAIN_NONACK, "DOMAIN_NONACK",
164                 NULL, NULL },
165     { YPPROC_FIRST, "FIRST",        
166                 NULL, NULL },
167     { YPPROC_MAPLIST,   "MAPLIST",      
168                 NULL, NULL },
169     { YPPROC_MASTER,    "MASTER",       
170                 NULL, NULL },
171     { YPPROC_MATCH, "MATCH",        
172                 NULL, NULL },
173     { YPPROC_NEXT,  "NEXT",     
174                 NULL, NULL },
175     { YPPROC_ORDER, "ORDER",        
176                 NULL, NULL },
177     { YPPROC_XFR,   "XFR",      
178                 NULL, NULL },
179     { 0, NULL, NULL, NULL }
180 };
181 /* end of YPServ version 2 */
182
183 const vsff ypserv2_proc[] = {
184     { 0, "NULL", NULL, NULL },
185     { YPPROC_ALL,   "ALL",      
186                 NULL, NULL },
187     { YPPROC_CLEAR, "CLEAR",        
188                 NULL, NULL },
189     { YPPROC_DOMAIN, "DOMAIN",
190                 dissect_domain_call, dissect_domain_reply },
191     { YPPROC_DOMAIN_NONACK, "DOMAIN_NONACK",
192                 dissect_domain_call, dissect_domain_reply },
193     { YPPROC_FIRST, "FIRST",        
194                 dissect_first_call, dissect_firstnext_reply },
195     { YPPROC_MAPLIST,   "MAPLIST",      
196                 NULL, NULL },
197     { YPPROC_MASTER,    "MASTER",       
198                 NULL, NULL },
199     { YPPROC_MATCH, "MATCH",        
200                 dissect_match_call, dissect_match_reply },
201     { YPPROC_NEXT,  "NEXT",     
202                 dissect_next_call, dissect_firstnext_reply },
203     { YPPROC_ORDER, "ORDER",        
204                 NULL, NULL },
205     { YPPROC_XFR,   "XFR",      
206                 NULL, NULL },
207     { 0, NULL, NULL, NULL }
208 };
209 /* end of YPServ version 2 */
210
211
212 void
213 proto_register_ypserv(void)
214 {
215         static struct true_false_string okfailed = { "Ok", "Failed" };
216         static struct true_false_string yesno = { "Yes", "No" };
217                 
218         static hf_register_info hf[] = {
219                 { &hf_ypserv_domain, {
220                         "Domain", "ypserv.domain", FT_STRING, BASE_DEC,
221                         NULL, 0, "Domain" }},
222                 { &hf_ypserv_servesdomain, {
223                         "Serves Domain", "ypserv.servesdomain", FT_BOOLEAN, BASE_DEC,
224                         &yesno, 0, "Serves Domain" }},
225                 { &hf_ypserv_map, {
226                         "Map Name", "ypserv.map", FT_STRING, BASE_DEC,
227                         NULL, 0, "Map Name" }},
228                 { &hf_ypserv_key, {
229                         "Key", "ypserv.key", FT_STRING, BASE_DEC,
230                         NULL, 0, "Key" }},
231                 { &hf_ypserv_value, {
232                         "Value", "ypserv.value", FT_STRING, BASE_DEC,
233                         NULL, 0, "Value" }},
234                 { &hf_ypserv_status, {
235                         "Status", "ypserv.status", FT_BOOLEAN, BASE_DEC,
236                         &okfailed , 0, "Status" }},
237         };
238         static gint *ett[] = {
239                 &ett_ypserv,
240         };
241
242         proto_ypserv = proto_register_protocol("Yellow Pages Service", "ypserv");
243         proto_register_field_array(proto_ypserv, hf, array_length(hf));
244         proto_register_subtree_array(ett, array_length(ett));
245
246         /* Register the protocol as RPC */
247         rpc_init_prog(proto_ypserv, YPSERV_PROGRAM, ett_ypserv);
248         /* Register the procedure tables */
249         rpc_init_proc_table(YPSERV_PROGRAM, 1, ypserv1_proc);
250         rpc_init_proc_table(YPSERV_PROGRAM, 2, ypserv2_proc);
251 }