2 * Routines for rsh packet disassembly
4 * Robert Tsai <rtsai@netapp.com>
5 * Liberally copied from packet-http.c, by Guy Harris <guy@alum.mit.edu>
7 * $Id: packet-rsh.c,v 1.20 2002/08/28 21:00:29 jmayer Exp $
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@ethereal.com>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include <epan/packet.h>
34 #include <epan/strutil.h>
36 static int proto_rsh = -1;
37 static int hf_rsh_response = -1;
38 static int hf_rsh_request = -1;
39 static gint ett_rsh = -1;
41 #define TCP_PORT_RSH 514
44 dissect_rsh(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
52 if (check_col(pinfo->cinfo, COL_PROTOCOL))
53 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RSH");
54 if (check_col(pinfo->cinfo, COL_INFO)) {
55 /* Put the first line from the buffer into the summary. */
56 tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
57 linelen = next_offset - offset; /* include the line terminator */
60 * Make sure the line terminator isn't past the end of
61 * the captured data in the packet, so we don't throw
62 * an exception in the "tvb_get_ptr()" call.
64 if (linelen > (int) tvb_length(tvb))
65 linelen = tvb_length(tvb);
66 col_add_str(pinfo->cinfo, COL_INFO,
67 tvb_format_text(tvb, offset, linelen));
70 ti = proto_tree_add_item(tree, proto_rsh, tvb, offset, -1,
72 rsh_tree = proto_item_add_subtree(ti, ett_rsh);
75 * Process the packet data, a line at a time.
77 while (tvb_offset_exists(tvb, offset)) {
79 * Find the end of the line.
81 tvb_find_line_end(tvb, offset, -1, &next_offset,
87 proto_tree_add_text(rsh_tree, tvb, offset,
88 next_offset - offset, "%s",
89 tvb_format_text(tvb, offset, next_offset - offset));
93 if (pinfo->match_port == pinfo->destport)
94 proto_tree_add_boolean_hidden(rsh_tree,
95 hf_rsh_request, tvb, 0, 0, 1);
97 proto_tree_add_boolean_hidden(rsh_tree,
98 hf_rsh_response, tvb, 0, 0, 1);
103 proto_register_rsh(void)
106 static hf_register_info hf[] = {
108 { "Response", "rsh.response",
109 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
110 "TRUE if rsh response", HFILL }},
112 { "Request", "rsh.request",
113 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
114 "TRUE if rsh request", HFILL }},
117 static gint *ett[] = {
121 proto_rsh = proto_register_protocol("Remote Shell", "RSH", "rsh");
122 proto_register_field_array(proto_rsh, hf, array_length(hf));
123 proto_register_subtree_array(ett, array_length(ett));
127 proto_reg_handoff_rsh(void)
129 dissector_handle_t rsh_handle;
131 rsh_handle = create_dissector_handle(dissect_rsh, proto_rsh);
132 dissector_add("tcp.port", TCP_PORT_RSH, rsh_handle);