]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-tcp.c
That didn't work, either.
[tcpdump] / print-tcp.c
index 4baaee3ad7e1719106e1d168d906b611ed5a99dd..66e87492a1b178325f0c82a9ee899371b1a1a43c 100644 (file)
@@ -31,10 +31,10 @@ __RCSID("$NetBSD: print-tcp.c,v 1.8 2007/07/24 11:53:48 drochner Exp $");
 #endif
 
 #ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
 #endif
 
-#include <netdissect-stdinc.h>
+#include "netdissect-stdinc.h"
 
 #include <stdlib.h>
 #include <string.h>
@@ -57,7 +57,7 @@ __RCSID("$NetBSD: print-tcp.c,v 1.8 2007/07/24 11:53:48 drochner Exp $");
 
 static int tcp_verify_signature(netdissect_options *ndo,
                                 const struct ip *ip, const struct tcphdr *tp,
-                                const u_char *data, int length, const u_char *rcvsig);
+                                const u_char *data, u_int length, const u_char *rcvsig);
 #endif
 
 static void print_tcp_rst_data(netdissect_options *, const u_char *sp, u_int length);
@@ -181,9 +181,15 @@ tcp_print(netdissect_options *ndo,
                 ip6 = NULL;
         ch = '\0';
         if (!ND_TTEST_2(tp->th_dport)) {
-                ND_PRINT("%s > %s: [|tcp]",
-                             ipaddr_string(ndo, &ip->ip_src),
-                             ipaddr_string(ndo, &ip->ip_dst));
+               if (ip6) {
+                        ND_PRINT("%s > %s: ",
+                                     ip6addr_string(ndo, ip6->ip6_src),
+                                     ip6addr_string(ndo, ip6->ip6_dst));
+               } else {
+                       ND_PRINT("%s > %s: [|tcp]",
+                                    ipaddr_string(ndo, ip->ip_src),
+                                    ipaddr_string(ndo, ip->ip_dst));
+                }
                 return;
         }
 
@@ -193,9 +199,9 @@ tcp_print(netdissect_options *ndo,
         if (ip6) {
                 if (EXTRACT_U_1(ip6->ip6_nxt) == IPPROTO_TCP) {
                         ND_PRINT("%s.%s > %s.%s: ",
-                                     ip6addr_string(ndo, &ip6->ip6_src),
+                                     ip6addr_string(ndo, ip6->ip6_src),
                                      tcpport_string(ndo, sport),
-                                     ip6addr_string(ndo, &ip6->ip6_dst),
+                                     ip6addr_string(ndo, ip6->ip6_dst),
                                      tcpport_string(ndo, dport));
                 } else {
                         ND_PRINT("%s > %s: ",
@@ -204,9 +210,9 @@ tcp_print(netdissect_options *ndo,
         } else {
                 if (EXTRACT_U_1(ip->ip_p) == IPPROTO_TCP) {
                         ND_PRINT("%s.%s > %s.%s: ",
-                                     ipaddr_string(ndo, &ip->ip_src),
+                                     ipaddr_string(ndo, ip->ip_src),
                                      tcpport_string(ndo, sport),
-                                     ipaddr_string(ndo, &ip->ip_dst),
+                                     ipaddr_string(ndo, ip->ip_dst),
                                      tcpport_string(ndo, dport));
                 } else {
                         ND_PRINT("%s > %s: ",
@@ -219,7 +225,7 @@ tcp_print(netdissect_options *ndo,
         hlen = TH_OFF(tp) * 4;
 
         if (hlen < sizeof(*tp)) {
-                ND_PRINT(" tcp %d [bad hdr length %u - too short, < %lu]",
+                ND_PRINT(" tcp %u [bad hdr length %u - too short, < %lu]",
                              length - hlen, hlen, (unsigned long)sizeof(*tp));
                 return;
         }
@@ -230,7 +236,7 @@ tcp_print(netdissect_options *ndo,
         urp = EXTRACT_BE_U_2(tp->th_urp);
 
         if (ndo->ndo_qflag) {
-                ND_PRINT("tcp %d", length - hlen);
+                ND_PRINT("tcp %u", length - hlen);
                 if (hlen > length) {
                         ND_PRINT(" [bad hdr length %u - too long, > %u]",
                                      hlen, length);
@@ -256,21 +262,21 @@ tcp_print(netdissect_options *ndo,
                         struct tha6 tha;
 
                         tcp_seq_hash = tcp_seq_hash6;
-                        src = (const void *)&ip6->ip6_src;
-                        dst = (const void *)&ip6->ip6_dst;
+                        src = (const void *)ip6->ip6_src;
+                        dst = (const void *)ip6->ip6_dst;
                         if (sport > dport)
                                 rev = 1;
                         else if (sport == dport) {
-                                if (UNALIGNED_MEMCMP(src, dst, sizeof ip6->ip6_dst) > 0)
+                                if (UNALIGNED_MEMCMP(src, dst, sizeof(ip6->ip6_dst)) > 0)
                                         rev = 1;
                         }
                         if (rev) {
-                                UNALIGNED_MEMCPY(&tha.src, dst, sizeof ip6->ip6_dst);
-                                UNALIGNED_MEMCPY(&tha.dst, src, sizeof ip6->ip6_src);
+                                UNALIGNED_MEMCPY(&tha.src, dst, sizeof(ip6->ip6_dst));
+                                UNALIGNED_MEMCPY(&tha.dst, src, sizeof(ip6->ip6_src));
                                 tha.port = dport << 16 | sport;
                         } else {
-                                UNALIGNED_MEMCPY(&tha.dst, dst, sizeof ip6->ip6_dst);
-                                UNALIGNED_MEMCPY(&tha.src, src, sizeof ip6->ip6_src);
+                                UNALIGNED_MEMCPY(&tha.dst, dst, sizeof(ip6->ip6_dst));
+                                UNALIGNED_MEMCPY(&tha.src, src, sizeof(ip6->ip6_src));
                                 tha.port = sport << 16 | dport;
                         }
 
@@ -282,6 +288,8 @@ tcp_print(netdissect_options *ndo,
 
                         if (!th->nxt || (flags & TH_SYN)) {
                                 /* didn't find it or new conversation */
+                               /* calloc() return used by the 'tcp_seq_hash6'
+                                  hash table: do not free() */
                                 if (th->nxt == NULL) {
                                         th->nxt = (struct tcp_seq_hash6 *)
                                                 calloc(1, sizeof(*th));
@@ -312,16 +320,20 @@ tcp_print(netdissect_options *ndo,
                         if (sport > dport)
                                 rev = 1;
                         else if (sport == dport) {
-                                if (UNALIGNED_MEMCMP(&ip->ip_src, &ip->ip_dst, sizeof ip->ip_dst) > 0)
+                                if (UNALIGNED_MEMCMP(ip->ip_src, ip->ip_dst, sizeof(ip->ip_dst)) > 0)
                                         rev = 1;
                         }
                         if (rev) {
-                                UNALIGNED_MEMCPY(&tha.src, &ip->ip_dst, sizeof ip->ip_dst);
-                                UNALIGNED_MEMCPY(&tha.dst, &ip->ip_src, sizeof ip->ip_src);
+                                UNALIGNED_MEMCPY(&tha.src, ip->ip_dst,
+                                                 sizeof(ip->ip_dst));
+                                UNALIGNED_MEMCPY(&tha.dst, ip->ip_src,
+                                                 sizeof(ip->ip_src));
                                 tha.port = dport << 16 | sport;
                         } else {
-                                UNALIGNED_MEMCPY(&tha.dst, &ip->ip_dst, sizeof ip->ip_dst);
-                                UNALIGNED_MEMCPY(&tha.src, &ip->ip_src, sizeof ip->ip_src);
+                                UNALIGNED_MEMCPY(&tha.dst, ip->ip_dst,
+                                                 sizeof(ip->ip_dst));
+                                UNALIGNED_MEMCPY(&tha.src, ip->ip_src,
+                                                 sizeof(ip->ip_src));
                                 tha.port = sport << 16 | dport;
                         }
 
@@ -333,6 +345,8 @@ tcp_print(netdissect_options *ndo,
 
                         if (!th->nxt || (flags & TH_SYN)) {
                                 /* didn't find it or new conversation */
+                               /* calloc() return used by the 'tcp_seq_hash4'
+                                  hash table: do not free() */
                                 if (th->nxt == NULL) {
                                         th->nxt = (struct tcp_seq_hash *)
                                                 calloc(1, sizeof(*th));
@@ -410,10 +424,10 @@ tcp_print(netdissect_options *ndo,
                 ND_PRINT(", ack %u", ack);
         }
 
-        ND_PRINT(", win %d", win);
+        ND_PRINT(", win %u", win);
 
         if (flags & TH_URG)
-                ND_PRINT(", urg %d", urp);
+                ND_PRINT(", urg %u", urp);
         /*
          * Handle any options.
          */
@@ -471,7 +485,7 @@ tcp_print(netdissect_options *ndo,
                                 } else {
                                         uint32_t s, e;
 
-                                        ND_PRINT(" %d ", datalen / 8);
+                                        ND_PRINT(" %u ", datalen / 8);
                                         for (i = 0; i < datalen; i += 8) {
                                                 LENCHECK(i + 4);
                                                 s = EXTRACT_BE_U_4(cp + i);
@@ -647,7 +661,7 @@ tcp_print(netdissect_options *ndo,
                         if (!ZEROLENOPT(opt))
                                 ++datalen;             /* size octet */
                         if (datalen != len)
-                                ND_PRINT("[len %d]", len);
+                                ND_PRINT("[len %u]", len);
                         ch = ',';
                         if (opt == TCPOPT_EOL)
                                 break;
@@ -841,7 +855,7 @@ USES_APPLE_DEPRECATED_API
 static int
 tcp_verify_signature(netdissect_options *ndo,
                      const struct ip *ip, const struct tcphdr *tp,
-                     const u_char *data, int length, const u_char *rcvsig)
+                     const u_char *data, u_int length, const u_char *rcvsig)
 {
         struct tcphdr tp1;
         u_char sig[TCP_SIGLEN];