From: guy Date: Sat, 29 Jul 2000 09:06:23 +0000 (+0000) Subject: Changes from Kevin Steves to print, in an RST segment, the payload as X-Git-Tag: tcpdump-3.5.1~201 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/674fea664da96caf629c5bdda52a9257d9c7ac91 Changes from Kevin Steves to print, in an RST segment, the payload as text, as per RFC 1122: 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. as some TCP implementations (e.g., HP-UX 11.0) do that. Clean up the code that prints the payload of non-RST segments. --- diff --git a/print-tcp.c b/print-tcp.c index 895cf216..d5790252 100644 --- a/print-tcp.c +++ b/print-tcp.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.68 2000-07-29 08:03:05 assar Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.69 2000-07-29 09:06:23 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -52,6 +52,10 @@ static const char rcsid[] = #include "addrtoname.h" #include "extract.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) */ @@ -518,13 +522,18 @@ tcp_print(register const u_char *bp, register u_int length, * Decode payload if necessary. */ bp += (tp->th_off * 4); - if (!qflag && vflag && length > 0 - && (sport == TELNET_PORT || dport == TELNET_PORT)) - telnet_print(bp, length); - else if (sport == BGP_PORT || dport == BGP_PORT) - bgp_print(bp, length); - else if (sport == NETBIOS_SSN_PORT || dport == NETBIOS_SSN_PORT) - nbt_tcp_print(bp, length); + if (flags & TH_RST) { + if (vflag) + print_tcp_rst_data(bp, length); + } else { + if (sport == TELNET_PORT || dport == TELNET_PORT) { + if (!qflag && vflag) + telnet_print(bp, length); + } else if (sport == BGP_PORT || dport == BGP_PORT) + bgp_print(bp, length); + else if (sport == NETBIOS_SSN_PORT || dport == NETBIOS_SSN_PORT) + nbt_tcp_print(bp, length); + } return; bad: fputs("[bad opt]", stdout); @@ -537,3 +546,41 @@ 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++; + if (isprint(c)) + putchar(c); + else + putchar('.'); + } + putchar(']'); +}