aboutsummaryrefslogtreecommitdiffstats
path: root/packet-tns.c
blob: 6db58407ef0896c24a5de68bd7e1c3f2d3bba1ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/* packet-tns.c
 * Routines for MSX tns packet dissection
 *
 * $Id: packet-tns.c,v 1.1 1999/11/29 19:43:26 nneul Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@unicom.net>
 * Copyright 1998 Gerald Combs
 *
 * Copied from packet-tftp.c
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>

#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif

#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif

#include <string.h>
#include <glib.h>
#include "packet.h"
#include "packet-tns.h"

static int proto_tns = -1;
static int hf_tns_request = -1;
static int hf_tns_response = -1;
static int hf_tns_length = -1;
static int hf_tns_packet_checksum = -1;
static int hf_tns_header_checksum = -1;
static int hf_tns_packet_type = -1;
static int hf_tns_reserved_byte = -1;

static gint ett_tns = -1;

static const value_string tns_type_vals[] = {
		{TNS_TYPE_CONNECT, "Connect" },
		{TNS_TYPE_ACCEPT, "Accept" },
		{TNS_TYPE_DATA, "Data" },
		{TNS_TYPE_RESEND, "Resend"},
        {0, NULL}
};


/* Handy macro for checking for truncated packet */
#define TRUNC(length) if ( ! BYTES_ARE_IN_FRAME(offset, length)) { \
			dissect_data(pd,offset,fd,tree); return; }

void dissect_tns_data(const u_char *pd, int offset, frame_data *fd, 
	proto_tree *tree)
{
	dissect_data(pd,offset,fd,tree);
	return;
}

void dissect_tns_connect(const u_char *pd, int offset, frame_data *fd, 
	proto_tree *tree)
{
	dissect_data(pd,offset,fd,tree);
	return;
}

void dissect_tns_accept(const u_char *pd, int offset, frame_data *fd, 
	proto_tree *tree)
{
	dissect_data(pd,offset,fd,tree);
	return;
}


void
dissect_tns(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
{
	proto_tree      *tns_tree, *ti;
	guint16 length;
	guint16 type;

	if (check_col(fd, COL_PROTOCOL))
	col_add_str(fd, COL_PROTOCOL, "TNS");

	if (check_col(fd, COL_INFO))
	{
		col_add_fstr(fd, COL_INFO, "%s", 
			(pi.match_port == pi.destport) ? "Request" : "Response");	  
	}

	if (tree) 
	{
		ti = proto_tree_add_item(tree, proto_tns, offset, END_OF_FRAME, NULL);
		tns_tree = proto_item_add_subtree(ti, ett_tns);

		if (pi.match_port == pi.destport)
		{
			proto_tree_add_item_hidden(tns_tree, hf_tns_request,
			   offset, END_OF_FRAME, TRUE);
			proto_tree_add_text(tns_tree, offset, 
				END_OF_FRAME, "Request: <opaque data>" );
		}
		else
		{
			proto_tree_add_item_hidden(tns_tree, hf_tns_response,
				offset, END_OF_FRAME, TRUE);
			proto_tree_add_text(tns_tree, offset, 
				END_OF_FRAME, "Response: <opaque data>");
		}
	}

		/* check to make sure length is present */
	if ( ! BYTES_ARE_IN_FRAME(offset, 2)) return;

	length = pntohs(&pd[offset]);
	if (tree)
	{
		proto_tree_add_item(tns_tree, hf_tns_length,
			offset, 2, length);
	}
	TRUNC(length);
	offset += 2;

	TRUNC(2);
	if ( tree )
	{
		proto_tree_add_item(tns_tree, hf_tns_packet_checksum,
			offset, 2, pntohs(&pd[offset]));
	}
	offset += 2;

	TRUNC(2);
	type = pd[offset];
	if ( tree )
	{
		proto_tree_add_item(tns_tree, hf_tns_packet_type,
			offset, 1, type);
	}
	offset += 1;

	if ( check_col(fd, COL_INFO))
	{
		col_append_fstr(fd, COL_INFO, ", %s (%d)",
			val_to_str(type, tns_type_vals, "Unknown"), type);
	}

	TRUNC(1);
	if ( tree )
	{
		proto_tree_add_item(tns_tree, hf_tns_reserved_byte,
			offset, 1, &pd[offset]);
	}
	offset += 1;

	TRUNC(2);
	if ( tree )
	{
		proto_tree_add_item(tns_tree, hf_tns_header_checksum,
			offset, 2, pntohs(&pd[offset]));
	}
	offset += 2;

	switch (type)
	{
		case TNS_TYPE_CONNECT:
			dissect_tns_connect(pd,offset,fd,tree);
			break;
		case TNS_TYPE_ACCEPT:
			dissect_tns_accept(pd,offset,fd,tree);
			break;
		case TNS_TYPE_DATA:
			dissect_tns_data(pd,offset,fd,tree);
			break;
		default:
			dissect_data(pd,offset,fd,tree);
	}
}

void proto_register_tns(void)
{
	static hf_register_info hf[] = {
		{ &hf_tns_response, { 
			"Response", "tns.response", FT_BOOLEAN, BASE_NONE, 
			NULL, 0x0, "TRUE if TNS response" }},
		{ &hf_tns_request, { 
			"Request", "tns.request", FT_BOOLEAN, BASE_NONE, 
			NULL, 0x0, "TRUE if TNS request" }},
		{ &hf_tns_length, { 	
			"Packet Length", "tns.length", FT_UINT32, BASE_NONE, 
			NULL, 0x0, "Length of TNS packet" }},
		{ &hf_tns_packet_checksum, { 	
			"Packet Checksum", "tns.packet_checksum", FT_UINT16, BASE_HEX, 
			NULL, 0x0, "Checksum of Packet Data" }},
		{ &hf_tns_header_checksum, { 	
			"Header Checksum", "tns.header_checksum", FT_UINT16, BASE_HEX, 
			NULL, 0x0, "Checksum of Header Data" }},
		{ &hf_tns_reserved_byte, { 	
			"Reserved Byte", "tns.reserved_byte", FT_BYTES, BASE_HEX, 
			NULL, 0x0, "Reserved Byte" }},
		{ &hf_tns_packet_type, { 	
			"Packet Type", "tns.type", FT_UINT8, BASE_NONE, 
			VALS(tns_type_vals), 0x0, "Type of TNS packet" }}	
	};

	static gint *ett[] = {
		&ett_tns,
	};
	proto_tns = proto_register_protocol(
		"Transparent Network Substrate Protocol", "tns");
	proto_register_field_array(proto_tns, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));
}