Squelch an MSVC++ complaint.
[obnox/wireshark/wip.git] / 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: packet-rsh.c,v 1.12 2001/10/26 18:28:16 gram Exp $
8  *
9  * Ethereal - Network traffic analyzer
10  * By Gerald Combs <gerald@zing.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * 
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  * 
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  * 
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27  *
28  *
29  */
30
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif
34
35 #ifdef HAVE_SYS_TYPES_H
36 #include <sys/types.h>
37 #endif
38
39 #include <glib.h>
40 #include "packet.h"
41 #include "strutil.h"
42
43 static int proto_rsh = -1;
44 static int hf_rsh_response = -1;
45 static int hf_rsh_request = -1;
46 static gint ett_rsh = -1;
47
48 #define TCP_PORT_RSH                    514
49
50 void
51 dissect_rsh(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
52 {
53         proto_tree      *rsh_tree;
54         proto_item      *ti;
55         gint            offset = 0;
56         gint            next_offset;
57         int             linelen;
58
59         if (check_col(pinfo->fd, COL_PROTOCOL))
60                 col_set_str(pinfo->fd, COL_PROTOCOL, "RSH");
61         if (check_col(pinfo->fd, COL_INFO)) {
62                 /* Put the first line from the buffer into the summary. */
63                 tvb_find_line_end(tvb, offset, -1, &next_offset);
64                 linelen = next_offset - offset; /* include the line terminator */
65
66                 /*
67                  * Make sure the line terminator isn't past the end of
68                  * the captured data in the packet, so we don't throw
69                  * an exception in the "tvb_get_ptr()" call.
70                  */
71                 if (linelen > (int) tvb_length(tvb))
72                         linelen = tvb_length(tvb);
73                 col_add_str(pinfo->fd, COL_INFO,
74                     tvb_format_text(tvb, offset, linelen));
75         }
76         if (tree) {
77                 ti = proto_tree_add_item(tree, proto_rsh, tvb, offset,
78                     tvb_length_remaining(tvb, offset), FALSE);
79                 rsh_tree = proto_item_add_subtree(ti, ett_rsh);
80
81                 /*
82                  * Process the packet data, a line at a time.
83                  */
84                 while (tvb_offset_exists(tvb, offset)) {
85                         /*
86                          * Find the end of the line.
87                          */
88                         tvb_find_line_end(tvb, offset, -1, &next_offset);
89
90                         /*
91                          * Put this line.
92                          */
93                         proto_tree_add_text(rsh_tree, tvb, offset,
94                             next_offset - offset, "%s",
95                             tvb_format_text(tvb, offset, next_offset - offset));
96                         offset = next_offset;
97                 }
98
99                 if (pinfo->match_port == pinfo->destport) 
100                         proto_tree_add_boolean_hidden(rsh_tree, 
101                             hf_rsh_request, tvb, 0, 0, 1);
102                 else
103                         proto_tree_add_boolean_hidden(rsh_tree, 
104                             hf_rsh_response, tvb, 0, 0, 1);
105         }
106 }
107
108 void
109 proto_register_rsh(void)
110 {
111
112         static hf_register_info hf[] = {
113                 { &hf_rsh_response,
114                 { "Response",           "rsh.response",  
115                 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
116                 "TRUE if rsh response", HFILL }},
117                 { &hf_rsh_request,
118                 { "Request",            "rsh.request",
119                 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
120                 "TRUE if rsh request", HFILL }},
121         };
122
123         static gint *ett[] = {
124                 &ett_rsh,
125         };
126
127         proto_rsh = proto_register_protocol("Remote Shell", "RSH", "rsh");
128         proto_register_field_array(proto_rsh, hf, array_length(hf));
129         proto_register_subtree_array(ett, array_length(ett));
130 }
131
132 void
133 proto_reg_handoff_rsh(void)
134 {
135         dissector_add("tcp.port", TCP_PORT_RSH, dissect_rsh, proto_rsh);
136 }