2 * Routines for portmap dissection
4 * $Id: packet-portmap.c,v 1.9 1999/11/22 03:32:55 nneul Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@unicom.net>
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"
41 static int proto_portmap = -1;
42 static int hf_portmap_proto = -1;
43 static int hf_portmap_prog = -1;
44 static int hf_portmap_proc = -1;
45 static int hf_portmap_version = -1;
46 static int hf_portmap_port = -1;
47 static int hf_portmap_answer = -1;
48 static int hf_portmap_rpcb = -1;
49 static int hf_portmap_rpcb_prog = -1;
50 static int hf_portmap_rpcb_version = -1;
51 static int hf_portmap_rpcb_netid = -1;
52 static int hf_portmap_rpcb_addr = -1;
53 static int hf_portmap_rpcb_owner = -1;
54 static int hf_portmap_uaddr = -1;
55 static int hf_portmap_value_follows = -1;
58 static gint ett_portmap = -1;
59 static gint ett_portmap_rpcb = -1;
60 static gint ett_portmap_entry = -1;
63 static struct true_false_string yesno = { "Yes", "No" };
66 /* Dissect a getport call */
67 int dissect_getport_call(const u_char *pd, int offset, frame_data *fd,
72 if ( !BYTES_ARE_IN_FRAME(offset, 16)) return offset;
76 prog = pntohl(&pd[offset+0]);
77 proto_tree_add_item_format(tree, hf_portmap_prog,
78 offset, 4, prog, "Program: %s (%u)",
79 rpc_prog_name(prog), prog);
80 proto_tree_add_item(tree, hf_portmap_version,
81 offset+4, 4, pntohl(&pd[offset+4]));
83 proto = pntohl(&pd[offset+8]);
84 proto_tree_add_item_format(tree, hf_portmap_proto,
85 offset+8, 4, proto, "Proto: %s (%u)", ipprotostr(proto), proto);
87 proto_tree_add_item(tree, hf_portmap_port,
88 offset+12, 4, pntohl(&pd[offset+12]));
94 int dissect_getport_reply(const u_char *pd, int offset, frame_data *fd,
97 if ( !BYTES_ARE_IN_FRAME(offset, 4)) return offset;
100 proto_tree_add_item(tree, hf_portmap_port,
101 offset, 4, pntohl(&pd[offset+0]));
106 /* Dissect a 'set' call */
107 int dissect_set_call(const u_char *pd, int offset, frame_data *fd,
112 if ( !BYTES_ARE_IN_FRAME(offset, 16)) return offset;
116 prog = pntohl(&pd[offset+0]);
117 proto_tree_add_item_format(tree, hf_portmap_prog,
118 offset, 4, prog, "Program: %s (%d)",
119 rpc_prog_name(prog), prog);
120 proto_tree_add_item(tree, hf_portmap_version,
121 offset+4, 4, pntohl(&pd[offset+4]));
123 proto = pntohl(&pd[offset+8]);
124 proto_tree_add_item_format(tree, hf_portmap_proto,
125 offset+8, 4, proto, "Proto: %s (%d)", ipprotostr(proto), proto);
127 proto_tree_add_item(tree, hf_portmap_port,
128 offset+12, 4, pntohl(&pd[offset+12]));
134 /* Dissect a 'unset' call */
135 int dissect_unset_call(const u_char *pd, int offset, frame_data *fd,
140 if ( !BYTES_ARE_IN_FRAME(offset, 16)) return offset;
144 prog = pntohl(&pd[offset+0]);
145 proto_tree_add_item_format(tree, hf_portmap_prog,
146 offset, 4, prog, "Program: %s (%d)",
147 rpc_prog_name(prog), prog);
148 proto_tree_add_item(tree, hf_portmap_version,
149 offset+4, 4, pntohl(&pd[offset+4]));
151 proto = pntohl(&pd[offset+8]);
152 proto_tree_add_item(tree, hf_portmap_proto,
155 proto_tree_add_item(tree, hf_portmap_port,
156 offset+12, 4, pntohl(&pd[offset+12]));
162 int dissect_set_reply(const u_char *pd, int offset, frame_data *fd,
167 if ( !BYTES_ARE_IN_FRAME(offset, 4)) return offset;
169 proto_tree_add_item(tree, hf_portmap_answer,
170 offset, 4, pntohl(&pd[offset+0]));
176 int dissect_dump_reply(const u_char *pd, int offset, frame_data *fd,
179 int prog, version, proto, port, value_follows;
180 proto_item *ti, *subtree;
182 while ( BYTES_ARE_IN_FRAME(offset, 4) )
184 value_follows = pntohl(&pd[offset+0]);
187 proto_tree_add_item(tree, hf_portmap_value_follows,
188 offset, 4, value_follows);
194 if ( ! BYTES_ARE_IN_FRAME(offset, 16) )
198 prog = pntohl(&pd[offset+0]);
199 version = pntohl(&pd[offset+4]);
200 proto = pntohl(&pd[offset+8]);
201 port = pntohl(&pd[offset+12]);
205 ti = proto_tree_add_text(tree, offset, 16, "Map Entry: %s (%d) V%d",
206 rpc_prog_name(prog), prog, version);
207 subtree = proto_item_add_subtree(ti, ett_portmap_entry);
209 proto_tree_add_item(subtree, hf_portmap_prog,
211 proto_tree_add_item(subtree, hf_portmap_version,
212 offset+4, 4, version);
213 proto_tree_add_item(subtree, hf_portmap_proto,
215 proto_tree_add_item(subtree, hf_portmap_port,
224 /* proc number, "proc name", dissect_request, dissect_reply */
225 /* NULL as function pointer means: take the generic one. */
226 const vsff portmap1_proc[] = {
227 { PORTMAPPROC_NULL, "NULL", NULL, NULL },
228 { PORTMAPPROC_SET, "SET", NULL, NULL },
229 { PORTMAPPROC_UNSET, "UNSET", NULL, NULL },
230 { PORTMAPPROC_GETPORT, "GETPORT", NULL, NULL },
231 { PORTMAPPROC_DUMP, "DUMP", NULL, NULL },
232 { PORTMAPPROC_CALLIT, "CALLIT", NULL, NULL },
233 { 0, NULL, NULL, NULL }
235 /* end of Portmap version 1 */
237 const vsff portmap2_proc[] = {
238 { PORTMAPPROC_NULL, "NULL",
240 { PORTMAPPROC_SET, "SET",
241 dissect_set_call, dissect_set_reply },
242 { PORTMAPPROC_UNSET, "UNSET",
243 dissect_unset_call, dissect_set_reply },
244 { PORTMAPPROC_GETPORT, "GETPORT",
245 dissect_getport_call, dissect_getport_reply },
246 { PORTMAPPROC_DUMP, "DUMP",
247 NULL, dissect_dump_reply },
248 { PORTMAPPROC_CALLIT, "CALLIT",
250 { 0, NULL, NULL, NULL }
252 /* end of Portmap version 2 */
255 /* RFC 1833, Page 3 */
256 int dissect_rpcb(const u_char *pd, int offset, frame_data *fd, proto_tree *tree, int hfindex)
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, hfindex,
266 offset+0, END_OF_FRAME, NULL);
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_item_format(rpcb_tree, hf_portmap_rpcb_prog,
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_item(rpcb_tree, hf_portmap_rpcb_version,
283 offset+0, 4, version);
286 offset = dissect_rpc_string(pd, offset, fd, rpcb_tree, hf_portmap_rpcb_netid);
287 offset = dissect_rpc_string(pd, offset, fd, rpcb_tree, hf_portmap_rpcb_addr);
288 offset = dissect_rpc_string(pd, offset, fd, rpcb_tree, hf_portmap_rpcb_owner);
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, hf_portmap_rpcb);
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);
320 /* RFC 1833, Page 7 */
321 int dissect_rpcb3_dump_reply(const u_char *pd, int offset, frame_data *fd,
324 guint32 value_follows;
327 if (!BYTES_ARE_IN_FRAME(offset,4)) break;
328 value_follows = EXTRACT_UINT(pd, offset+0);
329 proto_tree_add_item(tree,hf_portmap_value_follows,
330 offset+0, 4, value_follows);
332 if (value_follows == 1) {
333 offset = dissect_rpcb(pd, offset, fd, tree, hf_portmap_rpcb);
344 /* Portmapper version 3, RFC 1833, Page 7 */
345 const vsff portmap3_proc[] = {
346 { RPCBPROC_NULL, "NULL",
348 { RPCBPROC_SET, "SET",
350 { RPCBPROC_UNSET, "UNSET",
352 { RPCBPROC_GETADDR, "GETADDR",
353 dissect_rpcb3_getaddr_call, dissect_rpcb3_getaddr_reply},
354 { RPCBPROC_DUMP, "DUMP",
355 NULL, dissect_rpcb3_dump_reply },
356 { RPCBPROC_CALLIT, "CALLIT",
358 { RPCBPROC_GETTIME, "GETTIME",
360 { RPCBPROC_UADDR2TADDR, "UADDR2TADDR",
362 { RPCBPROC_TADDR2UADDR, "TADDR2UADDR",
364 { 0, NULL, NULL, NULL }
366 /* end of Portmap version 3 */
369 /* Portmapper version 4, RFC 1833, Page 8 */
370 const vsff portmap4_proc[] = {
371 { RPCBPROC_NULL, "NULL",
373 { RPCBPROC_SET, "SET",
375 { RPCBPROC_UNSET, "UNSET",
377 { RPCBPROC_GETADDR, "GETADDR",
378 dissect_rpcb3_getaddr_call, dissect_rpcb3_getaddr_reply},
379 { RPCBPROC_DUMP, "DUMP",
380 NULL, dissect_rpcb3_dump_reply },
381 { RPCBPROC_BCAST, "BCAST",
383 { RPCBPROC_GETTIME, "GETTIME",
385 { RPCBPROC_UADDR2TADDR, "UADDR2TADDR",
387 { RPCBPROC_TADDR2UADDR, "TADDR2UADDR",
389 { RPCBPROC_GETVERSADDR, "GETVERSADDR",
391 { RPCBPROC_INDIRECT, "INDIRECT",
393 { RPCBPROC_GETADDRLIST, "GETADDRLIST",
395 { RPCBPROC_GETSTAT, "GETSTAT",
397 { 0, NULL, NULL, NULL }
399 /* end of Portmap version 4 */
402 proto_register_portmap(void)
404 static hf_register_info hf[] = {
405 { &hf_portmap_prog, {
406 "Program", "portmap.prog", FT_UINT32, BASE_DEC,
407 NULL, 0, "Program" }},
408 { &hf_portmap_port, {
409 "Port", "portmap.port", FT_UINT32, BASE_DEC,
411 { &hf_portmap_proc, {
412 "Procedure", "portmap.proc", FT_UINT32, BASE_DEC,
413 NULL, 0, "Procedure" }},
414 { &hf_portmap_proto, {
415 "Protocol", "portmap.proto", FT_UINT32, BASE_DEC,
416 NULL, 0, "Protocol" }},
417 { &hf_portmap_version, {
418 "Version", "portmap.version", FT_UINT32, BASE_DEC,
419 NULL, 0, "Version" }},
420 { &hf_portmap_answer, {
421 "Answer", "portmap.answer", FT_BOOLEAN, BASE_DEC,
422 NULL, 0, "Answer" }},
423 { &hf_portmap_rpcb, {
424 "RPCB", "portmap.rpcb", FT_NONE, 0,
426 { &hf_portmap_rpcb_prog, {
427 "Program", "portmap.rpcb.prog", FT_UINT32, BASE_DEC,
428 NULL, 0, "Program" }},
429 { &hf_portmap_rpcb_version, {
430 "Version", "portmap.rpcb.version", FT_UINT32, BASE_DEC,
431 NULL, 0, "Version" }},
432 { &hf_portmap_rpcb_netid, {
433 "Network Id", "portmap.rpcb.netid", FT_STRING, BASE_DEC,
434 NULL, 0, "Network Id" }},
435 { &hf_portmap_rpcb_addr, {
436 "Universal Address", "portmap.rpcb.addr", FT_STRING, BASE_DEC,
437 NULL, 0, "Universal Address" }},
438 { &hf_portmap_rpcb_owner, {
439 "Owner of this Service", "portmap.rpcb.owner", FT_STRING, BASE_DEC,
440 NULL, 0, "Owner of this Service" }},
441 { &hf_portmap_uaddr, {
442 "Universal Address", "portmap.uaddr", FT_STRING, BASE_DEC,
443 NULL, 0, "Universal Address" }},
444 { &hf_portmap_value_follows, {
445 "Value Follows", "portmap.value_follows", FT_BOOLEAN, BASE_NONE,
446 &yesno, 0, "Value Follows" }},
448 static gint *ett[] = {
454 proto_portmap = proto_register_protocol("Portmap", "portmap");
455 proto_register_field_array(proto_portmap, hf, array_length(hf));
456 proto_register_subtree_array(ett, array_length(ett));
458 /* Register the protocol as RPC */
459 rpc_init_prog(proto_portmap, PORTMAP_PROGRAM, ett_portmap);
460 /* Register the procedure tables */
461 rpc_init_proc_table(PORTMAP_PROGRAM, 1, portmap1_proc);
462 rpc_init_proc_table(PORTMAP_PROGRAM, 2, portmap2_proc);
463 rpc_init_proc_table(PORTMAP_PROGRAM, 3, portmap3_proc);
464 rpc_init_proc_table(PORTMAP_PROGRAM, 4, portmap4_proc);