Get rid of an unused variable.
[obnox/wireshark/wip.git] / packet-ypbind.c
1 /* packet-ypbind.c
2  * Routines for ypbind dissection
3  *
4  * $Id: packet-ypbind.c,v 1.11 2002/04/03 13:24:13 girlich 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, added dissectors for the commands
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27  */
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33
34 #ifdef HAVE_SYS_TYPES_H
35 #include <sys/types.h>
36 #endif
37
38
39 #include "packet-rpc.h"
40 #include "packet-ypbind.h"
41
42 static int proto_ypbind = -1;
43 static int hf_ypbind_domain = -1;
44 static int hf_ypbind_resp_type = -1;
45 static int hf_ypbind_error = -1;
46 static int hf_ypbind_addr = -1;
47 static int hf_ypbind_port = -1;
48 static int hf_ypbind_setdom_version = -1;
49
50 static gint ett_ypbind = -1;
51
52
53 static int
54 dissect_ypbind_domain_v2_request(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
55 {
56         /* domain */
57         offset = dissect_rpc_string(tvb, tree, 
58                         hf_ypbind_domain, offset, NULL);
59
60         return offset;
61 }
62
63 #define YPBIND_RESP_TYPE_SUCC_VAL       1
64 #define YPBIND_RESP_TYPE_FAIL_VAL       2
65 static const value_string resp_type_vals[] = {
66         {YPBIND_RESP_TYPE_SUCC_VAL,     "SUCC_VAL"},
67         {YPBIND_RESP_TYPE_FAIL_VAL,     "FAIL_VAL"},
68         {0, NULL}
69 };
70
71 #define YPBIND_ERROR_ERR        1
72 #define YPBIND_ERROR_NOSERV     2
73 #define YPBIND_ERROR_RESC       3
74 static const value_string error_vals[] = {
75         {YPBIND_ERROR_ERR,      "Internal error"},
76         {YPBIND_ERROR_NOSERV,   "No bound server for passed domain"},
77         {YPBIND_ERROR_RESC,     "System resource allocation failure"},
78         {0, NULL}
79 };
80
81 static int
82 dissect_ypbind_domain_v2_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
83 {
84         guint32 type;
85
86         /* response type */
87         type=tvb_get_ntohl(tvb, offset);
88         offset = dissect_rpc_uint32(tvb, tree, hf_ypbind_resp_type, offset);
89
90         switch(type){
91         case YPBIND_RESP_TYPE_SUCC_VAL:
92                 /* ip address */
93                 proto_tree_add_item(tree, hf_ypbind_addr, 
94                         tvb, offset, 4, FALSE);
95                 offset += 4;
96
97                 /* port */
98                 offset = dissect_rpc_uint32(tvb, tree, 
99                                 hf_ypbind_port, offset);
100                 
101                 break;
102         case YPBIND_RESP_TYPE_FAIL_VAL:
103                 /* error */
104                 offset = dissect_rpc_uint32(tvb, tree, 
105                                 hf_ypbind_resp_type, offset);
106                 break;
107         }
108
109         return offset;
110 }
111
112 static int
113 dissect_ypbind_setdomain_v2_request(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
114 {
115         /* domain */
116         offset = dissect_rpc_string(tvb, tree, 
117                         hf_ypbind_domain, offset, NULL);
118
119         /* ip address */
120         proto_tree_add_item(tree, hf_ypbind_addr, 
121                 tvb, offset, 4, FALSE);
122         offset += 4;
123
124         /* port */
125         offset = dissect_rpc_uint32(tvb, tree, 
126                         hf_ypbind_port, offset);
127                 
128         /* version */
129         offset = dissect_rpc_uint32(tvb, tree, 
130                         hf_ypbind_setdom_version, offset);
131                 
132         return offset;
133 }
134
135
136
137 /* proc number, "proc name", dissect_request, dissect_reply */
138 /* NULL as function pointer means: type of arguments is "void". */
139 static const vsff ypbind1_proc[] = {
140         { YPBINDPROC_NULL,      "NULL",         NULL,                           NULL },
141         { YPBINDPROC_DOMAIN,    "DOMAIN",               NULL,                           NULL },
142         { YPBINDPROC_SETDOM,    "SETDOMAIN",            NULL,                           NULL },
143         { 0,    NULL,           NULL,                           NULL }
144 };
145 /* end of YPBind version 1 */
146
147 static const vsff ypbind2_proc[] = {
148         { YPBINDPROC_NULL,      "NULL",         NULL,                           NULL },
149         { YPBINDPROC_DOMAIN,    "DOMAIN",       
150                 dissect_ypbind_domain_v2_request, dissect_ypbind_domain_v2_reply},
151         { YPBINDPROC_SETDOM,    "SETDOMAIN",
152                 dissect_ypbind_setdomain_v2_request, NULL},
153         { 0,    NULL,       NULL,               NULL }
154 };
155 /* end of YPBind version 2 */
156
157
158 void
159 proto_register_ypbind(void)
160 {
161         static hf_register_info hf[] = {
162                 { &hf_ypbind_domain, {
163                         "Domain", "ypbind.domain", FT_STRING, BASE_DEC,
164                         NULL, 0, "Name of the NIS/YP Domain", HFILL }},
165
166                 { &hf_ypbind_resp_type, {
167                         "Response Type", "ypbind.resp_type", FT_UINT32, BASE_DEC,
168                         VALS(resp_type_vals), 0, "Response type", HFILL }},
169
170                 { &hf_ypbind_error, {
171                         "Error", "ypbind.error", FT_UINT32, BASE_DEC,
172                         VALS(error_vals), 0, "YPBIND Error code", HFILL }},
173
174                 { &hf_ypbind_addr, {
175                         "IP Addr", "ypbind.addr", FT_IPv4, BASE_DEC,
176                         NULL, 0, "IP Address of server", HFILL }},
177
178                 { &hf_ypbind_port, {
179                         "Port", "ypbind.port", FT_UINT32, BASE_DEC,
180                         NULL, 0, "Port to use", HFILL }},
181
182                 { &hf_ypbind_setdom_version, {
183                         "Version", "ypbind.setdom.version", FT_UINT32, BASE_DEC,
184                         NULL, 0, "Version of setdom", HFILL }},
185
186         };
187
188         static gint *ett[] = {
189                 &ett_ypbind,
190         };
191
192         proto_ypbind = proto_register_protocol("Yellow Pages Bind",
193             "YPBIND", "ypbind");
194         proto_register_field_array(proto_ypbind, hf, array_length(hf));
195         proto_register_subtree_array(ett, array_length(ett));
196 }
197
198 void
199 proto_reg_handoff_ypbind(void)
200 {
201         /* Register the protocol as RPC */
202         rpc_init_prog(proto_ypbind, YPBIND_PROGRAM, ett_ypbind);
203         /* Register the procedure tables */
204         rpc_init_proc_table(YPBIND_PROGRAM, 1, ypbind1_proc);
205         rpc_init_proc_table(YPBIND_PROGRAM, 2, ypbind2_proc);
206 }