1998-09-16 02:39:15 +00:00
|
|
|
/* packet-tcp.c
|
|
|
|
* Routines for TCP packet disassembly
|
|
|
|
*
|
1999-06-11 15:30:55 +00:00
|
|
|
* $Id: packet-tcp.c,v 1.24 1999/06/11 15:30:40 gram Exp $
|
1998-09-16 03:22:19 +00:00
|
|
|
*
|
1998-09-16 02:39:15 +00:00
|
|
|
* Ethereal - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@zing.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
# include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
# include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
|
1999-03-23 03:14:46 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <glib.h>
|
1998-09-16 02:39:15 +00:00
|
|
|
#include "packet.h"
|
1998-11-18 01:49:12 +00:00
|
|
|
#include "resolv.h"
|
1998-09-27 22:12:47 +00:00
|
|
|
#include "follow.h"
|
1998-12-29 04:05:38 +00:00
|
|
|
#include "util.h"
|
1998-09-16 02:39:15 +00:00
|
|
|
|
1999-03-23 03:58:59 +00:00
|
|
|
#ifdef NEED_SNPRINTF_H
|
|
|
|
# ifdef HAVE_STDARG_H
|
|
|
|
# include <stdarg.h>
|
|
|
|
# else
|
|
|
|
# include <varargs.h>
|
|
|
|
# endif
|
|
|
|
# include "snprintf.h"
|
|
|
|
#endif
|
|
|
|
|
1999-03-23 03:14:46 +00:00
|
|
|
#ifndef __PACKET_IP_H__
|
|
|
|
#include "packet-ip.h"
|
|
|
|
#endif
|
|
|
|
|
1998-09-17 03:12:28 +00:00
|
|
|
extern FILE* data_out_file;
|
|
|
|
extern packet_info pi;
|
|
|
|
|
1998-12-21 03:43:29 +00:00
|
|
|
static gchar info_str[COL_MAX_LEN];
|
|
|
|
static int info_len;
|
|
|
|
|
1999-03-23 03:14:46 +00:00
|
|
|
/* TCP Ports */
|
|
|
|
|
1999-04-05 21:54:41 +00:00
|
|
|
#define TCP_PORT_FTPDATA 20
|
|
|
|
#define TCP_PORT_FTP 21
|
|
|
|
#define TCP_PORT_TELNET 23
|
|
|
|
#define TCP_PORT_SMTP 25
|
1999-03-23 03:14:46 +00:00
|
|
|
#define TCP_PORT_HTTP 80
|
1999-04-05 21:54:41 +00:00
|
|
|
#define TCP_PORT_POP 110
|
1999-04-06 02:02:12 +00:00
|
|
|
#define TCP_PORT_NNTP 119
|
1999-04-30 03:16:03 +00:00
|
|
|
#define TCP_PORT_NBSS 139
|
1999-03-23 03:14:46 +00:00
|
|
|
#define TCP_PORT_PRINTER 515
|
|
|
|
#define TCP_ALT_PORT_HTTP 8080
|
1999-06-11 15:30:55 +00:00
|
|
|
#define TCP_PORT_PPTP 1723
|
1999-03-23 03:14:46 +00:00
|
|
|
|
|
|
|
/* TCP structs and definitions */
|
|
|
|
|
|
|
|
typedef struct _e_tcphdr {
|
|
|
|
guint16 th_sport;
|
|
|
|
guint16 th_dport;
|
|
|
|
guint32 th_seq;
|
|
|
|
guint32 th_ack;
|
|
|
|
guint8 th_off_x2; /* combines th_off and th_x2 */
|
|
|
|
guint8 th_flags;
|
|
|
|
#define TH_FIN 0x01
|
|
|
|
#define TH_SYN 0x02
|
|
|
|
#define TH_RST 0x04
|
|
|
|
#define TH_PUSH 0x08
|
|
|
|
#define TH_ACK 0x10
|
|
|
|
#define TH_URG 0x20
|
|
|
|
guint16 th_win;
|
|
|
|
guint16 th_sum;
|
|
|
|
guint16 th_urp;
|
|
|
|
} e_tcphdr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TCP option
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define TCPOPT_NOP 1 /* Padding */
|
|
|
|
#define TCPOPT_EOL 0 /* End of options */
|
|
|
|
#define TCPOPT_MSS 2 /* Segment size negotiating */
|
|
|
|
#define TCPOPT_WINDOW 3 /* Window scaling */
|
|
|
|
#define TCPOPT_SACK_PERM 4 /* SACK Permitted */
|
|
|
|
#define TCPOPT_SACK 5 /* SACK Block */
|
|
|
|
#define TCPOPT_ECHO 6
|
|
|
|
#define TCPOPT_ECHOREPLY 7
|
|
|
|
#define TCPOPT_TIMESTAMP 8 /* Better RTT estimations/PAWS */
|
|
|
|
#define TCPOPT_CC 11
|
|
|
|
#define TCPOPT_CCNEW 12
|
|
|
|
#define TCPOPT_CCECHO 13
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TCP option lengths
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define TCPOLEN_MSS 4
|
|
|
|
#define TCPOLEN_WINDOW 3
|
|
|
|
#define TCPOLEN_SACK_PERM 2
|
|
|
|
#define TCPOLEN_SACK_MIN 2
|
|
|
|
#define TCPOLEN_ECHO 6
|
|
|
|
#define TCPOLEN_ECHOREPLY 6
|
|
|
|
#define TCPOLEN_TIMESTAMP 10
|
|
|
|
#define TCPOLEN_CC 6
|
|
|
|
#define TCPOLEN_CCNEW 6
|
|
|
|
#define TCPOLEN_CCECHO 6
|
|
|
|
|
1998-12-21 03:43:29 +00:00
|
|
|
static void
|
|
|
|
tcp_info_append_uint(const char *abbrev, guint32 val) {
|
|
|
|
int add_len = 0;
|
|
|
|
|
|
|
|
if (info_len > 0)
|
|
|
|
if(info_len > 0)
|
|
|
|
add_len = snprintf(&info_str[info_len], COL_MAX_LEN - info_len, " %s=%u",
|
|
|
|
abbrev, val);
|
|
|
|
if (add_len > 0)
|
|
|
|
info_len += add_len;
|
1998-12-21 03:58:00 +00:00
|
|
|
}
|
1998-12-21 03:43:29 +00:00
|
|
|
|
1998-10-13 05:40:04 +00:00
|
|
|
static void
|
1999-03-23 03:14:46 +00:00
|
|
|
dissect_tcpopt_maxseg(proto_tree *opt_tree, const char *name, const u_char *opd,
|
1998-10-13 05:40:04 +00:00
|
|
|
int offset, guint optlen)
|
|
|
|
{
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree_add_item(opt_tree, offset, optlen,
|
1998-10-13 05:40:04 +00:00
|
|
|
"%s: %u bytes", name, pntohs(opd));
|
1998-12-21 03:43:29 +00:00
|
|
|
tcp_info_append_uint("MSS", pntohs(opd));
|
1998-10-13 05:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-03-23 03:14:46 +00:00
|
|
|
dissect_tcpopt_wscale(proto_tree *opt_tree, const char *name, const u_char *opd,
|
1998-10-13 05:40:04 +00:00
|
|
|
int offset, guint optlen)
|
|
|
|
{
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree_add_item(opt_tree, offset, optlen,
|
1998-10-13 05:40:04 +00:00
|
|
|
"%s: %u bytes", name, *opd);
|
1998-12-21 03:43:29 +00:00
|
|
|
tcp_info_append_uint("WS", *opd);
|
1998-10-13 05:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-03-23 03:14:46 +00:00
|
|
|
dissect_tcpopt_sack(proto_tree *opt_tree, const char *name, const u_char *opd,
|
1998-10-13 05:40:04 +00:00
|
|
|
int offset, guint optlen)
|
|
|
|
{
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree *field_tree = NULL;
|
|
|
|
proto_item *tf;
|
1998-10-13 05:40:04 +00:00
|
|
|
guint leftedge, rightedge;
|
|
|
|
|
1999-03-23 03:14:46 +00:00
|
|
|
tf = proto_tree_add_item(opt_tree, offset, optlen, "%s:", name);
|
1998-10-13 05:40:04 +00:00
|
|
|
offset += 2; /* skip past type and length */
|
|
|
|
optlen -= 2; /* subtract size of type and length */
|
|
|
|
while (optlen > 0) {
|
|
|
|
if (field_tree == NULL) {
|
|
|
|
/* Haven't yet made a subtree out of this option. Do so. */
|
1999-03-23 03:14:46 +00:00
|
|
|
field_tree = proto_tree_new();
|
|
|
|
proto_item_add_subtree(tf, field_tree, ETT_TCP_OPTION_SACK);
|
1998-10-13 05:40:04 +00:00
|
|
|
}
|
|
|
|
if (optlen < 4) {
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree_add_item(field_tree, offset, optlen,
|
1998-10-13 05:40:04 +00:00
|
|
|
"(suboption would go past end of option)");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* XXX - check whether it goes past end of packet */
|
|
|
|
leftedge = pntohl(opd);
|
|
|
|
opd += 4;
|
|
|
|
optlen -= 4;
|
|
|
|
if (optlen < 4) {
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree_add_item(field_tree, offset, optlen,
|
1998-10-13 05:40:04 +00:00
|
|
|
"(suboption would go past end of option)");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* XXX - check whether it goes past end of packet */
|
|
|
|
rightedge = pntohl(opd);
|
|
|
|
opd += 4;
|
|
|
|
optlen -= 4;
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree_add_item(field_tree, offset, 8,
|
1998-10-13 05:40:04 +00:00
|
|
|
"left edge = %u, right edge = %u", leftedge, rightedge);
|
1998-12-21 03:43:29 +00:00
|
|
|
tcp_info_append_uint("SLE", leftedge);
|
|
|
|
tcp_info_append_uint("SRE", rightedge);
|
1998-10-13 05:40:04 +00:00
|
|
|
offset += 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-03-23 03:14:46 +00:00
|
|
|
dissect_tcpopt_echo(proto_tree *opt_tree, const char *name, const u_char *opd,
|
1998-10-13 05:40:04 +00:00
|
|
|
int offset, guint optlen)
|
|
|
|
{
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree_add_item(opt_tree, offset, optlen,
|
1998-10-13 05:40:04 +00:00
|
|
|
"%s: %u", name, pntohl(opd));
|
1998-12-21 03:43:29 +00:00
|
|
|
tcp_info_append_uint("ECHO", pntohl(opd));
|
1998-10-13 05:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-03-23 03:14:46 +00:00
|
|
|
dissect_tcpopt_timestamp(proto_tree *opt_tree, const char *name,
|
1998-10-13 05:40:04 +00:00
|
|
|
const u_char *opd, int offset, guint optlen)
|
|
|
|
{
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree_add_item(opt_tree, offset, optlen,
|
1998-10-13 05:40:04 +00:00
|
|
|
"%s: tsval %u, tsecr %u", name, pntohl(opd), pntohl(opd + 4));
|
1998-12-21 03:43:29 +00:00
|
|
|
tcp_info_append_uint("TSV", pntohl(opd));
|
|
|
|
tcp_info_append_uint("TSER", pntohl(opd + 4));
|
1998-10-13 05:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-03-23 03:14:46 +00:00
|
|
|
dissect_tcpopt_cc(proto_tree *opt_tree, const char *name, const u_char *opd,
|
1998-10-13 05:40:04 +00:00
|
|
|
int offset, guint optlen)
|
|
|
|
{
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree_add_item(opt_tree, offset, optlen,
|
1998-10-13 05:40:04 +00:00
|
|
|
"%s: %u", name, pntohl(opd));
|
1998-12-21 03:43:29 +00:00
|
|
|
tcp_info_append_uint("CC", pntohl(opd));
|
1998-10-13 05:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static ip_tcp_opt tcpopts[] = {
|
|
|
|
{
|
|
|
|
TCPOPT_EOL,
|
|
|
|
"EOL",
|
|
|
|
NO_LENGTH,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TCPOPT_NOP,
|
|
|
|
"NOP",
|
|
|
|
NO_LENGTH,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TCPOPT_MSS,
|
|
|
|
"Maximum segment size",
|
|
|
|
FIXED_LENGTH,
|
|
|
|
TCPOLEN_MSS,
|
|
|
|
dissect_tcpopt_maxseg
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TCPOPT_WINDOW,
|
|
|
|
"Window scale",
|
|
|
|
FIXED_LENGTH,
|
|
|
|
TCPOLEN_WINDOW,
|
|
|
|
dissect_tcpopt_wscale
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TCPOPT_SACK_PERM,
|
|
|
|
"SACK permitted",
|
|
|
|
FIXED_LENGTH,
|
|
|
|
TCPOLEN_SACK_PERM,
|
|
|
|
NULL,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TCPOPT_SACK,
|
|
|
|
"SACK",
|
|
|
|
VARIABLE_LENGTH,
|
|
|
|
TCPOLEN_SACK_MIN,
|
|
|
|
dissect_tcpopt_sack
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TCPOPT_ECHO,
|
|
|
|
"Echo",
|
|
|
|
FIXED_LENGTH,
|
|
|
|
TCPOLEN_ECHO,
|
|
|
|
dissect_tcpopt_echo
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TCPOPT_ECHOREPLY,
|
|
|
|
"Echo reply",
|
|
|
|
FIXED_LENGTH,
|
|
|
|
TCPOLEN_ECHOREPLY,
|
|
|
|
dissect_tcpopt_echo
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TCPOPT_TIMESTAMP,
|
|
|
|
"Time stamp",
|
|
|
|
FIXED_LENGTH,
|
|
|
|
TCPOLEN_TIMESTAMP,
|
|
|
|
dissect_tcpopt_timestamp
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TCPOPT_CC,
|
|
|
|
"CC",
|
|
|
|
FIXED_LENGTH,
|
|
|
|
TCPOLEN_CC,
|
|
|
|
dissect_tcpopt_cc
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TCPOPT_CCNEW,
|
|
|
|
"CC.NEW",
|
|
|
|
FIXED_LENGTH,
|
|
|
|
TCPOPT_CCNEW,
|
|
|
|
dissect_tcpopt_cc
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TCPOPT_CCECHO,
|
|
|
|
"CC.ECHO",
|
|
|
|
FIXED_LENGTH,
|
|
|
|
TCPOLEN_CCECHO,
|
|
|
|
dissect_tcpopt_cc
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define N_TCP_OPTS (sizeof tcpopts / sizeof tcpopts[0])
|
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
void
|
1999-03-23 03:14:46 +00:00
|
|
|
dissect_tcp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
|
1998-09-16 02:39:15 +00:00
|
|
|
e_tcphdr th;
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree *tcp_tree = NULL, *field_tree = NULL;
|
|
|
|
proto_item *ti, *tf;
|
1998-09-16 02:39:15 +00:00
|
|
|
gchar flags[64] = "<None>";
|
|
|
|
gchar *fstr[] = {"FIN", "SYN", "RST", "PSH", "ACK", "URG"};
|
|
|
|
gint fpos = 0, i;
|
|
|
|
guint bpos;
|
1998-10-13 05:40:04 +00:00
|
|
|
guint hlen;
|
|
|
|
guint optlen;
|
1999-04-05 21:54:41 +00:00
|
|
|
guint packet_max = pi.payload + offset;
|
|
|
|
guint payload;
|
1998-09-16 02:39:15 +00:00
|
|
|
|
|
|
|
/* To do: Check for {cap len,pkt len} < struct len */
|
|
|
|
/* Avoids alignment problems on many architectures. */
|
|
|
|
memcpy(&th, &pd[offset], sizeof(e_tcphdr));
|
|
|
|
th.th_sport = ntohs(th.th_sport);
|
|
|
|
th.th_dport = ntohs(th.th_dport);
|
|
|
|
th.th_win = ntohs(th.th_win);
|
|
|
|
th.th_sum = ntohs(th.th_sum);
|
|
|
|
th.th_urp = ntohs(th.th_urp);
|
|
|
|
th.th_seq = ntohl(th.th_seq);
|
|
|
|
th.th_ack = ntohl(th.th_ack);
|
|
|
|
|
1998-12-21 03:43:29 +00:00
|
|
|
info_len = 0;
|
|
|
|
|
|
|
|
if (check_col(fd, COL_PROTOCOL) || tree) {
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
bpos = 1 << i;
|
|
|
|
if (th.th_flags & bpos) {
|
|
|
|
if (fpos) {
|
|
|
|
strcpy(&flags[fpos], ", ");
|
|
|
|
fpos += 2;
|
|
|
|
}
|
|
|
|
strcpy(&flags[fpos], fstr[i]);
|
|
|
|
fpos += 3;
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
|
|
|
}
|
1998-12-21 03:43:29 +00:00
|
|
|
flags[fpos] = '\0';
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
|
|
|
|
1999-02-08 20:02:35 +00:00
|
|
|
hlen = hi_nibble(th.th_off_x2) * 4; /* TCP header length, in bytes */
|
1998-12-21 03:43:29 +00:00
|
|
|
|
1999-04-05 21:54:41 +00:00
|
|
|
payload = pi.payload - hlen;
|
|
|
|
|
1998-11-17 05:04:04 +00:00
|
|
|
if (check_col(fd, COL_RES_SRC_PORT))
|
1998-11-18 01:49:12 +00:00
|
|
|
col_add_str(fd, COL_RES_SRC_PORT, get_tcp_port(th.th_sport));
|
1998-11-17 05:04:04 +00:00
|
|
|
if (check_col(fd, COL_UNRES_SRC_PORT))
|
1998-12-21 03:43:29 +00:00
|
|
|
col_add_fstr(fd, COL_UNRES_SRC_PORT, "%u", th.th_sport);
|
1998-11-17 05:04:04 +00:00
|
|
|
if (check_col(fd, COL_RES_DST_PORT))
|
1998-11-18 01:49:12 +00:00
|
|
|
col_add_str(fd, COL_RES_DST_PORT, get_tcp_port(th.th_dport));
|
1998-11-17 05:04:04 +00:00
|
|
|
if (check_col(fd, COL_UNRES_DST_PORT))
|
1998-12-21 03:43:29 +00:00
|
|
|
col_add_fstr(fd, COL_UNRES_DST_PORT, "%u", th.th_dport);
|
|
|
|
if (check_col(fd, COL_PROTOCOL))
|
|
|
|
col_add_str(fd, COL_PROTOCOL, "TCP");
|
|
|
|
if (check_col(fd, COL_INFO)) {
|
|
|
|
/* Copy the data into info_str in case one of the option handling
|
|
|
|
routines needs to append to it. */
|
|
|
|
if (th.th_flags & TH_URG)
|
|
|
|
info_len = snprintf(info_str, COL_MAX_LEN, "%s > %s [%s] Seq=%u Ack=%u Win=%u Urg=%u",
|
|
|
|
get_tcp_port(th.th_sport), get_tcp_port(th.th_dport), flags,
|
|
|
|
th.th_seq, th.th_ack, th.th_win, th.th_urp);
|
|
|
|
else
|
|
|
|
info_len = snprintf(info_str, COL_MAX_LEN, "%s > %s [%s] Seq=%u Ack=%u Win=%u",
|
|
|
|
get_tcp_port(th.th_sport), get_tcp_port(th.th_dport), flags,
|
|
|
|
th.th_seq, th.th_ack, th.th_win);
|
|
|
|
/* The info column is actually written after the options are decoded */
|
|
|
|
}
|
1998-09-16 02:39:15 +00:00
|
|
|
|
|
|
|
if (tree) {
|
1999-03-23 03:14:46 +00:00
|
|
|
ti = proto_tree_add_item(tree, offset, hlen,
|
1998-09-16 02:39:15 +00:00
|
|
|
"Transmission Control Protocol");
|
1999-03-23 03:14:46 +00:00
|
|
|
tcp_tree = proto_tree_new();
|
|
|
|
proto_item_add_subtree(ti, tcp_tree, ETT_TCP);
|
|
|
|
proto_tree_add_item(tcp_tree, offset, 2, "Source port: %s (%u)",
|
1998-12-21 03:43:29 +00:00
|
|
|
get_tcp_port(th.th_sport), th.th_sport);
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree_add_item(tcp_tree, offset + 2, 2, "Destination port: %s (%u)",
|
1998-12-21 03:43:29 +00:00
|
|
|
get_tcp_port(th.th_dport), th.th_dport);
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree_add_item(tcp_tree, offset + 4, 4, "Sequence number: %u",
|
1998-09-16 02:39:15 +00:00
|
|
|
th.th_seq);
|
1998-10-13 05:40:04 +00:00
|
|
|
if (th.th_flags & TH_ACK)
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree_add_item(tcp_tree, offset + 8, 4, "Acknowledgement number: %u",
|
1998-10-13 05:40:04 +00:00
|
|
|
th.th_ack);
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree_add_item(tcp_tree, offset + 12, 1, "Header length: %u bytes", hlen);
|
|
|
|
tf = proto_tree_add_item(tcp_tree, offset + 13, 1, "Flags: 0x%x", th.th_flags);
|
|
|
|
field_tree = proto_tree_new();
|
|
|
|
proto_item_add_subtree(tf, field_tree, ETT_TCP_FLAGS);
|
|
|
|
proto_tree_add_item(field_tree, offset + 13, 1, "%s",
|
1998-12-29 04:05:38 +00:00
|
|
|
decode_boolean_bitfield(th.th_flags, TH_URG, sizeof (th.th_flags)*8,
|
|
|
|
"Urgent pointer", "No urgent pointer"));
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree_add_item(field_tree, offset + 13, 1, "%s",
|
1998-12-29 04:05:38 +00:00
|
|
|
decode_boolean_bitfield(th.th_flags, TH_ACK, sizeof (th.th_flags)*8,
|
|
|
|
"Acknowledgment", "No acknowledgment"));
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree_add_item(field_tree, offset + 13, 1, "%s",
|
1998-12-29 04:05:38 +00:00
|
|
|
decode_boolean_bitfield(th.th_flags, TH_PUSH, sizeof (th.th_flags)*8,
|
|
|
|
"Push", "No push"));
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree_add_item(field_tree, offset + 13, 1, "%s",
|
1998-12-29 04:05:38 +00:00
|
|
|
decode_boolean_bitfield(th.th_flags, TH_RST, sizeof (th.th_flags)*8,
|
|
|
|
"Reset", "No reset"));
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree_add_item(field_tree, offset + 13, 1, "%s",
|
1998-12-29 04:05:38 +00:00
|
|
|
decode_boolean_bitfield(th.th_flags, TH_SYN, sizeof (th.th_flags)*8,
|
|
|
|
"Syn", "No Syn"));
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree_add_item(field_tree, offset + 13, 1, "%s",
|
1998-12-29 04:05:38 +00:00
|
|
|
decode_boolean_bitfield(th.th_flags, TH_FIN, sizeof (th.th_flags)*8,
|
|
|
|
"Fin", "No Fin"));
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree_add_item(tcp_tree, offset + 14, 2, "Window size: %u", th.th_win);
|
|
|
|
proto_tree_add_item(tcp_tree, offset + 16, 2, "Checksum: 0x%04x", th.th_sum);
|
1998-10-13 05:40:04 +00:00
|
|
|
if (th.th_flags & TH_URG)
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree_add_item(tcp_tree, offset + 18, 2, "Urgent pointer: 0x%04x",
|
1998-10-13 05:40:04 +00:00
|
|
|
th.th_urp);
|
1998-12-21 03:43:29 +00:00
|
|
|
}
|
1998-09-16 02:39:15 +00:00
|
|
|
|
1998-12-21 03:43:29 +00:00
|
|
|
/* Decode TCP options, if any. */
|
1999-05-12 20:44:59 +00:00
|
|
|
if (tree && hlen > sizeof (e_tcphdr)) {
|
1998-12-21 03:43:29 +00:00
|
|
|
/* There's more than just the fixed-length header. Decode the
|
|
|
|
options. */
|
|
|
|
optlen = hlen - sizeof (e_tcphdr); /* length of options, in bytes */
|
1999-05-12 20:44:59 +00:00
|
|
|
tf = proto_tree_add_item(tcp_tree, offset + 20, optlen,
|
|
|
|
"Options: (%d bytes)", optlen);
|
|
|
|
field_tree = proto_tree_new();
|
|
|
|
proto_item_add_subtree(tf, field_tree, ETT_TCP_OPTIONS);
|
1998-12-21 03:43:29 +00:00
|
|
|
dissect_ip_tcp_options(field_tree, &pd[offset + 20], offset + 20, optlen,
|
1999-05-12 20:44:59 +00:00
|
|
|
tcpopts, N_TCP_OPTS, TCPOPT_EOL);
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
1998-09-17 03:12:28 +00:00
|
|
|
|
1998-12-21 03:43:29 +00:00
|
|
|
if (check_col(fd, COL_INFO))
|
|
|
|
col_add_str(fd, COL_INFO, info_str);
|
|
|
|
|
1998-10-13 05:40:04 +00:00
|
|
|
/* Skip over header + options */
|
|
|
|
offset += hlen;
|
1998-09-17 03:12:28 +00:00
|
|
|
|
1999-04-05 21:54:41 +00:00
|
|
|
pi.srcport = th.th_sport;
|
|
|
|
pi.destport = th.th_dport;
|
|
|
|
|
1999-02-12 09:03:42 +00:00
|
|
|
/* Check the packet length to see if there's more data
|
|
|
|
(it could be an ACK-only packet) */
|
1999-04-05 21:54:41 +00:00
|
|
|
if (packet_max > offset) {
|
1999-06-02 01:28:47 +00:00
|
|
|
/* XXX - this should be handled the way UDP handles this, with a table
|
|
|
|
of port numbers to which stuff can be added */
|
|
|
|
#define PORT_IS(port) (th.th_sport == port || th.th_dport == port)
|
|
|
|
if (PORT_IS(TCP_PORT_PRINTER))
|
1999-04-05 21:54:41 +00:00
|
|
|
dissect_lpd(pd, offset, fd, tree);
|
1999-06-02 01:28:47 +00:00
|
|
|
else if (PORT_IS(TCP_PORT_TELNET)) {
|
1999-04-05 21:54:41 +00:00
|
|
|
pi.match_port = TCP_PORT_TELNET;
|
|
|
|
dissect_telnet(pd, offset, fd, tree, payload);
|
1999-06-02 01:28:47 +00:00
|
|
|
} else if (PORT_IS(TCP_PORT_FTPDATA)) {
|
1999-04-05 21:54:41 +00:00
|
|
|
pi.match_port = TCP_PORT_FTPDATA;
|
|
|
|
dissect_ftpdata(pd, offset, fd, tree, payload);
|
1999-06-02 01:28:47 +00:00
|
|
|
} else if (PORT_IS(TCP_PORT_FTP)) {
|
1999-04-05 21:54:41 +00:00
|
|
|
pi.match_port = TCP_PORT_FTP;
|
|
|
|
dissect_ftp(pd, offset, fd, tree, payload);
|
1999-06-02 01:28:47 +00:00
|
|
|
} else if (PORT_IS(TCP_PORT_POP)) {
|
1999-04-05 21:54:41 +00:00
|
|
|
pi.match_port = TCP_PORT_POP;
|
|
|
|
dissect_pop(pd, offset, fd, tree, payload);
|
1999-06-02 01:28:47 +00:00
|
|
|
} else if (PORT_IS(TCP_PORT_NNTP)) {
|
1999-04-06 02:02:12 +00:00
|
|
|
pi.match_port = TCP_PORT_NNTP;
|
|
|
|
dissect_nntp(pd, offset, fd, tree, payload);
|
1999-06-11 15:30:55 +00:00
|
|
|
} else if (PORT_IS(TCP_PORT_PPTP)) {
|
|
|
|
pi.match_port = TCP_PORT_PPTP;
|
|
|
|
dissect_pptp(pd, offset, fd, tree);
|
1999-06-02 01:28:47 +00:00
|
|
|
} else if (PORT_IS(TCP_PORT_HTTP) || PORT_IS(TCP_ALT_PORT_HTTP))
|
|
|
|
dissect_http(pd, offset, fd, tree);
|
|
|
|
else if (PORT_IS(TCP_PORT_NBSS)) {
|
1999-04-30 03:16:03 +00:00
|
|
|
pi.match_port = TCP_PORT_NBSS;
|
|
|
|
dissect_nbss(pd, offset, fd, tree, payload);
|
1999-06-02 01:28:47 +00:00
|
|
|
} else {
|
1998-11-18 03:01:44 +00:00
|
|
|
/* check existence of high level protocols */
|
|
|
|
|
|
|
|
if (memcmp(&pd[offset], "GIOP", 4) == 0) {
|
|
|
|
dissect_giop(pd, offset, fd, tree);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dissect_data(pd, offset, fd, tree);
|
|
|
|
}
|
1998-10-13 05:40:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( data_out_file ) {
|
|
|
|
reassemble_tcp( th.th_seq, /* sequence number */
|
1999-02-08 20:02:35 +00:00
|
|
|
( pi.iplen -( pi.iphdrlen * 4 )-( hi_nibble(th.th_off_x2) * 4 ) ), /* length */
|
1998-10-13 05:40:04 +00:00
|
|
|
( pd+offset ), /* data */
|
1999-03-23 20:25:50 +00:00
|
|
|
( fd->cap_len - offset ), /* captured data length */
|
1998-10-13 05:40:04 +00:00
|
|
|
( th.th_flags & 0x02 ), /* is syn set? */
|
|
|
|
pi.ip_src ); /* src ip */
|
|
|
|
}
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|