2 * Routines for X.25 over TCP dissection (RFC 1613)
4 * Copyright 2000, Paul Ionescu <paul@acorp.ro>
6 * $Id: packet-xot.c,v 1.10 2002/04/09 08:15:02 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
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.
37 #include <epan/packet.h>
38 #include "packet-frame.h"
41 #define TCP_PORT_XOT 1998
43 static gint proto_xot = -1;
44 static gint hf_xot_version = -1;
45 static gint hf_xot_length = -1;
47 static gint ett_xot = -1;
49 /* desegmentation of X.25 over TCP */
50 static gboolean xot_desegment = TRUE;
52 static dissector_handle_t x25_handle;
54 static void dissect_xot(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
56 volatile int offset = 0;
65 while (tvb_reported_length_remaining(tvb, offset) != 0) {
66 length_remaining = tvb_length_remaining(tvb, offset);
69 * Can we do reassembly?
71 if (xot_desegment && pinfo->can_desegment) {
73 * Yes - is the X.25-over-TCP header split across segment boundaries?
75 if (length_remaining < 4) {
77 * Yes. Tell the TCP dissector where the data for this message
78 * starts in the data it handed us, and how many
79 * more bytes we need, and return.
81 pinfo->desegment_offset = offset;
82 pinfo->desegment_len = 4 - length_remaining;
88 * Get the length of the XOT packet.
90 version = tvb_get_ntohs(tvb, offset + 0);
93 plen = tvb_get_ntohs(tvb, offset + 2);
96 * Can we do reassembly?
98 if (xot_desegment && pinfo->can_desegment) {
100 * Yes - is the XOT packet split across segment boundaries?
102 if (length_remaining < plen + 4) {
104 * Yes. Tell the TCP dissector where the data for this message
105 * starts in the data it handed us, and how many more bytes we
108 pinfo->desegment_offset = offset;
109 pinfo->desegment_len = (plen + 4) - length_remaining;
115 * Dissect the X.25-over-TCP packet.
117 * Catch the ReportedBoundsError exception; if this particular message
118 * happens to get a ReportedBoundsError exception, that doesn't mean
119 * that we should stop dissecting X.25-over-TCP messages within this
120 * frame or chunk of reassembled data.
122 * If it gets a BoundsError, we can stop, as there's nothing more to see,
123 * so we just re-throw it.
126 if (check_col(pinfo->cinfo, COL_PROTOCOL))
127 col_set_str(pinfo->cinfo, COL_PROTOCOL, "XOT");
128 if (check_col(pinfo->cinfo, COL_INFO))
129 col_add_fstr(pinfo->cinfo, COL_INFO, "XOT Version = %u, size = %u",
133 ti = proto_tree_add_protocol_format(tree, proto_xot, tvb, offset, 4,
135 xot_tree = proto_item_add_subtree(ti, ett_xot);
137 proto_tree_add_uint(xot_tree, hf_xot_version, tvb, offset, 2, version);
138 proto_tree_add_uint(xot_tree, hf_xot_length, tvb, offset + 2, 2, plen);
142 * Construct a tvbuff containing the amount of the payload we have
143 * available. Make its reported length the amount of data in the
144 * X.25-over-TCP packet.
146 * XXX - if reassembly isn't enabled. the subdissector will throw a
147 * BoundsError exception, rather than a ReportedBoundsError exception.
148 * We really want a tvbuff where the length is "length", the reported
149 * length is "plen + 4", and the "if the snapshot length were infinite"
150 * length is the minimum of the reported length of the tvbuff handed
151 * to us and "plen+4", with a new type of exception thrown if the offset
152 * is within the reported length but beyond that third length, with that
153 * exception getting the "Unreassembled Packet" error.
155 length = length_remaining - 4;
158 next_tvb = tvb_new_subset(tvb, offset + 4, length, plen);
159 call_dissector(x25_handle,next_tvb,pinfo,tree);
164 CATCH(ReportedBoundsError) {
165 show_reported_bounds_error(tvb, pinfo, tree);
170 * Skip the X.25-over-TCP header and the payload.
176 /* Register the protocol with Ethereal */
178 proto_register_xot(void)
180 static hf_register_info hf[] = {
182 { "Version", "xot.version", FT_UINT16, BASE_DEC,
183 NULL, 0, "Version of X.25 over TCP protocol", HFILL }},
186 { "Length", "xot.length", FT_UINT16, BASE_DEC,
187 NULL, 0, "Length of X.25 over TCP packet", HFILL }}
191 static gint *ett[] = {
194 module_t *xot_module;
196 proto_xot = proto_register_protocol("X.25 over TCP", "XOT", "xot");
197 proto_register_field_array(proto_xot, hf, array_length(hf));
198 proto_register_subtree_array(ett, array_length(ett));
200 xot_module = prefs_register_protocol(proto_xot, NULL);
201 prefs_register_bool_preference(xot_module, "desegment",
202 "Desegment all X.25-over-TCP messages spanning multiple TCP segments",
203 "Whether the X.25-over-TCP dissector should desegment all messages spanning multiple TCP segments",
208 proto_reg_handoff_xot(void)
210 dissector_handle_t xot_handle;
213 * Get a handle for the X.25 dissector.
215 x25_handle = find_dissector("x.25");
217 xot_handle = create_dissector_handle(dissect_xot, proto_xot);
218 dissector_add("tcp.port", TCP_PORT_XOT, xot_handle);