summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2015-11-10 19:25:46 +0100
committerTobias Klauser <tklauser@distanz.ch>2015-11-10 19:25:46 +0100
commit5c94119f5e03d5eb33b5b9717a4afa63522919ae (patch)
treef8b9db354401076bbb7bf58b4a4763eb043ae132
parent664dcf4217c4fc08cc43c050419fea8181d81ef1 (diff)
netsniff-ng: tcp: Don't print trailing space after last TCP flag name
Check whether there were flags printed before and if this is the case, add a space before printing the next flag. Nicely wrap this all in a macro. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--proto_tcp.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/proto_tcp.c b/proto_tcp.c
index 96d00f6..6f2ab14 100644
--- a/proto_tcp.c
+++ b/proto_tcp.c
@@ -51,11 +51,21 @@ struct tcphdr {
uint16_t urg_ptr;
} __packed;
+#define tprintf_flag(flag, str, prev) ({ \
+ bool __r = false; \
+ if (flag) { \
+ tprintf("%s%s", (prev) ? " " : "", str); \
+ __r = true; \
+ } \
+ __r; \
+})
+
static void tcp(struct pkt_buff *pkt)
{
struct tcphdr *tcp = (struct tcphdr *) pkt_pull(pkt, sizeof(*tcp));
uint16_t src, dest;
char *src_name, *dest_name;
+ bool v = false;
if (tcp == NULL)
return;
@@ -81,22 +91,14 @@ static void tcp(struct pkt_buff *pkt)
tprintf("DataOff (%u), ", tcp->doff);
tprintf("Res (%u), ", tcp->res1);
tprintf("Flags (");
- if (tcp->fin)
- tprintf("FIN ");
- if (tcp->syn)
- tprintf("SYN ");
- if (tcp->rst)
- tprintf("RST ");
- if (tcp->psh)
- tprintf("PSH ");
- if (tcp->ack)
- tprintf("ACK ");
- if (tcp->urg)
- tprintf("URG ");
- if (tcp->ece)
- tprintf("ECE ");
- if (tcp->cwr)
- tprintf("CWR ");
+ v = tprintf_flag(tcp->fin, "FIN", v);
+ v = tprintf_flag(tcp->syn, "SYN", v);
+ v = tprintf_flag(tcp->rst, "RST", v);
+ v = tprintf_flag(tcp->psh, "PSH", v);
+ v = tprintf_flag(tcp->ack, "ACK", v);
+ v = tprintf_flag(tcp->urg, "URG", v);
+ v = tprintf_flag(tcp->ece, "ECE", v);
+ v = tprintf_flag(tcp->cwr, "CWR", v);
tprintf("), ");
tprintf("Window (%u), ", ntohs(tcp->window));
tprintf("CSum (0x%.4x), ", ntohs(tcp->check));