1999-08-18 00:57:54 +00:00
|
|
|
/* packet-telnet.c
|
1999-04-05 21:54:41 +00:00
|
|
|
* Routines for telnet packet dissection
|
|
|
|
* Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
|
|
|
|
*
|
2002-08-28 21:04:11 +00:00
|
|
|
* $Id: packet-telnet.c,v 1.32 2002/08/28 21:00:36 jmayer Exp $
|
1999-04-05 21:54:41 +00:00
|
|
|
*
|
|
|
|
* Ethereal - Network traffic analyzer
|
2001-12-03 04:00:26 +00:00
|
|
|
* By Gerald Combs <gerald@ethereal.com>
|
1999-04-05 21:54:41 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* Copied from packet-pop.c
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-04-05 21:54:41 +00:00
|
|
|
* 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-04-05 21:54:41 +00:00
|
|
|
* 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-04-05 21:54:41 +00:00
|
|
|
* 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>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/strutil.h>
|
1999-04-05 21:54:41 +00:00
|
|
|
|
1999-07-29 05:47:07 +00:00
|
|
|
static int proto_telnet = -1;
|
|
|
|
|
1999-11-16 11:44:20 +00:00
|
|
|
static gint ett_telnet = -1;
|
|
|
|
static gint ett_telnet_subopt = -1;
|
|
|
|
|
1999-04-05 21:54:41 +00:00
|
|
|
/* Some defines for Telnet */
|
|
|
|
|
2000-04-08 07:07:42 +00:00
|
|
|
#define TCP_PORT_TELNET 23
|
|
|
|
|
1999-04-05 21:54:41 +00:00
|
|
|
#define TN_IAC 255
|
|
|
|
#define TN_DONT 254
|
|
|
|
#define TN_DO 253
|
|
|
|
#define TN_WONT 252
|
|
|
|
#define TN_WILL 251
|
|
|
|
#define TN_SB 250
|
|
|
|
#define TN_GA 249
|
|
|
|
#define TN_EL 248
|
|
|
|
#define TN_EC 247
|
|
|
|
#define TN_AYT 246
|
|
|
|
#define TN_AO 245
|
|
|
|
#define TN_IP 244
|
|
|
|
#define TN_BRK 243
|
|
|
|
#define TN_DM 242
|
|
|
|
#define TN_NOP 241
|
|
|
|
#define TN_SE 240
|
|
|
|
#define TN_EOR 239
|
|
|
|
#define TN_ABORT 238
|
|
|
|
#define TN_SUSP 237
|
|
|
|
#define TN_EOF 236
|
|
|
|
|
2000-03-23 10:25:38 +00:00
|
|
|
static const char *options[] = {
|
1999-04-05 21:54:41 +00:00
|
|
|
"Binary Transmission",
|
|
|
|
"Echo",
|
|
|
|
"Reconnection",
|
|
|
|
"Suppress Go Ahead",
|
|
|
|
"Approx Message Size Negotiation",
|
|
|
|
"Status",
|
|
|
|
"Timing Mark",
|
|
|
|
"Remote Controlled Trans and Echo",
|
|
|
|
"Output Line Width",
|
|
|
|
"Output Page Size",
|
|
|
|
"Output Carriage-Return Disposition",
|
|
|
|
"Output Horizontal Tab Stops",
|
|
|
|
"Output Horizontal Tab Disposition",
|
|
|
|
"Output Formfeed Disposition",
|
|
|
|
"Output Vertical Tabstops",
|
|
|
|
"Output Vertical Tab Disposition",
|
|
|
|
"Output Linefeed Disposition",
|
|
|
|
"Extended ASCII",
|
|
|
|
"Logout",
|
|
|
|
"Byte Macro",
|
|
|
|
"Data Entry Terminal",
|
|
|
|
"SUPDUP",
|
|
|
|
"SUPDUP Output",
|
|
|
|
"Send Location",
|
|
|
|
"Terminal Type",
|
|
|
|
"End of Record",
|
|
|
|
"TACACS User Identification",
|
|
|
|
"Output Marking",
|
|
|
|
"Terminal Location Number",
|
|
|
|
"Telnet 3270 Regime",
|
|
|
|
"X.3 PAD",
|
|
|
|
"Negotiate About Window Size",
|
|
|
|
"Terminal Speed",
|
|
|
|
"Remote Flow Control",
|
|
|
|
"Linemode",
|
|
|
|
"X Display Location",
|
|
|
|
"Environment Option",
|
|
|
|
"Authentication Option",
|
|
|
|
"Encryption Option",
|
|
|
|
"New Environment Option",
|
|
|
|
"TN3270E"
|
|
|
|
};
|
|
|
|
|
2000-03-23 10:25:38 +00:00
|
|
|
#define NOPTIONS (sizeof options / sizeof options[0])
|
|
|
|
|
|
|
|
static int
|
2000-11-09 10:56:33 +00:00
|
|
|
telnet_sub_option(proto_tree *telnet_tree, tvbuff_t *tvb, int start_offset)
|
1999-04-05 21:54:41 +00:00
|
|
|
{
|
|
|
|
proto_tree *ti, *option_tree;
|
2000-03-23 10:25:38 +00:00
|
|
|
int offset = start_offset;
|
2000-11-09 10:56:33 +00:00
|
|
|
guint8 opt_byte;
|
2000-03-23 10:25:38 +00:00
|
|
|
int subneg_len, req;
|
2002-08-02 23:36:07 +00:00
|
|
|
const guchar *opt;
|
2000-11-09 10:56:33 +00:00
|
|
|
guint len;
|
1999-04-05 21:54:41 +00:00
|
|
|
|
2000-03-23 10:25:38 +00:00
|
|
|
offset += 2; /* skip IAC and SB */
|
1999-04-05 21:54:41 +00:00
|
|
|
|
|
|
|
/* Figure out the option and type */
|
2000-11-09 10:56:33 +00:00
|
|
|
opt_byte = tvb_get_guint8(tvb, offset);
|
|
|
|
if (opt_byte > NOPTIONS)
|
2000-03-23 10:25:38 +00:00
|
|
|
opt = "<unknown option>";
|
|
|
|
else
|
2000-11-09 10:56:33 +00:00
|
|
|
opt = options[opt_byte];
|
2000-03-23 10:25:38 +00:00
|
|
|
offset++;
|
2000-11-09 10:56:33 +00:00
|
|
|
req = tvb_get_guint8(tvb, offset);
|
2000-03-23 10:25:38 +00:00
|
|
|
offset++;
|
|
|
|
|
2000-11-09 10:56:33 +00:00
|
|
|
/* Search for an IAC. */
|
|
|
|
len = tvb_length_remaining(tvb, offset);
|
|
|
|
offset = tvb_find_guint8(tvb, offset, len, TN_IAC);
|
|
|
|
if (offset == -1) {
|
|
|
|
/* None found - run to the end of the packet. */
|
|
|
|
offset += len;
|
1999-04-05 21:54:41 +00:00
|
|
|
}
|
|
|
|
|
2000-03-23 10:25:38 +00:00
|
|
|
subneg_len = offset - start_offset;
|
1999-04-05 21:54:41 +00:00
|
|
|
|
2001-10-26 02:55:20 +00:00
|
|
|
if (subneg_len > 0) {
|
|
|
|
ti = proto_tree_add_text(telnet_tree, tvb, start_offset, subneg_len,
|
|
|
|
"Suboption Begin: %s", opt);
|
1999-04-05 21:54:41 +00:00
|
|
|
|
2001-10-26 02:55:20 +00:00
|
|
|
option_tree = proto_item_add_subtree(ti, ett_telnet_subopt);
|
1999-04-05 21:54:41 +00:00
|
|
|
|
2001-10-26 02:55:20 +00:00
|
|
|
proto_tree_add_text(option_tree, tvb, start_offset + 2, 2,
|
|
|
|
"%s %s", (req ? "Send your" : "Here's my"), opt);
|
1999-04-05 21:54:41 +00:00
|
|
|
|
2001-10-26 02:55:20 +00:00
|
|
|
if (req == 0) { /* Add the value */
|
|
|
|
proto_tree_add_text(option_tree, tvb, start_offset + 4, subneg_len - 4,
|
|
|
|
"Value: %s", tvb_format_text(tvb, start_offset + 4, subneg_len - 4));
|
|
|
|
}
|
1999-04-05 21:54:41 +00:00
|
|
|
}
|
2000-03-23 10:25:38 +00:00
|
|
|
return offset;
|
|
|
|
}
|
1999-04-05 21:54:41 +00:00
|
|
|
|
2000-03-23 10:25:38 +00:00
|
|
|
static int
|
2000-11-09 10:56:33 +00:00
|
|
|
telnet_will_wont_do_dont(proto_tree *telnet_tree, tvbuff_t *tvb,
|
2000-03-23 10:25:38 +00:00
|
|
|
int start_offset, char *type)
|
|
|
|
{
|
|
|
|
int offset = start_offset;
|
2000-11-09 10:56:33 +00:00
|
|
|
guint8 opt_byte;
|
2000-03-23 10:25:38 +00:00
|
|
|
const char *opt;
|
|
|
|
|
|
|
|
offset += 2; /* skip IAC and WILL,WONT,DO,DONT} */
|
2000-11-09 10:56:33 +00:00
|
|
|
opt_byte = tvb_get_guint8(tvb, offset);
|
|
|
|
if (opt_byte > NOPTIONS)
|
2000-03-23 10:25:38 +00:00
|
|
|
opt = "<unknown option>";
|
|
|
|
else
|
2000-11-09 10:56:33 +00:00
|
|
|
opt = options[opt_byte];
|
2000-03-23 10:25:38 +00:00
|
|
|
offset++;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-11-09 10:56:33 +00:00
|
|
|
proto_tree_add_text(telnet_tree, tvb, start_offset, 3,
|
2000-03-23 10:25:38 +00:00
|
|
|
"Command: %s %s", type, opt);
|
|
|
|
return offset;
|
1999-04-05 21:54:41 +00:00
|
|
|
}
|
|
|
|
|
2000-03-23 10:25:38 +00:00
|
|
|
static int
|
2000-11-09 10:56:33 +00:00
|
|
|
telnet_command(proto_tree *telnet_tree, tvbuff_t *tvb, int start_offset)
|
1999-04-05 21:54:41 +00:00
|
|
|
{
|
2000-03-23 10:25:38 +00:00
|
|
|
int offset = start_offset;
|
2002-08-02 23:36:07 +00:00
|
|
|
guchar optcode;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-03-23 10:25:38 +00:00
|
|
|
offset += 1; /* skip IAC */
|
2000-11-09 10:56:33 +00:00
|
|
|
optcode = tvb_get_guint8(tvb, offset);
|
2000-03-23 10:25:38 +00:00
|
|
|
offset++;
|
|
|
|
switch(optcode) {
|
1999-04-05 21:54:41 +00:00
|
|
|
|
|
|
|
case TN_EOF:
|
2000-11-09 10:56:33 +00:00
|
|
|
proto_tree_add_text(telnet_tree, tvb, start_offset, 2,
|
2000-03-23 10:25:38 +00:00
|
|
|
"Command: End of File");
|
1999-04-05 21:54:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TN_SUSP:
|
2000-11-09 10:56:33 +00:00
|
|
|
proto_tree_add_text(telnet_tree, tvb, start_offset, 2,
|
2000-03-23 10:25:38 +00:00
|
|
|
"Command: Suspend Current Process");
|
1999-04-05 21:54:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TN_ABORT:
|
2000-11-09 10:56:33 +00:00
|
|
|
proto_tree_add_text(telnet_tree, tvb, start_offset, 2,
|
2000-03-23 10:25:38 +00:00
|
|
|
"Command: Abort Process");
|
1999-04-05 21:54:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TN_EOR:
|
2000-11-09 10:56:33 +00:00
|
|
|
proto_tree_add_text(telnet_tree, tvb, start_offset, 2,
|
2000-03-23 10:25:38 +00:00
|
|
|
"Command: End of Record");
|
1999-04-05 21:54:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TN_SE:
|
2000-11-09 10:56:33 +00:00
|
|
|
proto_tree_add_text(telnet_tree, tvb, start_offset, 2,
|
2000-03-23 10:25:38 +00:00
|
|
|
"Command: Suboption End");
|
1999-04-05 21:54:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TN_NOP:
|
2000-11-09 10:56:33 +00:00
|
|
|
proto_tree_add_text(telnet_tree, tvb, start_offset, 2,
|
2000-03-23 10:25:38 +00:00
|
|
|
"Command: No Operation");
|
1999-04-05 21:54:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TN_DM:
|
2000-11-09 10:56:33 +00:00
|
|
|
proto_tree_add_text(telnet_tree, tvb, start_offset, 2,
|
2000-03-23 10:25:38 +00:00
|
|
|
"Command: Data Mark");
|
1999-04-05 21:54:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TN_BRK:
|
2000-11-09 10:56:33 +00:00
|
|
|
proto_tree_add_text(telnet_tree, tvb, start_offset, 2,
|
2000-03-23 10:25:38 +00:00
|
|
|
"Command: Break");
|
1999-04-05 21:54:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TN_IP:
|
2000-11-09 10:56:33 +00:00
|
|
|
proto_tree_add_text(telnet_tree, tvb, start_offset, 2,
|
2000-03-23 10:25:38 +00:00
|
|
|
"Command: Interrupt Process");
|
1999-04-05 21:54:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TN_AO:
|
2000-11-09 10:56:33 +00:00
|
|
|
proto_tree_add_text(telnet_tree, tvb, start_offset, 2,
|
2000-03-23 10:25:38 +00:00
|
|
|
"Command: Abort Output");
|
1999-04-05 21:54:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TN_AYT:
|
2000-11-09 10:56:33 +00:00
|
|
|
proto_tree_add_text(telnet_tree, tvb, start_offset, 2,
|
2000-03-23 10:25:38 +00:00
|
|
|
"Command: Are You There?");
|
1999-04-05 21:54:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TN_EC:
|
2000-11-09 10:56:33 +00:00
|
|
|
proto_tree_add_text(telnet_tree, tvb, start_offset, 2,
|
2000-03-23 10:25:38 +00:00
|
|
|
"Command: Escape Character");
|
1999-04-05 21:54:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TN_EL:
|
2000-11-09 10:56:33 +00:00
|
|
|
proto_tree_add_text(telnet_tree, tvb, start_offset, 2,
|
2000-03-23 10:25:38 +00:00
|
|
|
"Command: Erase Line");
|
1999-04-05 21:54:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TN_GA:
|
2000-11-09 10:56:33 +00:00
|
|
|
proto_tree_add_text(telnet_tree, tvb, start_offset, 2,
|
2000-03-23 10:25:38 +00:00
|
|
|
"Command: Go Ahead");
|
1999-04-05 21:54:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TN_SB:
|
2000-11-09 10:56:33 +00:00
|
|
|
offset = telnet_sub_option(telnet_tree, tvb, start_offset);
|
1999-04-05 21:54:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TN_WILL:
|
2000-11-09 10:56:33 +00:00
|
|
|
offset = telnet_will_wont_do_dont(telnet_tree, tvb, start_offset,
|
2000-03-23 10:25:38 +00:00
|
|
|
"Will");
|
1999-04-05 21:54:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TN_WONT:
|
2000-11-09 10:56:33 +00:00
|
|
|
offset = telnet_will_wont_do_dont(telnet_tree, tvb, start_offset,
|
2000-03-23 10:25:38 +00:00
|
|
|
"Won't");
|
1999-04-05 21:54:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TN_DO:
|
2000-11-09 10:56:33 +00:00
|
|
|
offset = telnet_will_wont_do_dont(telnet_tree, tvb, start_offset,
|
2000-03-23 10:25:38 +00:00
|
|
|
"Do");
|
1999-04-05 21:54:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TN_DONT:
|
2000-11-09 10:56:33 +00:00
|
|
|
offset = telnet_will_wont_do_dont(telnet_tree, tvb, start_offset,
|
2000-03-23 10:25:38 +00:00
|
|
|
"Don't");
|
1999-04-05 21:54:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-03-23 10:25:38 +00:00
|
|
|
return offset;
|
1999-04-05 21:54:41 +00:00
|
|
|
}
|
|
|
|
|
2000-09-29 19:06:12 +00:00
|
|
|
static void
|
2000-11-09 10:56:33 +00:00
|
|
|
telnet_add_text(proto_tree *tree, tvbuff_t *tvb, int offset, int len)
|
2000-09-29 19:06:12 +00:00
|
|
|
{
|
2000-11-09 10:56:33 +00:00
|
|
|
gint next_offset;
|
2000-09-29 19:06:12 +00:00
|
|
|
int linelen;
|
2000-11-12 00:59:09 +00:00
|
|
|
guint8 c;
|
|
|
|
gboolean last_char_was_cr;
|
2000-09-29 19:06:12 +00:00
|
|
|
|
2000-11-13 08:58:17 +00:00
|
|
|
while (len != 0 && tvb_offset_exists(tvb, offset)) {
|
2000-09-29 19:06:12 +00:00
|
|
|
/*
|
|
|
|
* Find the end of the line.
|
|
|
|
*/
|
2002-07-17 06:55:29 +00:00
|
|
|
linelen = tvb_find_line_end(tvb, offset, len, &next_offset, FALSE);
|
2000-11-12 00:59:09 +00:00
|
|
|
len -= next_offset - offset; /* subtract out the line's characters */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In Telnet, CR NUL is the way you send a CR by itself in the
|
|
|
|
* default ASCII mode; don't treat CR by itself as a line ending,
|
|
|
|
* treat only CR NUL, CR LF, or LF by itself as a line ending.
|
|
|
|
*/
|
|
|
|
if (next_offset == offset + linelen + 1 && len >= 1) {
|
|
|
|
/*
|
|
|
|
* Well, we saw a one-character line ending, so either it's a CR
|
|
|
|
* or an LF; we have at least two characters left, including the
|
|
|
|
* CR.
|
|
|
|
*
|
|
|
|
* If the line ending is a CR, skip all subsequent CRs; at
|
|
|
|
* least one capture appeared to have multiple CRs at the end of
|
|
|
|
* a line.
|
|
|
|
*/
|
|
|
|
if (tvb_get_guint8(tvb, offset + linelen) == '\r') {
|
|
|
|
last_char_was_cr = TRUE;
|
2000-11-13 08:58:17 +00:00
|
|
|
while (len != 0 && tvb_offset_exists(tvb, next_offset)) {
|
2000-11-12 00:59:09 +00:00
|
|
|
c = tvb_get_guint8(tvb, next_offset);
|
|
|
|
next_offset++; /* skip over that character */
|
|
|
|
len--;
|
|
|
|
if (c == '\n' || (c == '\0' && last_char_was_cr)) {
|
|
|
|
/*
|
|
|
|
* LF is a line ending, whether preceded by CR or not.
|
|
|
|
* NUL is a line ending if preceded by CR.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
last_char_was_cr = (c == '\r');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now compute the length of the line *including* the end-of-line
|
|
|
|
* indication, if any; we display it all.
|
|
|
|
*/
|
2000-11-09 10:56:33 +00:00
|
|
|
linelen = next_offset - offset;
|
2000-09-29 19:06:12 +00:00
|
|
|
|
2000-11-09 10:56:33 +00:00
|
|
|
proto_tree_add_text(tree, tvb, offset, linelen,
|
|
|
|
"Data: %s",
|
|
|
|
tvb_format_text(tvb, offset, linelen));
|
2000-11-12 00:59:09 +00:00
|
|
|
offset = next_offset;
|
2000-09-29 19:06:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-08 07:07:42 +00:00
|
|
|
static void
|
2000-11-09 10:56:33 +00:00
|
|
|
dissect_telnet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
1999-04-05 21:54:41 +00:00
|
|
|
{
|
|
|
|
proto_tree *telnet_tree, *ti;
|
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_PROTOCOL))
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "TELNET");
|
2000-11-09 10:56:33 +00:00
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
|
|
|
col_add_fstr(pinfo->cinfo, COL_INFO, "Telnet Data ...");
|
1999-04-05 21:54:41 +00:00
|
|
|
|
|
|
|
if (tree) {
|
2000-11-09 10:56:33 +00:00
|
|
|
gint offset = 0;
|
|
|
|
guint len;
|
2000-03-23 10:25:38 +00:00
|
|
|
int data_len;
|
2000-11-09 10:56:33 +00:00
|
|
|
gint iac_offset;
|
1999-04-05 21:54:41 +00:00
|
|
|
|
2002-01-24 09:20:54 +00:00
|
|
|
ti = proto_tree_add_item(tree, proto_telnet, tvb, offset, -1, FALSE);
|
1999-11-16 11:44:20 +00:00
|
|
|
telnet_tree = proto_item_add_subtree(ti, ett_telnet);
|
1999-04-05 21:54:41 +00:00
|
|
|
|
2000-03-23 10:25:38 +00:00
|
|
|
/*
|
|
|
|
* Scan through the buffer looking for an IAC byte.
|
|
|
|
*/
|
2000-11-13 08:58:17 +00:00
|
|
|
while ((len = tvb_length_remaining(tvb, offset)) > 0) {
|
2000-11-09 10:56:33 +00:00
|
|
|
iac_offset = tvb_find_guint8(tvb, offset, len, TN_IAC);
|
|
|
|
if (iac_offset != -1) {
|
2000-03-23 10:25:38 +00:00
|
|
|
/*
|
|
|
|
* We found an IAC byte.
|
|
|
|
* If there's any data before it, add that data to the
|
2000-09-29 19:06:12 +00:00
|
|
|
* tree, a line at a time.
|
2000-03-23 10:25:38 +00:00
|
|
|
*/
|
2000-11-09 10:56:33 +00:00
|
|
|
data_len = iac_offset - offset;
|
|
|
|
if (data_len > 0)
|
|
|
|
telnet_add_text(telnet_tree, tvb, offset, data_len);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-03-23 10:25:38 +00:00
|
|
|
/*
|
|
|
|
* Now interpret the command.
|
|
|
|
*/
|
2000-11-09 10:56:33 +00:00
|
|
|
offset = telnet_command(telnet_tree, tvb, iac_offset);
|
1999-04-05 21:54:41 +00:00
|
|
|
}
|
|
|
|
else {
|
2000-11-09 10:56:33 +00:00
|
|
|
/*
|
|
|
|
* We found no IAC byte, so what remains in the buffer
|
|
|
|
* is the last of the data in the packet.
|
|
|
|
* Add it to the tree, a line at a time, and then quit.
|
|
|
|
*/
|
|
|
|
telnet_add_text(telnet_tree, tvb, offset, len);
|
|
|
|
break;
|
1999-04-05 21:54:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-29 05:47:07 +00:00
|
|
|
void
|
|
|
|
proto_register_telnet(void)
|
|
|
|
{
|
|
|
|
/* static hf_register_info hf[] = {
|
|
|
|
{ &variable,
|
|
|
|
{ "Name", "telnet.abbreviation", TYPE, VALS_POINTER }},
|
|
|
|
};*/
|
1999-11-16 11:44:20 +00:00
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_telnet,
|
|
|
|
&ett_telnet_subopt,
|
|
|
|
};
|
1999-04-05 21:54:41 +00:00
|
|
|
|
2001-01-03 06:56:03 +00:00
|
|
|
proto_telnet = proto_register_protocol("Telnet", "TELNET", "telnet");
|
1999-07-29 05:47:07 +00:00
|
|
|
/* proto_register_field_array(proto_telnet, hf, array_length(hf));*/
|
1999-11-16 11:44:20 +00:00
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
1999-07-29 05:47:07 +00:00
|
|
|
}
|
2000-04-08 07:07:42 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_telnet(void)
|
|
|
|
{
|
2001-12-03 04:00:26 +00:00
|
|
|
dissector_handle_t telnet_handle;
|
|
|
|
|
|
|
|
telnet_handle = create_dissector_handle(dissect_telnet, proto_telnet);
|
|
|
|
dissector_add("tcp.port", TCP_PORT_TELNET, telnet_handle);
|
2000-04-08 07:07:42 +00:00
|
|
|
}
|