2 * Routines for portmap dissection
4 * $Id: packet-portmap.c,v 1.21 2001/01/03 06:55:31 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.org>
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"
43 * RFC 1833, "Binding Protocols for ONC RPC Version 2".
46 static int proto_portmap = -1;
47 static int hf_portmap_proto = -1;
48 static int hf_portmap_prog = -1;
49 static int hf_portmap_proc = -1;
50 static int hf_portmap_version = -1;
51 static int hf_portmap_port = -1;
52 static int hf_portmap_answer = -1;
53 static int hf_portmap_rpcb = -1;
54 static int hf_portmap_rpcb_prog = -1;
55 static int hf_portmap_rpcb_version = -1;
56 static int hf_portmap_rpcb_netid = -1;
57 static int hf_portmap_rpcb_addr = -1;
58 static int hf_portmap_rpcb_owner = -1;
59 static int hf_portmap_uaddr = -1;
62 static gint ett_portmap = -1;
63 static gint ett_portmap_rpcb = -1;
64 static gint ett_portmap_entry = -1;
67 /* Dissect a getport call */
68 int dissect_getport_call(const u_char *pd, int offset, frame_data *fd,
73 if ( !BYTES_ARE_IN_FRAME(offset, 16)) return offset;
77 prog = pntohl(&pd[offset+0]);
78 proto_tree_add_uint_format(tree, hf_portmap_prog, NullTVB,
79 offset, 4, prog, "Program: %s (%u)",
80 rpc_prog_name(prog), prog);
81 proto_tree_add_uint(tree, hf_portmap_version, NullTVB,
82 offset+4, 4, pntohl(&pd[offset+4]));
84 proto = pntohl(&pd[offset+8]);
85 proto_tree_add_uint_format(tree, hf_portmap_proto, NullTVB,
86 offset+8, 4, proto, "Proto: %s (%u)", ipprotostr(proto), proto);
88 proto_tree_add_uint(tree, hf_portmap_port, NullTVB,
89 offset+12, 4, pntohl(&pd[offset+12]));
95 int dissect_getport_reply(const u_char *pd, int offset, frame_data *fd,
98 if ( !BYTES_ARE_IN_FRAME(offset, 4)) return offset;
101 proto_tree_add_uint(tree, hf_portmap_port, NullTVB,
102 offset, 4, pntohl(&pd[offset+0]));
107 /* Dissect a 'set' call */
108 int dissect_set_call(const u_char *pd, int offset, frame_data *fd,
113 if ( !BYTES_ARE_IN_FRAME(offset, 16)) return offset;
117 prog = pntohl(&pd[offset+0]);
118 proto_tree_add_uint_format(tree, hf_portmap_prog, NullTVB,
119 offset, 4, prog, "Program: %s (%d)",
120 rpc_prog_name(prog), prog);
121 proto_tree_add_uint(tree, hf_portmap_version, NullTVB,
122 offset+4, 4, pntohl(&pd[offset+4]));
124 proto = pntohl(&pd[offset+8]);
125 proto_tree_add_uint_format(tree, hf_portmap_proto, NullTVB,
126 offset+8, 4, proto, "Proto: %s (%d)", ipprotostr(proto), proto);
128 proto_tree_add_uint(tree, hf_portmap_port, NullTVB,
129 offset+12, 4, pntohl(&pd[offset+12]));
135 /* Dissect a 'unset' call */
136 int dissect_unset_call(const u_char *pd, int offset, frame_data *fd,
141 if ( !BYTES_ARE_IN_FRAME(offset, 16)) return offset;
145 prog = pntohl(&pd[offset+0]);
146 proto_tree_add_uint_format(tree, hf_portmap_prog, NullTVB,
147 offset, 4, prog, "Program: %s (%d)",
148 rpc_prog_name(prog), prog);
149 proto_tree_add_uint(tree, hf_portmap_version, NullTVB,
150 offset+4, 4, pntohl(&pd[offset+4]));
152 proto = pntohl(&pd[offset+8]);
153 proto_tree_add_uint(tree, hf_portmap_proto, NullTVB,
156 proto_tree_add_uint(tree, hf_portmap_port, NullTVB,
157 offset+12, 4, pntohl(&pd[offset+12]));
163 int dissect_set_reply(const u_char *pd, int offset, frame_data *fd,
168 if ( !BYTES_ARE_IN_FRAME(offset, 4)) return offset;
170 proto_tree_add_boolean(tree, hf_portmap_answer, NullTVB,
171 offset, 4, pntohl(&pd[offset+0]));
178 dissect_dump_entry(const u_char* pd, int offset, frame_data* fd, proto_tree* tree)
180 int prog, version, proto, port;
181 proto_item *ti, *subtree;
183 if ( ! BYTES_ARE_IN_FRAME(offset, 16) )
187 proto_tree_add_text(tree, NullTVB, offset, END_OF_FRAME, "Map Entry: <TRUNCATED>");
189 return pi.captured_len;
191 prog = pntohl(&pd[offset+0]);
192 version = pntohl(&pd[offset+4]);
193 proto = pntohl(&pd[offset+8]);
194 port = pntohl(&pd[offset+12]);
197 ti = proto_tree_add_text(tree, NullTVB, offset, 16, "Map Entry: %s (%u) V%d",
198 rpc_prog_name(prog), prog, version);
199 subtree = proto_item_add_subtree(ti, ett_portmap_entry);
201 proto_tree_add_uint_format(subtree, hf_portmap_prog, NullTVB,
203 "Program: %s (%u)", rpc_prog_name(prog), prog);
204 proto_tree_add_uint(subtree, hf_portmap_version, NullTVB,
205 offset+4, 4, version);
206 proto_tree_add_uint_format(subtree, hf_portmap_proto, NullTVB,
208 "Protocol: %s (0x%02x)", ipprotostr(proto), proto);
209 proto_tree_add_uint(subtree, hf_portmap_port, NullTVB,
216 int dissect_dump_reply(const u_char *pd, int offset, frame_data *fd,
219 offset = dissect_rpc_list(pd, offset, fd, tree, dissect_dump_entry);
223 /* proc number, "proc name", dissect_request, dissect_reply */
224 /* NULL as function pointer means: take the generic one. */
225 const vsff portmap1_proc[] = {
226 { PORTMAPPROC_NULL, "NULL", NULL, NULL },
227 { PORTMAPPROC_SET, "SET", NULL, NULL },
228 { PORTMAPPROC_UNSET, "UNSET", NULL, NULL },
229 { PORTMAPPROC_GETPORT, "GETPORT", NULL, NULL },
230 { PORTMAPPROC_DUMP, "DUMP", NULL, NULL },
231 { PORTMAPPROC_CALLIT, "CALLIT", NULL, NULL },
232 { 0, NULL, NULL, NULL }
234 /* end of Portmap version 1 */
236 const vsff portmap2_proc[] = {
237 { PORTMAPPROC_NULL, "NULL",
239 { PORTMAPPROC_SET, "SET",
240 dissect_set_call, dissect_set_reply },
241 { PORTMAPPROC_UNSET, "UNSET",
242 dissect_unset_call, dissect_set_reply },
243 { PORTMAPPROC_GETPORT, "GETPORT",
244 dissect_getport_call, dissect_getport_reply },
245 { PORTMAPPROC_DUMP, "DUMP",
246 NULL, dissect_dump_reply },
247 { PORTMAPPROC_CALLIT, "CALLIT",
249 { 0, NULL, NULL, NULL }
251 /* end of Portmap version 2 */
254 /* RFC 1833, Page 3 */
256 dissect_rpcb(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
258 proto_item* rpcb_item = NULL;
259 proto_tree* rpcb_tree = NULL;
260 int old_offset = offset;
265 rpcb_item = proto_tree_add_item(tree, hf_portmap_rpcb, NullTVB,
266 offset+0, END_OF_FRAME, FALSE);
268 rpcb_tree = proto_item_add_subtree(rpcb_item, ett_portmap_rpcb);
271 if (!BYTES_ARE_IN_FRAME(offset, 4)) return offset;
272 prog = EXTRACT_UINT(pd, offset + 0);
274 proto_tree_add_uint_format(rpcb_tree, hf_portmap_rpcb_prog, NullTVB,
276 "Program: %s (%u)", rpc_prog_name(prog), prog);
279 if (!BYTES_ARE_IN_FRAME(offset, 4)) return offset;
280 version = EXTRACT_UINT(pd, offset + 0);
282 proto_tree_add_uint(rpcb_tree, hf_portmap_rpcb_version, NullTVB,
283 offset+0, 4, version);
286 offset = dissect_rpc_string(pd, offset, fd, rpcb_tree, hf_portmap_rpcb_netid,NULL);
287 offset = dissect_rpc_string(pd, offset, fd, rpcb_tree, hf_portmap_rpcb_addr,NULL);
288 offset = dissect_rpc_string(pd, offset, fd, rpcb_tree, hf_portmap_rpcb_owner,NULL);
290 /* now we know, that rpcb is shorter */
292 proto_item_set_len(rpcb_item, offset - old_offset);
300 /* RFC 1833, Page 7 */
301 int dissect_rpcb3_getaddr_call(const u_char *pd, int offset, frame_data *fd,
304 offset = dissect_rpcb(pd, offset, fd, tree);
310 /* RFC 1833, Page 7 */
311 int dissect_rpcb3_getaddr_reply(const u_char *pd, int offset, frame_data *fd,
314 offset = dissect_rpc_string(pd, offset, fd, tree, hf_portmap_uaddr,NULL);
320 /* RFC 1833, Page 7 */
321 int dissect_rpcb3_dump_reply(const u_char *pd, int offset, frame_data *fd,
324 offset = dissect_rpc_list(pd, offset, fd, tree, dissect_rpcb);
329 /* Portmapper version 3, RFC 1833, Page 7 */
330 const vsff portmap3_proc[] = {
331 { RPCBPROC_NULL, "NULL",
333 { RPCBPROC_SET, "SET",
335 { RPCBPROC_UNSET, "UNSET",
337 { RPCBPROC_GETADDR, "GETADDR",
338 dissect_rpcb3_getaddr_call, dissect_rpcb3_getaddr_reply},
339 { RPCBPROC_DUMP, "DUMP",
340 NULL, dissect_rpcb3_dump_reply },
341 { RPCBPROC_CALLIT, "CALLIT",
343 { RPCBPROC_GETTIME, "GETTIME",
345 { RPCBPROC_UADDR2TADDR, "UADDR2TADDR",
347 { RPCBPROC_TADDR2UADDR, "TADDR2UADDR",
349 { 0, NULL, NULL, NULL }
351 /* end of Portmap version 3 */
354 /* Portmapper version 4, RFC 1833, Page 8 */
355 const vsff portmap4_proc[] = {
356 { RPCBPROC_NULL, "NULL",
358 { RPCBPROC_SET, "SET",
360 { RPCBPROC_UNSET, "UNSET",
362 { RPCBPROC_GETADDR, "GETADDR",
363 dissect_rpcb3_getaddr_call, dissect_rpcb3_getaddr_reply},
364 { RPCBPROC_DUMP, "DUMP",
365 NULL, dissect_rpcb3_dump_reply },
366 { RPCBPROC_BCAST, "BCAST",
368 { RPCBPROC_GETTIME, "GETTIME",
370 { RPCBPROC_UADDR2TADDR, "UADDR2TADDR",
372 { RPCBPROC_TADDR2UADDR, "TADDR2UADDR",
374 { RPCBPROC_GETVERSADDR, "GETVERSADDR",
376 { RPCBPROC_INDIRECT, "INDIRECT",
378 { RPCBPROC_GETADDRLIST, "GETADDRLIST",
380 { RPCBPROC_GETSTAT, "GETSTAT",
382 { 0, NULL, NULL, NULL }
384 /* end of Portmap version 4 */
387 proto_register_portmap(void)
389 static hf_register_info hf[] = {
390 { &hf_portmap_prog, {
391 "Program", "portmap.prog", FT_UINT32, BASE_DEC,
392 NULL, 0, "Program" }},
393 { &hf_portmap_port, {
394 "Port", "portmap.port", FT_UINT32, BASE_DEC,
396 { &hf_portmap_proc, {
397 "Procedure", "portmap.proc", FT_UINT32, BASE_DEC,
398 NULL, 0, "Procedure" }},
399 { &hf_portmap_proto, {
400 "Protocol", "portmap.proto", FT_UINT32, BASE_DEC,
401 NULL, 0, "Protocol" }},
402 { &hf_portmap_version, {
403 "Version", "portmap.version", FT_UINT32, BASE_DEC,
404 NULL, 0, "Version" }},
405 { &hf_portmap_answer, {
406 "Answer", "portmap.answer", FT_BOOLEAN, BASE_DEC,
407 NULL, 0, "Answer" }},
408 { &hf_portmap_rpcb, {
409 "RPCB", "portmap.rpcb", FT_NONE, 0,
411 { &hf_portmap_rpcb_prog, {
412 "Program", "portmap.rpcb.prog", FT_UINT32, BASE_DEC,
413 NULL, 0, "Program" }},
414 { &hf_portmap_rpcb_version, {
415 "Version", "portmap.rpcb.version", FT_UINT32, BASE_DEC,
416 NULL, 0, "Version" }},
417 { &hf_portmap_rpcb_netid, {
418 "Network Id", "portmap.rpcb.netid", FT_STRING, BASE_DEC,
419 NULL, 0, "Network Id" }},
420 { &hf_portmap_rpcb_addr, {
421 "Universal Address", "portmap.rpcb.addr", FT_STRING, BASE_DEC,
422 NULL, 0, "Universal Address" }},
423 { &hf_portmap_rpcb_owner, {
424 "Owner of this Service", "portmap.rpcb.owner", FT_STRING, BASE_DEC,
425 NULL, 0, "Owner of this Service" }},
426 { &hf_portmap_uaddr, {
427 "Universal Address", "portmap.uaddr", FT_STRING, BASE_DEC,
428 NULL, 0, "Universal Address" }},
430 static gint *ett[] = {
436 proto_portmap = proto_register_protocol("Portmap", "Portmap", "portmap");
437 proto_register_field_array(proto_portmap, hf, array_length(hf));
438 proto_register_subtree_array(ett, array_length(ett));
442 proto_reg_handoff_portmap(void)
444 /* Register the protocol as RPC */
445 rpc_init_prog(proto_portmap, PORTMAP_PROGRAM, ett_portmap);
446 /* Register the procedure tables */
447 rpc_init_proc_table(PORTMAP_PROGRAM, 1, portmap1_proc);
448 rpc_init_proc_table(PORTMAP_PROGRAM, 2, portmap2_proc);
449 rpc_init_proc_table(PORTMAP_PROGRAM, 3, portmap3_proc);
450 rpc_init_proc_table(PORTMAP_PROGRAM, 4, portmap4_proc);