]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-tcp.c
DCCP: Fix printing "Timestamp" and "Timestamp Echo" options
[tcpdump] / print-tcp.c
index 554f8a61eaaa6b423509c6dbe761f4bb93087081..6e4815c05e6e412e3b3124cc8437241dc39577bc 100644 (file)
@@ -173,6 +173,7 @@ tcp_print(netdissect_options *ndo,
         int rev;
         const struct ip6_hdr *ip6;
 
+       ndo->ndo_protocol = "tcp";
         tp = (const struct tcphdr *)bp;
         ip = (const struct ip *)bp2;
         if (IP_V(ip) == 6)
@@ -182,14 +183,15 @@ tcp_print(netdissect_options *ndo,
         ch = '\0';
         if (!ND_TTEST_2(tp->th_dport)) {
                if (ip6) {
-                        ND_PRINT("%s > %s: ",
+                        ND_PRINT("%s > %s:",
                                      ip6addr_string(ndo, ip6->ip6_src),
                                      ip6addr_string(ndo, ip6->ip6_dst));
                } else {
-                       ND_PRINT("%s > %s: [|tcp]",
+                       ND_PRINT("%s > %s:",
                                     ipaddr_string(ndo, ip->ip_src),
                                     ipaddr_string(ndo, ip->ip_dst));
                 }
+                nd_print_trunc(ndo);
                 return;
         }
 
@@ -267,16 +269,16 @@ tcp_print(netdissect_options *ndo,
                         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;
                         }
 
@@ -288,12 +290,15 @@ 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));
                                         if (th->nxt == NULL)
                                                 (*ndo->ndo_error)(ndo,
-                                                                 "tcp_print: calloc");
+                                                       S_ERR_ND_MEM_ALLOC,
+                                                       "tcp_print: calloc");
                                 }
                                 th->addr = tha;
                                 if (rev)
@@ -318,20 +323,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);
+                                                 sizeof(ip->ip_dst));
                                 UNALIGNED_MEMCPY(&tha.dst, ip->ip_src,
-                                                 sizeof ip->ip_src);
+                                                 sizeof(ip->ip_src));
                                 tha.port = dport << 16 | sport;
                         } else {
                                 UNALIGNED_MEMCPY(&tha.dst, ip->ip_dst,
-                                                 sizeof ip->ip_dst);
+                                                 sizeof(ip->ip_dst));
                                 UNALIGNED_MEMCPY(&tha.src, ip->ip_src,
-                                                 sizeof ip->ip_src);
+                                                 sizeof(ip->ip_src));
                                 tha.port = sport << 16 | dport;
                         }
 
@@ -343,12 +348,15 @@ 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));
                                         if (th->nxt == NULL)
                                                 (*ndo->ndo_error)(ndo,
-                                                                 "tcp_print: calloc");
+                                                       S_ERR_ND_MEM_ALLOC,
+                                                       "tcp_print: calloc");
                                 }
                                 th->addr = tha;
                                 if (rev)
@@ -779,10 +787,10 @@ tcp_print(netdissect_options *ndo,
  bad:
         ND_PRINT("[bad opt]");
         if (ch != '\0')
-                ND_PRINT(">");
+                ND_PRINT("]");
         return;
  trunc:
-        ND_PRINT("[|tcp]");
+        nd_print_trunc(ndo);
         if (ch != '\0')
                 ND_PRINT(">");
 }
@@ -817,7 +825,7 @@ print_tcp_rst_data(netdissect_options *ndo,
         while (length-- && sp < ndo->ndo_snapend) {
                 c = EXTRACT_U_1(sp);
                 sp++;
-                safeputchar(ndo, c);
+                fn_print_char(ndo, c);
         }
         ND_PRINT("]");
 }
@@ -929,10 +937,3 @@ tcp_verify_signature(netdissect_options *ndo,
 }
 USES_APPLE_RST
 #endif /* HAVE_LIBCRYPTO */
-
-/*
- * Local Variables:
- * c-style: whitesmith
- * c-basic-offset: 8
- * End:
- */