summaryrefslogtreecommitdiff
path: root/usr.sbin/tcpdump
diff options
context:
space:
mode:
authorKevin Steves <stevesk@cvs.openbsd.org>2001-12-23 01:05:16 +0000
committerKevin Steves <stevesk@cvs.openbsd.org>2001-12-23 01:05:16 +0000
commite644901a38264451dfd06843df010ca40626523b (patch)
treec2b7501c9379dfb1d6b1fee9d47eb2c802dc8d0e /usr.sbin/tcpdump
parent6c94f14742572bff0ee56b0948f0904dc8815e58 (diff)
integrate a patch i did around 1.5 years ago that's already in
tcpdump.org and netbsd. if verbose and TCP RST segment with payload, print the payload string. Mentat derived stacks may put text strings in RST segments. ok jakob@
Diffstat (limited to 'usr.sbin/tcpdump')
-rw-r--r--usr.sbin/tcpdump/print-tcp.c57
1 files changed, 51 insertions, 6 deletions
diff --git a/usr.sbin/tcpdump/print-tcp.c b/usr.sbin/tcpdump/print-tcp.c
index 68e94717bd0..d28fd983fb6 100644
--- a/usr.sbin/tcpdump/print-tcp.c
+++ b/usr.sbin/tcpdump/print-tcp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: print-tcp.c,v 1.15 2001/06/25 19:56:11 itojun Exp $ */
+/* $OpenBSD: print-tcp.c,v 1.16 2001/12/23 01:05:15 stevesk Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -23,7 +23,7 @@
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-tcp.c,v 1.15 2001/06/25 19:56:11 itojun Exp $ (LBL)";
+ "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-tcp.c,v 1.16 2001/12/23 01:05:15 stevesk Exp $ (LBL)";
#endif
#include <sys/param.h>
@@ -53,6 +53,10 @@ static const char rcsid[] =
#include "nfs.h"
+static void print_tcp_rst_data(register const u_char *sp, u_int length);
+
+#define MAX_RST_DATA_LEN 30
+
/* Compatibility */
#ifndef TCPOPT_WSCALE
#define TCPOPT_WSCALE 3 /* window scale factor (rfc1072) */
@@ -562,12 +566,17 @@ tcp_print(register const u_char *bp, register u_int length,
* Decode payload if necessary.
*/
bp += (tp->th_off * 4);
- if (sport == BGP_PORT || dport == BGP_PORT)
- bgp_print(bp, length);
+ if (flags & TH_RST) {
+ if (vflag)
+ print_tcp_rst_data(bp, length);
+ } else {
+ if (sport == BGP_PORT || dport == BGP_PORT)
+ bgp_print(bp, length);
#if 0
- else if (sport == NETBIOS_SSN_PORT || dport == NETBIOS_SSN_PORT)
- nbt_tcp_print(bp, length);
+ else if (sport == NETBIOS_SSN_PORT || dport == NETBIOS_SSN_PORT)
+ nbt_tcp_print(bp, length);
#endif
+ }
return;
bad:
fputs("[bad opt]", stdout);
@@ -580,3 +589,39 @@ trunc:
putchar('>');
}
+
+/*
+ * RFC1122 says the following on data in RST segments:
+ *
+ * 4.2.2.12 RST Segment: RFC-793 Section 3.4
+ *
+ * A TCP SHOULD allow a received RST segment to include data.
+ *
+ * DISCUSSION
+ * It has been suggested that a RST segment could contain
+ * ASCII text that encoded and explained the cause of the
+ * RST. No standard has yet been established for such
+ * data.
+ *
+ */
+
+static void
+print_tcp_rst_data(register const u_char *sp, u_int length)
+{
+ int c;
+
+ if (TTEST2(*sp, length))
+ printf(" [RST");
+ else
+ printf(" [!RST");
+ if (length > MAX_RST_DATA_LEN) {
+ length = MAX_RST_DATA_LEN; /* can use -X for longer */
+ putchar('+'); /* indicate we truncate */
+ }
+ putchar(' ');
+ while (length-- && sp <= snapend) {
+ c = *sp++;
+ safeputchar(c);
+ }
+ putchar(']');
+}