summaryrefslogtreecommitdiffstats
path: root/sbin/ipfw
diff options
context:
space:
mode:
authormaxim <maxim@FreeBSD.org>2003-03-13 10:51:53 +0000
committermaxim <maxim@FreeBSD.org>2003-03-13 10:51:53 +0000
commit943ba45ae5ca2f2d117bcb4d8a03441351d87c0f (patch)
tree525a1d8e267838aa6fea92e0c2a5f6fdb1aace91 /sbin/ipfw
parent64228bbbc70b981a7340cccbf235f5e197c02fc4 (diff)
downloadFreeBSD-src-943ba45ae5ca2f2d117bcb4d8a03441351d87c0f.zip
FreeBSD-src-943ba45ae5ca2f2d117bcb4d8a03441351d87c0f.tar.gz
o Partially revert rev. 1.103, fix 'ipfw show': dynamically adjust a
width of fields for packets and bytes counters. PR: bin/47196 Reviewed by: -audit Not objected by: luigi, des o Use %llu instead of deprecated %qu convert specification for ipfw packets and bytes counters. Noted by: des MFC after: 1 month
Diffstat (limited to 'sbin/ipfw')
-rw-r--r--sbin/ipfw/ipfw2.c50
1 files changed, 39 insertions, 11 deletions
diff --git a/sbin/ipfw/ipfw2.c b/sbin/ipfw/ipfw2.c
index 953c7f4..6d2857f 100644
--- a/sbin/ipfw/ipfw2.c
+++ b/sbin/ipfw/ipfw2.c
@@ -802,7 +802,7 @@ show_prerequisites(int *flags, int want, int cmd)
}
static void
-show_ipfw(struct ip_fw *rule)
+show_ipfw(struct ip_fw *rule, int pcwidth, int bcwidth)
{
static int twidth = 0;
int l;
@@ -823,7 +823,8 @@ show_ipfw(struct ip_fw *rule)
printf("%05u ", rule->rulenum);
if (do_acct)
- printf("%10qu %10qu ", rule->pcnt, rule->bcnt);
+ printf("%*llu %*llu ", pcwidth, rule->pcnt, bcwidth,
+ rule->bcnt);
if (do_time) {
char timestr[30];
@@ -1202,7 +1203,7 @@ show_ipfw(struct ip_fw *rule)
}
static void
-show_dyn_ipfw(ipfw_dyn_rule *d)
+show_dyn_ipfw(ipfw_dyn_rule *d, int pcwidth, int bcwidth)
{
struct protoent *pe;
struct in_addr a;
@@ -1212,8 +1213,8 @@ show_dyn_ipfw(ipfw_dyn_rule *d)
return;
}
- printf("%05d %10qu %10qu (%ds)",
- d->rulenum, d->pcnt, d->bcnt, d->expire);
+ printf("%05d %*llu %*llu (%ds)", d->rulenum, pcwidth, d->pcnt, bcwidth,
+ d->bcnt, d->expire);
switch (d->dyn_type) {
case O_LIMIT_PARENT:
printf(" PARENT %d", d->count);
@@ -1557,7 +1558,7 @@ list(int ac, char *av[])
ipfw_dyn_rule *dynrules, *d;
void *lim, *data = NULL;
- int n, nbytes, nstat, ndyn;
+ int bcwidth, n, nbytes, nstat, ndyn, pcwidth, width;
int exitval = EX_OK;
int lac;
char **lav;
@@ -1607,16 +1608,43 @@ list(int ac, char *av[])
n = (void *)r - data;
ndyn = (nbytes - n) / sizeof *dynrules;
+ /* if showing stats, figure out column widths ahead of time */
+ bcwidth = pcwidth = 0;
+ if (do_acct) {
+ for (n = 0, r = data; n < nstat;
+ n++, r = (void *)r + RULESIZE(r)) {
+ /* packet counter */
+ width = snprintf(NULL, 0, "%llu", r->pcnt);
+ if (width > pcwidth)
+ pcwidth = width;
+
+ /* byte counter */
+ width = snprintf(NULL, 0, "%llu", r->bcnt);
+ if (width > bcwidth)
+ bcwidth = width;
+ }
+ }
+ if (do_dynamic && ndyn) {
+ for (n = 0, d = dynrules; n < ndyn; n++, d++) {
+ width = snprintf(NULL, 0, "%llu", d->pcnt);
+ if (width > pcwidth)
+ pcwidth = width;
+
+ width = snprintf(NULL, 0, "%llu", d->bcnt);
+ if (width > bcwidth)
+ bcwidth = width;
+ }
+ }
/* if no rule numbers were specified, list all rules */
if (ac == 0) {
for (n = 0, r = data; n < nstat;
n++, r = (void *)r + RULESIZE(r) )
- show_ipfw(r);
+ show_ipfw(r, pcwidth, bcwidth);
if (do_dynamic && ndyn) {
printf("## Dynamic rules (%d):\n", ndyn);
for (n = 0, d = dynrules; n < ndyn; n++, d++)
- show_dyn_ipfw(d);
+ show_dyn_ipfw(d, pcwidth, bcwidth);
}
goto done;
}
@@ -1636,7 +1664,7 @@ list(int ac, char *av[])
if (r->rulenum > rnum)
break;
if (r->rulenum == rnum) {
- show_ipfw(r);
+ show_ipfw(r, pcwidth, bcwidth);
seen = 1;
}
}
@@ -1659,7 +1687,7 @@ list(int ac, char *av[])
if (d->rulenum > rnum)
break;
if (d->rulenum == rnum)
- show_dyn_ipfw(d);
+ show_dyn_ipfw(d, pcwidth, bcwidth);
}
}
}
@@ -3221,7 +3249,7 @@ done:
if (getsockopt(s, IPPROTO_IP, IP_FW_ADD, rule, &i) == -1)
err(EX_UNAVAILABLE, "getsockopt(%s)", "IP_FW_ADD");
if (!do_quiet)
- show_ipfw(rule);
+ show_ipfw(rule, 10, 10);
}
static void
OpenPOWER on IntegriCloud