From: Denis Ovsienko Date: Sat, 16 Jan 2021 10:56:30 +0000 (+0000) Subject: NetFlow: Use tcp_flag_values[] for TCP flags. X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/f72772154caa9c3851f91954c2a43dc2b653f637 NetFlow: Use tcp_flag_values[] for TCP flags. This way there is less code duplication and more consistency. --- diff --git a/CHANGES b/CHANGES index dcb1b6fb..c410109a 100644 --- 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!) diff --git a/print-cnfp.c b/print-cnfp.c index 101148fa..0c8e4f52 100644 --- a/print-cnfp.c +++ b/print-cnfp.c @@ -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'; diff --git a/print-tcp.c b/print-tcp.c index a1aae18a..595515c4 100644 --- a/print-tcp.c +++ b/print-tcp.c @@ -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 491157b0..a4c28b61 100644 --- 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