From e644901a38264451dfd06843df010ca40626523b Mon Sep 17 00:00:00 2001 From: Kevin Steves Date: Sun, 23 Dec 2001 01:05:16 +0000 Subject: 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@ --- usr.sbin/tcpdump/print-tcp.c | 57 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 6 deletions(-) (limited to 'usr.sbin/tcpdump') 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 @@ -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(']'); +} -- cgit v1.2.3