For proto_tree_add_item(..., proto_xxx, ...)use ENC_NA as the encoding arg.
[obnox/wireshark/wip.git] / epan / dissectors / packet-rsh.c
1 /* packet-rsh.c
2  * Routines for rsh packet disassembly
3  *
4  * Robert Tsai <rtsai@netapp.com>
5  * Liberally copied from packet-http.c, by Guy Harris <guy@alum.mit.edu>
6  *
7  * $Id$
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
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.
17  *
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.
22  *
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.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include <glib.h>
33 #include <epan/packet.h>
34 #include <epan/strutil.h>
35
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;
40
41 #define TCP_PORT_RSH                    514
42
43 static void
44 dissect_rsh(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
45 {
46         proto_tree      *rsh_tree;
47         proto_item      *ti, *hidden_item;
48         gint            offset = 0;
49         gint            next_offset;
50         int             linelen;
51
52         col_set_str(pinfo->cinfo, COL_PROTOCOL, "RSH");
53         if (check_col(pinfo->cinfo, COL_INFO)) {
54                 /* Put the first line from the buffer into the summary. */
55                 tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
56                 linelen = next_offset - offset; /* include the line terminator */
57
58                 /*
59                  * Make sure the line terminator isn't past the end of
60                  * the captured data in the packet, so we don't throw
61                  * an exception in the "tvb_get_ptr()" call.
62                  */
63                 if (linelen > (int) tvb_length(tvb))
64                         linelen = tvb_length(tvb);
65                 col_add_str(pinfo->cinfo, COL_INFO,
66                     tvb_format_text(tvb, offset, linelen));
67         }
68         if (tree) {
69                 ti = proto_tree_add_item(tree, proto_rsh, tvb, offset, -1,
70                     ENC_NA);
71                 rsh_tree = proto_item_add_subtree(ti, ett_rsh);
72
73                 /*
74                  * Process the packet data, a line at a time.
75                  */
76                 while (tvb_offset_exists(tvb, offset)) {
77                         /*
78                          * Find the end of the line.
79                          */
80                         tvb_find_line_end(tvb, offset, -1, &next_offset,
81                             FALSE);
82
83                         /*
84                          * Put this line.
85                          */
86                         proto_tree_add_text(rsh_tree, tvb, offset,
87                             next_offset - offset, "%s",
88                             tvb_format_text(tvb, offset, next_offset - offset));
89                         offset = next_offset;
90                 }
91
92                 if (pinfo->match_uint == pinfo->destport) {
93                         hidden_item = proto_tree_add_boolean(rsh_tree,
94                             hf_rsh_request, tvb, 0, 0, 1);
95                 } else {
96                         hidden_item = proto_tree_add_boolean(rsh_tree,
97                             hf_rsh_response, tvb, 0, 0, 1);
98                 }
99                 PROTO_ITEM_SET_HIDDEN(hidden_item);
100         }
101 }
102
103 void
104 proto_register_rsh(void)
105 {
106
107         static hf_register_info hf[] = {
108                 { &hf_rsh_response,
109                 { "Response",           "rsh.response",
110                 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
111                 "TRUE if rsh response", HFILL }},
112                 { &hf_rsh_request,
113                 { "Request",            "rsh.request",
114                 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
115                 "TRUE if rsh request", HFILL }},
116         };
117
118         static gint *ett[] = {
119                 &ett_rsh,
120         };
121
122         proto_rsh = proto_register_protocol("Remote Shell", "RSH", "rsh");
123         proto_register_field_array(proto_rsh, hf, array_length(hf));
124         proto_register_subtree_array(ett, array_length(ett));
125 }
126
127 void
128 proto_reg_handoff_rsh(void)
129 {
130         dissector_handle_t rsh_handle;
131
132         rsh_handle = create_dissector_handle(dissect_rsh, proto_rsh);
133         dissector_add_uint("tcp.port", TCP_PORT_RSH, rsh_handle);
134 }