]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-tcp.c
Handle (GRE-encapsulated) PPTP
[tcpdump] / print-tcp.c
index 8e15607d155ede373702d897ff424802b1386a22..a7d9c57e1b06e856b38e32dd65b93842a8387a3b 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.78 2000-10-03 02:55:01 itojun Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.84 2001-02-03 05:04:49 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -41,10 +41,6 @@ static const char rcsid[] =
 #include <ctype.h>
 #include <unistd.h>
 
-#ifdef INET6
-#include <netinet/ip6.h>
-#endif
-
 #include "interface.h"
 #include "addrtoname.h"
 #include "extract.h"
@@ -52,6 +48,11 @@ static const char rcsid[] =
 #include "tcp.h"
 
 #include "ip.h"
+#ifdef INET6
+#include "ip6.h"
+#endif
+
+#include "nameser.h"
 
 static void print_tcp_rst_data(register const u_char *sp, u_int length);
 
@@ -170,7 +171,7 @@ static int tcp_cksum(register const struct ip *ip,
                sum += *sp++;
 
        if (tlen & 1) {
-               sum += htons( (*(const char *)sp) << 8);
+               sum += htons( (*(const u_int8_t *)sp) << 8);
        }
 
        while (sum > 0xffff)
@@ -218,7 +219,7 @@ static int tcp6_cksum(const struct ip6_hdr *ip6, const struct tcphdr *tp,
                sum += *sp++;
 
        if (tlen & 1)
-               sum += htons((*(const char *)sp) << 8);
+               sum += htons((*(const u_int8_t *)sp) << 8);
 
        while (sum > 0xffff)
                sum = (sum & 0xffff) + (sum >> 16);
@@ -230,7 +231,7 @@ static int tcp6_cksum(const struct ip6_hdr *ip6, const struct tcphdr *tp,
 
 void
 tcp_print(register const u_char *bp, register u_int length,
-         register const u_char *bp2)
+         register const u_char *bp2, int fragmented)
 {
        register const struct tcphdr *tp;
        register const struct ip *ip;
@@ -274,7 +275,7 @@ tcp_print(register const u_char *bp, register u_int length,
        if (!qflag) {
                if ((u_char *)tp + 4 + sizeof(struct rpc_msg) <= snapend &&
                    dport == NFS_PORT) {
-                       nfsreq_print((u_char *)tp + hlen + 4, length-hlen,
+                       nfsreq_print((u_char *)tp + hlen + 4, length - hlen,
                                     (u_char *)ip);
                        return;
                } else if ((u_char *)tp + 4 + sizeof(struct rpc_msg)
@@ -354,18 +355,18 @@ tcp_print(register const u_char *bp, register u_int length,
                memset(&tha, 0, sizeof(tha));
                rev = 0;
                if (ip6) {
-                       if (sport > dport) {
+                       if (sport > dport)
                                rev = 1;
-                       } else if (sport == dport) {
-                           int i;
-
-                           for (i = 0; i < 4; i++) {
-                               if (((u_int32_t *)(&ip6->ip6_src))[i] >
-                                   ((u_int32_t *)(&ip6->ip6_dst))[i]) {
-                                       rev = 1;
-                                       break;
+                       else if (sport == dport) {
+                               int i;
+
+                               for (i = 0; i < 4; i++) {
+                                       if (((u_int32_t *)(&ip6->ip6_src))[i] >
+                                           ((u_int32_t *)(&ip6->ip6_dst))[i]) {
+                                               rev = 1;
+                                               break;
+                                       }
                                }
-                           }
                        }
                        if (rev) {
                                tha.src = ip6->ip6_dst;
@@ -426,7 +427,6 @@ tcp_print(register const u_char *bp, register u_int length,
                                th->ack = seq, th->seq = ack - 1;
                        else
                                th->seq = seq, th->ack = ack - 1;
-
                } else {
                        if (rev)
                                seq -= th->ack, ack -= th->seq;
@@ -445,7 +445,7 @@ tcp_print(register const u_char *bp, register u_int length,
                return;
        }
 
-       if (IP_V(ip) == 4 && vflag) {
+       if (IP_V(ip) == 4 && vflag && !fragmented) {
                int sum;
                if (TTEST2(tp->th_sport, length)) {
                        sum = tcp_cksum(ip, tp, length);
@@ -456,7 +456,7 @@ tcp_print(register const u_char *bp, register u_int length,
                }
        }
 #ifdef INET6
-       if (IP_V(ip) == 6 && ip6->ip6_plen && vflag) {
+       if (IP_V(ip) == 6 && ip6->ip6_plen && vflag && !fragmented) {
                int sum;
                if (TTEST2(tp->th_sport, length)) {
                        sum = tcp6_cksum(ip6, tp, length);
@@ -654,6 +654,11 @@ tcp_print(register const u_char *bp, register u_int length,
                        nbt_tcp_print(bp, length);
                else if (sport == BXXP_PORT || dport == BXXP_PORT)
                        bxxp_print(bp, length);
+               else if (length > 2 &&
+                   (sport == NAMESERVER_PORT || dport == NAMESERVER_PORT)) {
+                       /* TCP DNS query has 2byte length at the head */
+                       ns_print(bp + 2, length - 2);
+               }
        }
        return;
 bad:
@@ -698,10 +703,7 @@ print_tcp_rst_data(register const u_char *sp, u_int length)
        putchar(' ');
        while (length-- && sp <= snapend) {
                c = *sp++;
-               if (isprint(c))
-                       putchar(c);
-               else
-                       putchar('.');
+               safeputchar(c);
        }
        putchar(']');
 }