]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Changes from Kevin Steves to print, in an RST segment, the payload as
authorguy <guy>
Sat, 29 Jul 2000 09:06:23 +0000 (09:06 +0000)
committerguy <guy>
Sat, 29 Jul 2000 09:06:23 +0000 (09:06 +0000)
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.

print-tcp.c

index 895cf216576239f53ba04421a8988a58f544cc41..d57902529eb1772c8c16a430f3634a398878a5a5 100644 (file)
@@ -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(']');
+}