From Anders Broman:
[obnox/wireshark/wip.git] / packet-ypbind.c
1 /* packet-ypbind.c
2  * Routines for ypbind dissection
3  *
4  * $Id: packet-ypbind.c,v 1.15 2002/11/01 00:48:39 sahlberg 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
35 #include "packet-rpc.h"
36 #include "packet-ypbind.h"
37
38 static int proto_ypbind = -1;
39 static int hf_ypbind_procedure_v1 = -1;
40 static int hf_ypbind_procedure_v2 = -1;
41 static int hf_ypbind_domain = -1;
42 static int hf_ypbind_resp_type = -1;
43 static int hf_ypbind_error = -1;
44 static int hf_ypbind_addr = -1;
45 static int hf_ypbind_port = -1;
46 static int hf_ypbind_setdom_version = -1;
47
48 static gint ett_ypbind = -1;
49
50
51 static int
52 dissect_ypbind_domain_v2_request(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
53 {
54         /* domain */
55         offset = dissect_rpc_string(tvb, tree,
56                         hf_ypbind_domain, offset, NULL);
57
58         return offset;
59 }
60
61 #define YPBIND_RESP_TYPE_SUCC_VAL       1
62 #define YPBIND_RESP_TYPE_FAIL_VAL       2
63 static const value_string resp_type_vals[] = {
64         {YPBIND_RESP_TYPE_SUCC_VAL,     "SUCC_VAL"},
65         {YPBIND_RESP_TYPE_FAIL_VAL,     "FAIL_VAL"},
66         {0, NULL}
67 };
68
69 #define YPBIND_ERROR_ERR        1
70 #define YPBIND_ERROR_NOSERV     2
71 #define YPBIND_ERROR_RESC       3
72 static const value_string error_vals[] = {
73         {YPBIND_ERROR_ERR,      "Internal error"},
74         {YPBIND_ERROR_NOSERV,   "No bound server for passed domain"},
75         {YPBIND_ERROR_RESC,     "System resource allocation failure"},
76         {0, NULL}
77 };
78
79 static int
80 dissect_ypbind_domain_v2_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
81 {
82         guint32 type;
83
84         /* response type */
85         type=tvb_get_ntohl(tvb, offset);
86         offset = dissect_rpc_uint32(tvb, tree, hf_ypbind_resp_type, offset);
87
88         switch(type){
89         case YPBIND_RESP_TYPE_SUCC_VAL:
90                 /* ip address */
91                 proto_tree_add_item(tree, hf_ypbind_addr,
92                         tvb, offset, 4, FALSE);
93                 offset += 4;
94
95                 /* port */
96                 offset = dissect_rpc_uint32(tvb, tree,
97                                 hf_ypbind_port, offset);
98
99                 break;
100         case YPBIND_RESP_TYPE_FAIL_VAL:
101                 /* error */
102                 offset = dissect_rpc_uint32(tvb, tree,
103                                 hf_ypbind_resp_type, offset);
104                 break;
105         }
106
107         return offset;
108 }
109
110 static int
111 dissect_ypbind_setdomain_v2_request(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
112 {
113         /* domain */
114         offset = dissect_rpc_string(tvb, tree,
115                         hf_ypbind_domain, offset, NULL);
116
117         /* ip address */
118         proto_tree_add_item(tree, hf_ypbind_addr,
119                 tvb, offset, 4, FALSE);
120         offset += 4;
121
122         /* port */
123         offset = dissect_rpc_uint32(tvb, tree,
124                         hf_ypbind_port, offset);
125
126         /* version */
127         offset = dissect_rpc_uint32(tvb, tree,
128                         hf_ypbind_setdom_version, offset);
129
130         return offset;
131 }
132
133
134
135 /* proc number, "proc name", dissect_request, dissect_reply */
136 /* NULL as function pointer means: type of arguments is "void". */
137 static const vsff ypbind1_proc[] = {
138         { YPBINDPROC_NULL,      "NULL",         NULL,                           NULL },
139         { YPBINDPROC_DOMAIN,    "DOMAIN",               NULL,                           NULL },
140         { YPBINDPROC_SETDOM,    "SETDOMAIN",            NULL,                           NULL },
141         { 0,    NULL,           NULL,                           NULL }
142 };
143 static const value_string ypbind1_proc_vals[] = {
144         { YPBINDPROC_NULL,      "NULL" },
145         { YPBINDPROC_DOMAIN,    "DOMAIN" },
146         { YPBINDPROC_SETDOM,    "SETDOMAIN" },
147         { 0,    NULL }
148 };
149 /* end of YPBind version 1 */
150
151 static const vsff ypbind2_proc[] = {
152         { YPBINDPROC_NULL,      "NULL",         NULL,                           NULL },
153         { YPBINDPROC_DOMAIN,    "DOMAIN",
154                 dissect_ypbind_domain_v2_request, dissect_ypbind_domain_v2_reply},
155         { YPBINDPROC_SETDOM,    "SETDOMAIN",
156                 dissect_ypbind_setdomain_v2_request, NULL},
157         { 0,    NULL,       NULL,               NULL }
158 };
159 static const value_string ypbind2_proc_vals[] = {
160         { YPBINDPROC_NULL,      "NULL" },
161         { YPBINDPROC_DOMAIN,    "DOMAIN" },
162         { YPBINDPROC_SETDOM,    "SETDOMAIN" },
163         { 0,    NULL }
164 };
165 /* end of YPBind version 2 */
166
167
168 void
169 proto_register_ypbind(void)
170 {
171         static hf_register_info hf[] = {
172                 { &hf_ypbind_procedure_v1, {
173                         "V1 Procedure", "ypbind.procedure_v1", FT_UINT32, BASE_DEC,
174                         VALS(ypbind1_proc_vals), 0, "V1 Procedure", HFILL }},
175                 { &hf_ypbind_procedure_v2, {
176                         "V2 Procedure", "ypbind.procedure_v2", FT_UINT32, BASE_DEC,
177                         VALS(ypbind2_proc_vals), 0, "V2 Procedure", HFILL }},
178                 { &hf_ypbind_domain, {
179                         "Domain", "ypbind.domain", FT_STRING, BASE_DEC,
180                         NULL, 0, "Name of the NIS/YP Domain", HFILL }},
181
182                 { &hf_ypbind_resp_type, {
183                         "Response Type", "ypbind.resp_type", FT_UINT32, BASE_DEC,
184                         VALS(resp_type_vals), 0, "Response type", HFILL }},
185
186                 { &hf_ypbind_error, {
187                         "Error", "ypbind.error", FT_UINT32, BASE_DEC,
188                         VALS(error_vals), 0, "YPBIND Error code", HFILL }},
189
190                 { &hf_ypbind_addr, {
191                         "IP Addr", "ypbind.addr", FT_IPv4, BASE_DEC,
192                         NULL, 0, "IP Address of server", HFILL }},
193
194                 { &hf_ypbind_port, {
195                         "Port", "ypbind.port", FT_UINT32, BASE_DEC,
196                         NULL, 0, "Port to use", HFILL }},
197
198                 { &hf_ypbind_setdom_version, {
199                         "Version", "ypbind.setdom.version", FT_UINT32, BASE_DEC,
200                         NULL, 0, "Version of setdom", HFILL }},
201
202         };
203
204         static gint *ett[] = {
205                 &ett_ypbind,
206         };
207
208         proto_ypbind = proto_register_protocol("Yellow Pages Bind",
209             "YPBIND", "ypbind");
210         proto_register_field_array(proto_ypbind, hf, array_length(hf));
211         proto_register_subtree_array(ett, array_length(ett));
212 }
213
214 void
215 proto_reg_handoff_ypbind(void)
216 {
217         /* Register the protocol as RPC */
218         rpc_init_prog(proto_ypbind, YPBIND_PROGRAM, ett_ypbind);
219         /* Register the procedure tables */
220         rpc_init_proc_table(YPBIND_PROGRAM, 1, ypbind1_proc, hf_ypbind_procedure_v1);
221         rpc_init_proc_table(YPBIND_PROGRAM, 2, ypbind2_proc, hf_ypbind_procedure_v2);
222 }