From 73866357e4a7a0fdc1b293bf8863fee2bd56da9e Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Sat, 18 Dec 2010 02:04:59 +0100 Subject: iptables: do not print trailing whitespaces Due to the use of printf("foobar "), iptables emits spaces at the end-of-line, which looks odd to some users because it causes the terminal to wrap even if there is seemingly nothing to print. It may also have other points of annoyance, such as mailers interpreting a trailing space as an indicator that the paragraph continues when format=flowed is also on. And git highlights trailing spaces in red, so let's avoid :) Preexisting inconsistencies in outputting spaces in the right spot are also addressed right away. References: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=429579 Signed-off-by: Jan Engelhardt --- extensions/libxt_iprange.c | 76 ++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 39 deletions(-) (limited to 'extensions/libxt_iprange.c') diff --git a/extensions/libxt_iprange.c b/extensions/libxt_iprange.c index 2ac2fa4d..2a914165 100644 --- a/extensions/libxt_iprange.c +++ b/extensions/libxt_iprange.c @@ -202,7 +202,7 @@ print_iprange(const struct ipt_iprange *range) byte_min = (const unsigned char *)&range->min_ip; byte_max = (const unsigned char *)&range->max_ip; - printf("%u.%u.%u.%u-%u.%u.%u.%u ", + printf(" %u.%u.%u.%u-%u.%u.%u.%u", byte_min[0], byte_min[1], byte_min[2], byte_min[3], byte_max[0], byte_max[1], byte_max[2], byte_max[3]); } @@ -213,15 +213,15 @@ static void iprange_print(const void *ip, const struct xt_entry_match *match, const struct ipt_iprange_info *info = (const void *)match->data; if (info->flags & IPRANGE_SRC) { - printf("source IP range "); + printf(" source IP range"); if (info->flags & IPRANGE_SRC_INV) - printf("! "); + printf(" !"); print_iprange(&info->src); } if (info->flags & IPRANGE_DST) { - printf("destination IP range "); + printf(" destination IP range"); if (info->flags & IPRANGE_DST_INV) - printf("! "); + printf(" !"); print_iprange(&info->dst); } } @@ -233,22 +233,22 @@ iprange_mt4_print(const void *ip, const struct xt_entry_match *match, const struct xt_iprange_mtinfo *info = (const void *)match->data; if (info->flags & IPRANGE_SRC) { - printf("source IP range "); + printf(" source IP range"); if (info->flags & IPRANGE_SRC_INV) - printf("! "); + printf(" !"); /* * ipaddr_to_numeric() uses a static buffer, so cannot * combine the printf() calls. */ - printf("%s", xtables_ipaddr_to_numeric(&info->src_min.in)); - printf("-%s ", xtables_ipaddr_to_numeric(&info->src_max.in)); + printf(" %s", xtables_ipaddr_to_numeric(&info->src_min.in)); + printf("-%s", xtables_ipaddr_to_numeric(&info->src_max.in)); } if (info->flags & IPRANGE_DST) { - printf("destination IP range "); + printf(" destination IP range"); if (info->flags & IPRANGE_DST_INV) - printf("! "); - printf("%s", xtables_ipaddr_to_numeric(&info->dst_min.in)); - printf("-%s ", xtables_ipaddr_to_numeric(&info->dst_max.in)); + printf(" !"); + printf(" %s", xtables_ipaddr_to_numeric(&info->dst_min.in)); + printf("-%s", xtables_ipaddr_to_numeric(&info->dst_max.in)); } } @@ -259,22 +259,22 @@ iprange_mt6_print(const void *ip, const struct xt_entry_match *match, const struct xt_iprange_mtinfo *info = (const void *)match->data; if (info->flags & IPRANGE_SRC) { - printf("source IP range "); + printf(" source IP range"); if (info->flags & IPRANGE_SRC_INV) - printf("! "); + printf(" !"); /* * ipaddr_to_numeric() uses a static buffer, so cannot * combine the printf() calls. */ - printf("%s", xtables_ip6addr_to_numeric(&info->src_min.in6)); - printf("-%s ", xtables_ip6addr_to_numeric(&info->src_max.in6)); + printf(" %s", xtables_ip6addr_to_numeric(&info->src_min.in6)); + printf("-%s", xtables_ip6addr_to_numeric(&info->src_max.in6)); } if (info->flags & IPRANGE_DST) { - printf("destination IP range "); + printf(" destination IP range"); if (info->flags & IPRANGE_DST_INV) - printf("! "); - printf("%s", xtables_ip6addr_to_numeric(&info->dst_min.in6)); - printf("-%s ", xtables_ip6addr_to_numeric(&info->dst_max.in6)); + printf(" !"); + printf(" %s", xtables_ip6addr_to_numeric(&info->dst_min.in6)); + printf("-%s", xtables_ip6addr_to_numeric(&info->dst_max.in6)); } } @@ -284,16 +284,14 @@ static void iprange_save(const void *ip, const struct xt_entry_match *match) if (info->flags & IPRANGE_SRC) { if (info->flags & IPRANGE_SRC_INV) - printf("! "); - printf("--src-range "); + printf(" !"); + printf(" --src-range"); print_iprange(&info->src); - if (info->flags & IPRANGE_DST) - fputc(' ', stdout); } if (info->flags & IPRANGE_DST) { if (info->flags & IPRANGE_DST_INV) - printf("! "); - printf("--dst-range "); + printf(" !"); + printf(" --dst-range"); print_iprange(&info->dst); } } @@ -304,15 +302,15 @@ static void iprange_mt4_save(const void *ip, const struct xt_entry_match *match) if (info->flags & IPRANGE_SRC) { if (info->flags & IPRANGE_SRC_INV) - printf("! "); - printf("--src-range %s", xtables_ipaddr_to_numeric(&info->src_min.in)); - printf("-%s ", xtables_ipaddr_to_numeric(&info->src_max.in)); + printf(" !"); + printf(" --src-range %s", xtables_ipaddr_to_numeric(&info->src_min.in)); + printf("-%s", xtables_ipaddr_to_numeric(&info->src_max.in)); } if (info->flags & IPRANGE_DST) { if (info->flags & IPRANGE_DST_INV) - printf("! "); - printf("--dst-range %s", xtables_ipaddr_to_numeric(&info->dst_min.in)); - printf("-%s ", xtables_ipaddr_to_numeric(&info->dst_max.in)); + printf(" !"); + printf(" --dst-range %s", xtables_ipaddr_to_numeric(&info->dst_min.in)); + printf("-%s", xtables_ipaddr_to_numeric(&info->dst_max.in)); } } @@ -322,15 +320,15 @@ static void iprange_mt6_save(const void *ip, const struct xt_entry_match *match) if (info->flags & IPRANGE_SRC) { if (info->flags & IPRANGE_SRC_INV) - printf("! "); - printf("--src-range %s", xtables_ip6addr_to_numeric(&info->src_min.in6)); - printf("-%s ", xtables_ip6addr_to_numeric(&info->src_max.in6)); + printf(" !"); + printf(" --src-range %s", xtables_ip6addr_to_numeric(&info->src_min.in6)); + printf("-%s", xtables_ip6addr_to_numeric(&info->src_max.in6)); } if (info->flags & IPRANGE_DST) { if (info->flags & IPRANGE_DST_INV) - printf("! "); - printf("--dst-range %s", xtables_ip6addr_to_numeric(&info->dst_min.in6)); - printf("-%s ", xtables_ip6addr_to_numeric(&info->dst_max.in6)); + printf(" !"); + printf(" --dst-range %s", xtables_ip6addr_to_numeric(&info->dst_min.in6)); + printf("-%s", xtables_ip6addr_to_numeric(&info->dst_max.in6)); } } -- cgit v1.2.3