]> The Tcpdump Group git mirrors - tcpdump/commitdiff
NetFlow: Use tcp_flag_values[] for TCP flags.
authorDenis Ovsienko <[email protected]>
Sat, 16 Jan 2021 10:56:30 +0000 (10:56 +0000)
committerDenis Ovsienko <[email protected]>
Sun, 17 Jan 2021 20:24:45 +0000 (20:24 +0000)
This way there is less code duplication and more consistency.

CHANGES
print-cnfp.c
print-tcp.c
tcp.h

diff --git a/CHANGES b/CHANGES
index dcb1b6fb132b807130512761b88b3279758d8c59..c410109af589626ca31628574c4bab4004f5c510 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -9,6 +9,7 @@ Monthday, Month DD, YYYY by gharris and denis
       AppleTalk: Declutter appletalk.h.
       OpenFlow 1.0: Fix indentation of PORT_MOD.
       RIP: Make a couple trivial protocol updates.
+      NetFlow: Use tcp_flag_values[] for TCP flags.
 
 Monthday, Month DD, YYYY by gharris
   Summary for 4.99.1 tcpdump release (so far!)
index 101148fa86c0c138ef33315ffc46ca0cde4e0d7c..0c8e4f52b11ebe892eb14bddbb4b2566df11fb82 100644 (file)
@@ -226,14 +226,8 @@ cnfp_v1_print(netdissect_options *ndo, const u_char *cp)
                if (proto == IPPROTO_TCP) {
                        u_int flags;
                        flags = GET_U_1(nr->tcp_flags);
-                       ND_PRINT("%s%s%s%s%s%s%s",
-                               flags & TH_FIN  ? "F" : "",
-                               flags & TH_SYN  ? "S" : "",
-                               flags & TH_RST  ? "R" : "",
-                               flags & TH_PUSH ? "P" : "",
-                               flags & TH_ACK  ? "A" : "",
-                               flags & TH_URG  ? "U" : "",
-                               flags           ? " " : "");
+                       if (flags)
+                               ND_PRINT("%s ", bittok2str_nosep(tcp_flag_values, "", flags));
                }
 
                buf[0]='\0';
@@ -328,14 +322,8 @@ cnfp_v5_print(netdissect_options *ndo, const u_char *cp)
                if (proto == IPPROTO_TCP) {
                        u_int flags;
                        flags = GET_U_1(nr->tcp_flags);
-                       ND_PRINT("%s%s%s%s%s%s%s",
-                               flags & TH_FIN  ? "F" : "",
-                               flags & TH_SYN  ? "S" : "",
-                               flags & TH_RST  ? "R" : "",
-                               flags & TH_PUSH ? "P" : "",
-                               flags & TH_ACK  ? "A" : "",
-                               flags & TH_URG  ? "U" : "",
-                               flags           ? " " : "");
+                       if (flags)
+                               ND_PRINT("%s ", bittok2str_nosep(tcp_flag_values, "", flags));
                }
 
                buf[0]='\0';
@@ -430,14 +418,8 @@ cnfp_v6_print(netdissect_options *ndo, const u_char *cp)
                if (proto == IPPROTO_TCP) {
                        u_int flags;
                        flags = GET_U_1(nr->tcp_flags);
-                       ND_PRINT("%s%s%s%s%s%s%s",
-                               flags & TH_FIN  ? "F" : "",
-                               flags & TH_SYN  ? "S" : "",
-                               flags & TH_RST  ? "R" : "",
-                               flags & TH_PUSH ? "P" : "",
-                               flags & TH_ACK  ? "A" : "",
-                               flags & TH_URG  ? "U" : "",
-                               flags           ? " " : "");
+                       if (flags)
+                               ND_PRINT("%s ", bittok2str_nosep(tcp_flag_values, "", flags));
                }
 
                buf[0]='\0';
index a1aae18a8f23b1ab615c14099bfb2a577f2dfd6e..595515c4c5d62b1da3e5c6f6cc0d0e220f463779 100644 (file)
@@ -101,7 +101,7 @@ struct tcp_seq_hash6 {
 static struct tcp_seq_hash tcp_seq_hash4[TSEQ_HASHSIZE];
 static struct tcp_seq_hash6 tcp_seq_hash6[TSEQ_HASHSIZE];
 
-static const struct tok tcp_flag_values[] = {
+const struct tok tcp_flag_values[] = {
         { TH_FIN, "F" },
         { TH_SYN, "S" },
         { TH_RST, "R" },
diff --git a/tcp.h b/tcp.h
index 491157b0ae7d8920ff6dc152efeed726746504d3..a4c28b61c27584a37eb5e5c0f477451256884f81 100644 (file)
--- a/tcp.h
+++ b/tcp.h
@@ -60,6 +60,7 @@ struct tcphdr {
 #define        TH_URG     0x20
 #define TH_ECNECHO 0x40        /* ECN Echo */
 #define TH_CWR    0x80 /* ECN Cwnd Reduced */
+extern const struct tok tcp_flag_values[];
 
 
 #define        TCPOPT_EOL              0