]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-tcp.c
Use the passed in length instead of the IP header's length in the
[tcpdump] / print-tcp.c
index d45a295779f61c3d63930e163397ca03e3d04c50..54ae3d5571c6d7dff716625f0188baab98d009a5 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.85 2001-03-09 05:38:21 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.88 2001-08-20 17:53:53 fenner Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -58,45 +58,6 @@ 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) */
-#endif
-#ifndef TCPOPT_SACKOK
-#define        TCPOPT_SACKOK           4       /* selective ack ok (rfc1072) */
-#endif
-#ifndef TCPOPT_SACK
-#define        TCPOPT_SACK             5       /* selective ack (rfc1072) */
-#endif
-#ifndef TCPOPT_ECHO
-#define        TCPOPT_ECHO             6       /* echo (rfc1072) */
-#endif
-#ifndef TCPOPT_ECHOREPLY
-#define        TCPOPT_ECHOREPLY        7       /* echo (rfc1072) */
-#endif
-#ifndef TCPOPT_TIMESTAMP
-#define TCPOPT_TIMESTAMP       8       /* timestamps (rfc1323) */
-#endif
-#ifndef TCPOPT_CC
-#define TCPOPT_CC              11      /* T/TCP CC options (rfc1644) */
-#endif
-#ifndef TCPOPT_CCNEW
-#define TCPOPT_CCNEW           12      /* T/TCP CC options (rfc1644) */
-#endif
-#ifndef TCPOPT_CCECHO
-#define TCPOPT_CCECHO          13      /* T/TCP CC options (rfc1644) */
-#endif
-
-/*
- * Definitions required for ECN
- * for use if the OS running tcpdump does not have ECN
- */
-#ifndef TH_ECNECHO
-#define TH_ECNECHO             0x40    /* ECN Echo in tcp header */
-#endif
-#ifndef TH_CWR
-#define TH_CWR                 0x80    /* ECN Cwnd Reduced in tcp header*/
-#endif
 
 struct tha {
 #ifndef INET6
@@ -143,7 +104,6 @@ static int tcp_cksum(register const struct ip *ip,
                     register const struct tcphdr *tp,
                     register int len)
 {
-       int i, tlen;
        union phu {
                struct phdr {
                        u_int32_t src;
@@ -154,34 +114,18 @@ static int tcp_cksum(register const struct ip *ip,
                } ph;
                u_int16_t pa[6];
        } phu;
-       register const u_int16_t *sp;
-       u_int32_t sum;
-       tlen = ntohs(ip->ip_len) - ((const char *)tp-(const char*)ip);
+       const u_int16_t *sp;
 
        /* pseudo-header.. */
-       phu.ph.len = htons(tlen);
+       phu.ph.len = htons(len);        /* XXX */
        phu.ph.mbz = 0;
        phu.ph.proto = IPPROTO_TCP;
        memcpy(&phu.ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t));
        memcpy(&phu.ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t));
 
        sp = &phu.pa[0];
-       sum = sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5];
-
-       sp = (const u_int16_t *)tp;
-
-       for (i=0; i<(tlen&~1); i+= 2)
-               sum += *sp++;
-
-       if (tlen & 1) {
-               sum += htons( (*(const u_int8_t *)sp) << 8);
-       }
-
-       while (sum > 0xffff)
-               sum = (sum & 0xffff) + (sum >> 16);
-       sum = ~sum & 0xffff;
-
-       return (sum);
+       return in_cksum((u_short *)tp, len,
+                       sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5]);
 }
 
 #ifdef INET6
@@ -284,7 +228,7 @@ tcp_print(register const u_char *bp, register u_int length,
                } else if ((u_char *)tp + 4 + sizeof(struct rpc_msg)
                           <= snapend &&
                           sport == NFS_PORT) {
-                       nfsreply_print((u_char *)tp + hlen + 4,length-hlen,
+                       nfsreply_print((u_char *)tp + hlen + 4, length - hlen,
                                       (u_char *)ip);
                        return;
                }