summaryrefslogtreecommitdiffstats
path: root/extensions/libxt_tcp.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2022-11-25 03:13:14 +0100
committerPhil Sutter <phil@nwl.cc>2022-11-29 13:25:26 +0100
commit023dd2c515be63ddb2f0b6a6f3bccab4cdf7a71c (patch)
tree4209d3e8123555385bbc731fe8da9ac2c90bf07b /extensions/libxt_tcp.c
parent208290ff0bfecb49044c3df87149aa6fa683de09 (diff)
libxtables: xt_xlate_add() to take care of spacing
Try to eliminate most of the whitespace issues by separating strings from separate xt_xlate_add() calls by whitespace if needed. Cover the common case of consecutive range, list or MAC/IP address printing by inserting whitespace only if the string to be appended starts with an alphanumeric character or a brace. The latter helps to make spacing in anonymous sets consistent. Provide *_nospc() variants which disable the auto-spacing for the mandatory exception to the rule. Make things round by dropping any trailing whitespace before returning the buffer via xt_xlate_get(). Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'extensions/libxt_tcp.c')
-rw-r--r--extensions/libxt_tcp.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/extensions/libxt_tcp.c b/extensions/libxt_tcp.c
index 043382d4..2ef84299 100644
--- a/extensions/libxt_tcp.c
+++ b/extensions/libxt_tcp.c
@@ -380,10 +380,9 @@ static void print_tcp_xlate(struct xt_xlate *xl, uint8_t flags)
for (i = 0; (flags & tcp_flag_names_xlate[i].flag) == 0; i++);
- if (have_flag)
- xt_xlate_add(xl, ",");
-
- xt_xlate_add(xl, "%s", tcp_flag_names_xlate[i].name);
+ xt_xlate_add(xl, "%s%s",
+ have_flag ? "," : "",
+ tcp_flag_names_xlate[i].name);
have_flag = 1;
flags &= ~tcp_flag_names_xlate[i].flag;