2 * Routines for MSX tns packet dissection
4 * $Id: packet-tns.c,v 1.11 2001/01/03 06:55:34 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.org>
8 * Copyright 1998 Gerald Combs
10 * Copied from packet-tftp.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.
33 #ifdef HAVE_SYS_TYPES_H
34 # include <sys/types.h>
37 #ifdef HAVE_NETINET_IN_H
38 # include <netinet/in.h>
44 #include "packet-tns.h"
46 static int proto_tns = -1;
47 static int hf_tns_request = -1;
48 static int hf_tns_response = -1;
49 static int hf_tns_length = -1;
50 static int hf_tns_packet_checksum = -1;
51 static int hf_tns_header_checksum = -1;
52 static int hf_tns_packet_type = -1;
53 static int hf_tns_reserved_byte = -1;
54 static int hf_tns_data_flag = -1;
55 static int hf_tns_sns = -1;
56 static int hf_tns_connect = -1;
57 static int hf_tns_version = -1;
58 static int hf_tns_compat_version = -1;
59 static int hf_tns_service_options = -1;
61 static gint ett_tns = -1;
62 static gint ett_tns_sns = -1;
63 static gint ett_tns_connect = -1;
64 static gint ett_sql = -1;
66 #define TCP_PORT_TNS 1521
68 static const value_string tns_type_vals[] = {
69 {TNS_TYPE_CONNECT, "Connect" },
70 {TNS_TYPE_ACCEPT, "Accept" },
71 {TNS_TYPE_DATA, "Data" },
72 {TNS_TYPE_RESEND, "Resend"},
77 /* Handy macro for checking for truncated packet */
78 #define TRUNC(length) if ( ! BYTES_ARE_IN_FRAME(offset, length)) { \
79 old_dissect_data(pd,offset,fd,tree); return; }
81 static void dissect_tns_sns(const u_char *pd, int offset, frame_data *fd,
82 proto_tree *tree, proto_tree *tns_tree)
84 proto_tree *sns_tree = NULL, *ti;
88 ti = proto_tree_add_text(tns_tree, NullTVB, offset, END_OF_FRAME, "Secure Network Services");
89 sns_tree = proto_item_add_subtree(ti, ett_tns_sns);
91 proto_tree_add_boolean_hidden(tns_tree, hf_tns_sns, NullTVB, 0, 0, TRUE);
94 if ( check_col(fd, COL_INFO) )
96 col_append_fstr(fd, COL_INFO, ", SNS");
101 old_dissect_data(pd,offset,fd,sns_tree);
105 static void dissect_tns_data(const u_char *pd, int offset, frame_data *fd,
106 proto_tree *tree, proto_tree *tns_tree)
112 proto_tree_add_uint(tns_tree, hf_tns_data_flag, NullTVB,
113 offset, 2, pntohs(&pd[offset]));
117 if ( BYTES_ARE_IN_FRAME(offset, 4) )
119 if ( pd[offset] == 0xDE && pd[offset+1] == 0xAD &&
120 pd[offset+2] == 0xBE && pd[offset+3] == 0xEF )
122 dissect_tns_sns(pd,offset,fd,tree,tns_tree);
127 old_dissect_data(pd,offset,fd,tree);
131 static void dissect_tns_connect(const u_char *pd, int offset, frame_data *fd,
132 proto_tree *tree, proto_tree *tns_tree)
134 proto_tree *connect_tree = NULL, *ti;
138 ti = proto_tree_add_text(tns_tree, NullTVB, offset, END_OF_FRAME, "Connect");
139 connect_tree = proto_item_add_subtree(ti, ett_tns_connect);
141 proto_tree_add_boolean_hidden(tns_tree, hf_tns_connect, NullTVB, 0, 0, TRUE);
144 if ( check_col(fd, COL_INFO) )
146 col_append_fstr(fd, COL_INFO, ", Connect");
152 proto_tree_add_uint(connect_tree, hf_tns_version, NullTVB,
153 offset, 2, pntohs(&pd[offset]));
160 proto_tree_add_uint(connect_tree, hf_tns_compat_version, NullTVB,
161 offset, 2, pntohs(&pd[offset]));
168 /* need to break down w/ bitfield */
169 proto_tree_add_uint(connect_tree, hf_tns_service_options, NullTVB,
170 offset, 2, pntohs(&pd[offset]));
176 old_dissect_data(pd,offset,fd,connect_tree);
181 static void dissect_tns_accept(const u_char *pd, int offset, frame_data *fd,
182 proto_tree *tree, proto_tree *tns_tree)
184 old_dissect_data(pd,offset,fd,tns_tree);
190 dissect_tns(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
192 proto_tree *tns_tree = NULL, *ti;
196 OLD_CHECK_DISPLAY_AS_DATA(proto_tns, pd, offset, fd, tree);
198 if (check_col(fd, COL_PROTOCOL))
199 col_set_str(fd, COL_PROTOCOL, "TNS");
201 if (check_col(fd, COL_INFO))
203 col_add_fstr(fd, COL_INFO, "%s",
204 (pi.match_port == pi.destport) ? "Request" : "Response");
209 ti = proto_tree_add_item(tree, proto_tns, NullTVB, offset, END_OF_FRAME, FALSE);
210 tns_tree = proto_item_add_subtree(ti, ett_tns);
212 if (pi.match_port == pi.destport)
214 proto_tree_add_boolean_hidden(tns_tree, hf_tns_request, NullTVB,
215 offset, END_OF_FRAME, TRUE);
216 proto_tree_add_text(tns_tree, NullTVB, offset,
217 END_OF_FRAME, "Request: <opaque data>" );
221 proto_tree_add_boolean_hidden(tns_tree, hf_tns_response, NullTVB,
222 offset, END_OF_FRAME, TRUE);
223 proto_tree_add_text(tns_tree, NullTVB, offset,
224 END_OF_FRAME, "Response: <opaque data>");
228 /* check to make sure length is present */
229 if ( ! BYTES_ARE_IN_FRAME(offset, 2)) return;
231 length = pntohs(&pd[offset]);
234 proto_tree_add_uint(tns_tree, hf_tns_length, NullTVB,
243 proto_tree_add_uint(tns_tree, hf_tns_packet_checksum, NullTVB,
244 offset, 2, pntohs(&pd[offset]));
252 proto_tree_add_uint(tns_tree, hf_tns_packet_type, NullTVB,
257 if ( check_col(fd, COL_INFO))
259 col_append_fstr(fd, COL_INFO, ", %s (%d)",
260 val_to_str(type, tns_type_vals, "Unknown"), type);
266 proto_tree_add_bytes(tns_tree, hf_tns_reserved_byte, NullTVB,
267 offset, 1, &pd[offset]);
274 proto_tree_add_uint(tns_tree, hf_tns_header_checksum, NullTVB,
275 offset, 2, pntohs(&pd[offset]));
281 case TNS_TYPE_CONNECT:
282 dissect_tns_connect(pd,offset,fd,tree,tns_tree);
284 case TNS_TYPE_ACCEPT:
285 dissect_tns_accept(pd,offset,fd,tree,tns_tree);
288 dissect_tns_data(pd,offset,fd,tree,tns_tree);
291 old_dissect_data(pd,offset,fd,tns_tree);
295 void proto_register_tns(void)
297 static hf_register_info hf[] = {
299 "Secure Network Services", "tns.sns", FT_BOOLEAN, BASE_NONE,
300 NULL, 0x0, "Secure Network Services" }},
302 "Connect", "tns.connect", FT_BOOLEAN, BASE_NONE,
303 NULL, 0x0, "Connect" }},
304 { &hf_tns_response, {
305 "Response", "tns.response", FT_BOOLEAN, BASE_NONE,
306 NULL, 0x0, "TRUE if TNS response" }},
308 "Request", "tns.request", FT_BOOLEAN, BASE_NONE,
309 NULL, 0x0, "TRUE if TNS request" }},
311 "Packet Length", "tns.length", FT_UINT32, BASE_NONE,
312 NULL, 0x0, "Length of TNS packet" }},
313 { &hf_tns_packet_checksum, {
314 "Packet Checksum", "tns.packet_checksum", FT_UINT16, BASE_HEX,
315 NULL, 0x0, "Checksum of Packet Data" }},
316 { &hf_tns_header_checksum, {
317 "Header Checksum", "tns.header_checksum", FT_UINT16, BASE_HEX,
318 NULL, 0x0, "Checksum of Header Data" }},
319 { &hf_tns_data_flag, {
320 "Data Flag", "tns.data_flag", FT_UINT16, BASE_HEX,
321 NULL, 0x0, "Data Flag" }},
323 "Version", "tns.version", FT_UINT16, BASE_DEC,
324 NULL, 0x0, "Version" }},
325 { &hf_tns_compat_version, {
326 "Version (Compatible)", "tns.compat_version", FT_UINT16, BASE_DEC,
327 NULL, 0x0, "Version (Compatible)" }},
328 { &hf_tns_service_options, {
329 "Service Options", "tns.service_options", FT_UINT16, BASE_HEX,
330 NULL, 0x0, "Service Options" }},
331 { &hf_tns_reserved_byte, {
332 "Reserved Byte", "tns.reserved_byte", FT_BYTES, BASE_HEX,
333 NULL, 0x0, "Reserved Byte" }},
334 { &hf_tns_packet_type, {
335 "Packet Type", "tns.type", FT_UINT8, BASE_NONE,
336 VALS(tns_type_vals), 0x0, "Type of TNS packet" }}
339 static gint *ett[] = {
345 proto_tns = proto_register_protocol(
346 "Transparent Network Substrate Protocol", "TNS", "tns");
347 proto_register_field_array(proto_tns, hf, array_length(hf));
348 proto_register_subtree_array(ett, array_length(ett));
352 proto_reg_handoff_tns(void)
354 old_dissector_add("tcp.port", TCP_PORT_TNS, dissect_tns);