2 * Routines for portmap dissection
4 * $Id: packet-portmap.c,v 1.34 2002/04/03 13:24:12 girlich Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * Copied from packet-smb.c
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.
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.
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.
32 #ifdef HAVE_SYS_TYPES_H
33 #include <sys/types.h>
37 #include "packet-rpc.h"
38 #include "packet-portmap.h"
44 * RFC 1833, "Binding Protocols for ONC RPC Version 2".
47 static int proto_portmap = -1;
48 static int hf_portmap_proto = -1;
49 static int hf_portmap_prog = -1;
50 static int hf_portmap_proc = -1;
51 static int hf_portmap_version = -1;
52 static int hf_portmap_port = -1;
53 static int hf_portmap_answer = -1;
54 static int hf_portmap_args = -1;
55 static int hf_portmap_result = -1;
56 static int hf_portmap_rpcb = -1;
57 static int hf_portmap_rpcb_prog = -1;
58 static int hf_portmap_rpcb_version = -1;
59 static int hf_portmap_rpcb_netid = -1;
60 static int hf_portmap_rpcb_addr = -1;
61 static int hf_portmap_rpcb_owner = -1;
62 static int hf_portmap_uaddr = -1;
65 static gint ett_portmap = -1;
66 static gint ett_portmap_rpcb = -1;
67 static gint ett_portmap_entry = -1;
70 /* Dissect a getport call */
71 int dissect_getport_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
79 prog = tvb_get_ntohl(tvb, offset+0);
80 proto_tree_add_uint_format(tree, hf_portmap_prog, tvb,
81 offset, 4, prog, "Program: %s (%u)",
82 rpc_prog_name(prog), prog);
83 proto_tree_add_item(tree, hf_portmap_version, tvb,
86 proto = tvb_get_ntohl(tvb, offset+8);
87 proto_tree_add_uint_format(tree, hf_portmap_proto, tvb,
88 offset+8, 4, proto, "Proto: %s (%u)", ipprotostr(proto), proto);
90 proto_tree_add_item(tree, hf_portmap_port, tvb,
97 int dissect_getport_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
100 offset = dissect_rpc_uint32(tvb, tree, hf_portmap_port,
105 /* Dissect a 'set' call */
106 int dissect_set_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
114 prog = tvb_get_ntohl(tvb, offset+0);
115 proto_tree_add_uint_format(tree, hf_portmap_prog, tvb,
116 offset, 4, prog, "Program: %s (%d)",
117 rpc_prog_name(prog), prog);
118 proto_tree_add_item(tree, hf_portmap_version, tvb,
121 proto = tvb_get_ntohl(tvb, offset+8);
122 proto_tree_add_uint_format(tree, hf_portmap_proto,tvb,
123 offset+8, 4, proto, "Proto: %s (%d)", ipprotostr(proto), proto);
125 proto_tree_add_item(tree, hf_portmap_port, tvb,
126 offset+12, 4, FALSE);
132 /* Dissect a 'unset' call */
133 int dissect_unset_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
141 prog = tvb_get_ntohl(tvb, offset+0);
142 proto_tree_add_uint_format(tree, hf_portmap_prog, tvb,
143 offset, 4, prog, "Program: %s (%d)",
144 rpc_prog_name(prog), prog);
145 proto_tree_add_item(tree, hf_portmap_version, tvb,
148 proto = tvb_get_ntohl(tvb, offset+8);
149 proto_tree_add_uint(tree, hf_portmap_proto, tvb,
152 proto_tree_add_item(tree, hf_portmap_port, tvb,
153 offset+12, 4, FALSE);
159 int dissect_set_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
162 offset = dissect_rpc_bool(tvb, tree, hf_portmap_answer,
168 dissect_dump_entry(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
171 int prog, version, proto, port;
172 proto_item *ti, *subtree;
174 prog = tvb_get_ntohl(tvb, offset+0);
175 version = tvb_get_ntohl(tvb, offset+4);
176 proto = tvb_get_ntohl(tvb, offset+8);
177 port = tvb_get_ntohl(tvb, offset+12);
180 ti = proto_tree_add_text(tree, tvb, offset, 16,
181 "Map Entry: %s (%u) V%d",
182 rpc_prog_name(prog), prog, version);
183 subtree = proto_item_add_subtree(ti, ett_portmap_entry);
185 proto_tree_add_uint_format(subtree, hf_portmap_prog, tvb,
187 "Program: %s (%u)", rpc_prog_name(prog), prog);
188 proto_tree_add_uint(subtree, hf_portmap_version, tvb,
189 offset+4, 4, version);
190 proto_tree_add_uint_format(subtree, hf_portmap_proto, tvb,
192 "Protocol: %s (0x%02x)", ipprotostr(proto), proto);
193 proto_tree_add_uint(subtree, hf_portmap_port, tvb,
200 int dissect_dump_reply(tvbuff_t *tvb, int offset, packet_info *pinfo,
203 offset = dissect_rpc_list(tvb, pinfo, tree, offset,
208 /* Dissect a callit call */
209 int dissect_callit_call(tvbuff_t *tvb, int offset, packet_info *pinfo,
212 guint32 prog, vers, proc;
214 prog = tvb_get_ntohl(tvb, offset+0);
217 proto_tree_add_uint_format(tree, hf_portmap_prog, tvb,
218 offset, 4, prog, "Program: %s (%u)",
219 rpc_prog_name(prog), prog);
222 vers = tvb_get_ntohl(tvb, offset+4);
225 proto_tree_add_uint(tree, hf_portmap_version, tvb,
229 proc = tvb_get_ntohl(tvb, offset+8);
232 proto_tree_add_uint_format(tree, hf_portmap_proc, tvb,
233 offset+8, 4, proc, "Procedure: %s (%u)",
234 rpc_proc_name(prog, vers, proc), proc);
239 /* Dissect the arguments for this procedure.
240 Make the columns non-writable, so the dissector won't change
241 them out from under us. */
242 col_set_writable(pinfo->cinfo, FALSE);
243 offset = dissect_rpc_indir_call(tvb, pinfo, tree, offset,
244 hf_portmap_args, prog, vers, proc);
249 /* Dissect a callit reply */
250 int dissect_callit_reply(tvbuff_t *tvb, int offset, packet_info *pinfo,
255 proto_tree_add_item(tree, hf_portmap_port, tvb,
260 /* Dissect the result of this procedure.
261 Make the columns non-writable, so the dissector won't change
262 them out from under us. */
263 col_set_writable(pinfo->cinfo, FALSE);
264 offset = dissect_rpc_indir_reply(tvb, pinfo, tree, offset,
265 hf_portmap_result, hf_portmap_prog, hf_portmap_version,
271 /* proc number, "proc name", dissect_request, dissect_reply */
272 /* NULL as function pointer means: type of arguments is "void". */
273 static const vsff portmap1_proc[] = {
274 { PORTMAPPROC_NULL, "NULL", NULL, NULL },
275 { PORTMAPPROC_SET, "SET", NULL, NULL },
276 { PORTMAPPROC_UNSET, "UNSET", NULL, NULL },
277 { PORTMAPPROC_GETPORT, "GETPORT", NULL, NULL },
278 { PORTMAPPROC_DUMP, "DUMP", NULL, NULL },
279 { PORTMAPPROC_CALLIT, "CALLIT", NULL, NULL },
280 { 0, NULL, NULL, NULL }
282 /* end of Portmap version 1 */
284 static const vsff portmap2_proc[] = {
285 { PORTMAPPROC_NULL, "NULL",
287 { PORTMAPPROC_SET, "SET",
288 dissect_set_call, dissect_set_reply },
289 { PORTMAPPROC_UNSET, "UNSET",
290 dissect_unset_call, dissect_set_reply },
291 { PORTMAPPROC_GETPORT, "GETPORT",
292 dissect_getport_call, dissect_getport_reply },
293 { PORTMAPPROC_DUMP, "DUMP",
294 NULL, dissect_dump_reply },
295 { PORTMAPPROC_CALLIT, "CALLIT",
296 dissect_callit_call, dissect_callit_reply },
297 { 0, NULL, NULL, NULL }
299 /* end of Portmap version 2 */
302 /* RFC 1833, Page 3 */
304 dissect_rpcb(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
306 proto_item* rpcb_item = NULL;
307 proto_tree* rpcb_tree = NULL;
308 int old_offset = offset;
312 rpcb_item = proto_tree_add_item(tree, hf_portmap_rpcb, tvb,
315 rpcb_tree = proto_item_add_subtree(rpcb_item, ett_portmap_rpcb);
318 prog = tvb_get_ntohl(tvb, offset);
320 proto_tree_add_uint_format(rpcb_tree, hf_portmap_rpcb_prog, tvb,
322 "Program: %s (%u)", rpc_prog_name(prog), prog);
325 offset = dissect_rpc_uint32(tvb, rpcb_tree,
326 hf_portmap_rpcb_version, offset);
327 offset = dissect_rpc_string(tvb, rpcb_tree,
328 hf_portmap_rpcb_netid, offset, NULL);
329 offset = dissect_rpc_string(tvb, rpcb_tree,
330 hf_portmap_rpcb_addr, offset, NULL);
331 offset = dissect_rpc_string(tvb, rpcb_tree,
332 hf_portmap_rpcb_owner, offset, NULL);
334 /* now we know, that rpcb is shorter */
336 proto_item_set_len(rpcb_item, offset - old_offset);
344 /* RFC 1833, Page 7 */
345 int dissect_rpcb3_getaddr_call(tvbuff_t *tvb, int offset, packet_info *pinfo,
348 offset = dissect_rpcb(tvb, offset, pinfo, tree);
354 /* RFC 1833, Page 7 */
355 int dissect_rpcb3_getaddr_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
358 offset = dissect_rpc_string(tvb, tree,
359 hf_portmap_uaddr, offset, NULL);
365 /* RFC 1833, Page 7 */
366 int dissect_rpcb3_dump_reply(tvbuff_t *tvb, int offset, packet_info *pinfo,
369 offset = dissect_rpc_list(tvb, pinfo, tree, offset, dissect_rpcb);
373 /* RFC 1833, page 4 */
374 int dissect_rpcb_rmtcallres(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
377 /* Dissect the remote universal address. */
378 offset = dissect_rpc_string(tvb, tree,
379 hf_portmap_rpcb_addr, offset, NULL);
381 /* Dissect the result of this procedure.
382 Make the columns non-writable, so the dissector won't change
383 them out from under us. */
384 col_set_writable(pinfo->cinfo, FALSE);
385 offset = dissect_rpc_indir_reply(tvb, pinfo, tree, offset,
386 hf_portmap_result, hf_portmap_prog, hf_portmap_version,
393 /* Portmapper version 3, RFC 1833, Page 7 */
394 static const vsff portmap3_proc[] = {
395 { RPCBPROC_NULL, "NULL",
397 { RPCBPROC_SET, "SET",
399 { RPCBPROC_UNSET, "UNSET",
401 { RPCBPROC_GETADDR, "GETADDR",
402 dissect_rpcb3_getaddr_call, dissect_rpcb3_getaddr_reply},
403 { RPCBPROC_DUMP, "DUMP",
404 NULL, dissect_rpcb3_dump_reply },
405 { RPCBPROC_CALLIT, "CALLIT",
406 dissect_callit_call, dissect_rpcb_rmtcallres },
407 { RPCBPROC_GETTIME, "GETTIME",
409 { RPCBPROC_UADDR2TADDR, "UADDR2TADDR",
411 { RPCBPROC_TADDR2UADDR, "TADDR2UADDR",
413 { 0, NULL, NULL, NULL }
415 /* end of Portmap version 3 */
418 /* Portmapper version 4, RFC 1833, Page 8 */
419 static const vsff portmap4_proc[] = {
420 { RPCBPROC_NULL, "NULL",
422 { RPCBPROC_SET, "SET",
424 { RPCBPROC_UNSET, "UNSET",
426 { RPCBPROC_GETADDR, "GETADDR",
427 dissect_rpcb3_getaddr_call, dissect_rpcb3_getaddr_reply},
428 { RPCBPROC_DUMP, "DUMP",
429 NULL, dissect_rpcb3_dump_reply },
430 { RPCBPROC_BCAST, "BCAST",
431 dissect_callit_call, dissect_rpcb_rmtcallres },
432 { RPCBPROC_GETTIME, "GETTIME",
434 { RPCBPROC_UADDR2TADDR, "UADDR2TADDR",
436 { RPCBPROC_TADDR2UADDR, "TADDR2UADDR",
438 { RPCBPROC_GETVERSADDR, "GETVERSADDR",
440 { RPCBPROC_INDIRECT, "INDIRECT",
441 dissect_callit_call, dissect_rpcb_rmtcallres },
442 { RPCBPROC_GETADDRLIST, "GETADDRLIST",
444 { RPCBPROC_GETSTAT, "GETSTAT",
446 { 0, NULL, NULL, NULL }
448 /* end of Portmap version 4 */
451 proto_register_portmap(void)
453 static hf_register_info hf[] = {
454 { &hf_portmap_prog, {
455 "Program", "portmap.prog", FT_UINT32, BASE_DEC,
456 NULL, 0, "Program", HFILL }},
457 { &hf_portmap_port, {
458 "Port", "portmap.port", FT_UINT32, BASE_DEC,
459 NULL, 0, "Port", HFILL }},
460 { &hf_portmap_proc, {
461 "Procedure", "portmap.proc", FT_UINT32, BASE_DEC,
462 NULL, 0, "Procedure", HFILL }},
463 { &hf_portmap_proto, {
464 "Protocol", "portmap.proto", FT_UINT32, BASE_DEC,
465 NULL, 0, "Protocol", HFILL }},
466 { &hf_portmap_version, {
467 "Version", "portmap.version", FT_UINT32, BASE_DEC,
468 NULL, 0, "Version", HFILL }},
469 { &hf_portmap_answer, {
470 "Answer", "portmap.answer", FT_BOOLEAN, BASE_DEC,
471 NULL, 0, "Answer", HFILL }},
472 { &hf_portmap_args, {
473 "Arguments", "portmap.args", FT_BYTES, BASE_HEX,
474 NULL, 0, "Arguments", HFILL }},
475 { &hf_portmap_result, {
476 "Result", "portmap.result", FT_BYTES, BASE_HEX,
477 NULL, 0, "Result", HFILL }},
478 { &hf_portmap_rpcb, {
479 "RPCB", "portmap.rpcb", FT_NONE, 0,
480 NULL, 0, "RPCB", HFILL }},
481 { &hf_portmap_rpcb_prog, {
482 "Program", "portmap.rpcb.prog", FT_UINT32, BASE_DEC,
483 NULL, 0, "Program", HFILL }},
484 { &hf_portmap_rpcb_version, {
485 "Version", "portmap.rpcb.version", FT_UINT32, BASE_DEC,
486 NULL, 0, "Version", HFILL }},
487 { &hf_portmap_rpcb_netid, {
488 "Network Id", "portmap.rpcb.netid", FT_STRING, BASE_DEC,
489 NULL, 0, "Network Id", HFILL }},
490 { &hf_portmap_rpcb_addr, { /* address in rpcb structure in request */
491 "Universal Address", "portmap.rpcb.addr", FT_STRING, BASE_DEC,
492 NULL, 0, "Universal Address", HFILL }},
493 { &hf_portmap_rpcb_owner, {
494 "Owner of this Service", "portmap.rpcb.owner", FT_STRING, BASE_DEC,
495 NULL, 0, "Owner of this Service", HFILL }},
496 { &hf_portmap_uaddr, { /* address in RPCBPROC_GETADDR reply */
497 "Universal Address", "portmap.uaddr", FT_STRING, BASE_DEC,
498 NULL, 0, "Universal Address", HFILL }},
500 static gint *ett[] = {
506 proto_portmap = proto_register_protocol("Portmap", "Portmap", "portmap");
507 proto_register_field_array(proto_portmap, hf, array_length(hf));
508 proto_register_subtree_array(ett, array_length(ett));
512 proto_reg_handoff_portmap(void)
514 /* Register the protocol as RPC */
515 rpc_init_prog(proto_portmap, PORTMAP_PROGRAM, ett_portmap);
516 /* Register the procedure tables */
517 rpc_init_proc_table(PORTMAP_PROGRAM, 1, portmap1_proc);
518 rpc_init_proc_table(PORTMAP_PROGRAM, 2, portmap2_proc);
519 rpc_init_proc_table(PORTMAP_PROGRAM, 3, portmap3_proc);
520 rpc_init_proc_table(PORTMAP_PROGRAM, 4, portmap4_proc);