*
* NEW command line interface for IP firewall facility
*
- * $FreeBSD: user/luigi/ipfw3-head/sbin/ipfw/ipfw2.c 203369 2010-02-02 07:39:56Z luigi $
+ * $FreeBSD: head/sbin/ipfw/ipfw2.c 206843 2010-04-19 15:11:45Z luigi $
*/
#include <sys/types.h>
{ NULL, 0 } /* terminator */
};
-/*
- * The following is used to generate a printable argument for
- * 64-bit numbers, irrespective of platform alignment and bit size.
- * Because all the printf in this program use %llu as a format,
- * we just return an unsigned long long, which is larger than
- * we need in certain cases, but saves the hassle of using
- * PRIu64 as a format specifier.
- * We don't care about inlining, this is not performance critical code.
+/*
+ * Helper routine to print a possibly unaligned uint64_t on
+ * various platform. If width > 0, print the value with
+ * the desired width, followed by a space;
+ * otherwise, return the required width.
*/
-unsigned long long
-align_uint64(const uint64_t *pll)
+int
+pr_u64(uint64_t *pd, int width)
{
- uint64_t ret;
-
- bcopy (pll, &ret, sizeof(ret));
- return ret;
+#ifdef TCC
+#define U64_FMT "I64"
+#else
+#define U64_FMT "llu"
+#endif
+ uint64_t u;
+ unsigned long long d;
+
+ bcopy (pd, &u, sizeof(u));
+ d = u;
+ return (width > 0) ?
+ printf("%*" U64_FMT " ", width, d) :
+ snprintf(NULL, 0, "%" U64_FMT, d) ;
+#undef U64_FMT
}
void *
}
printf("%05u ", rule->rulenum);
- if (pcwidth>0 || bcwidth>0)
+ if (pcwidth > 0 || bcwidth > 0) {
+ pr_u64(&rule->pcnt, pcwidth);
+ pr_u64(&rule->bcnt, bcwidth);
+ }
- /* Tcc relies on msvcrt.dll for printf, and
- * it does not support ANSI %llu syntax
- */
-#ifndef TCC
- printf("%*llu %*llu ", pcwidth, align_uint64(&rule->pcnt),
- bcwidth, align_uint64(&rule->bcnt));
-#else
- printf("%*I64u %*I64u ", pcwidth, align_uint64(&rule->pcnt),
- bcwidth, align_uint64(&rule->bcnt));
-#endif
if (co.do_time == 2)
printf("%10u ", rule->timestamp);
else if (co.do_time == 1) {
}
bcopy(&d->rule, &rulenum, sizeof(rulenum));
printf("%05d", rulenum);
- if (pcwidth>0 || bcwidth>0)
-
- /* Tcc relies on msvcrt.dll for printf, and
- * it does not support ANSI %llu syntax
- */
-#ifndef TCC
- printf(" %*llu %*llu (%ds)", pcwidth,
- align_uint64(&d->pcnt), bcwidth,
- align_uint64(&d->bcnt), d->expire);
-#else
- /*printf(" %*I64u %*I64u (%ds)", pcwidth,
- align_uint64(&d->pcnt), bcwidth,
- align_uint64(&d->bcnt), d->expire);*/
-
- //XXX workaround here, for multiple I64 on the same printf
- printf(" %*I64u",pcwidth,align_uint64(&d->pcnt));
- printf(" %*I64u",bcwidth,align_uint64(&d->bcnt));
- printf(" (%ds)",d->expire);
-#endif
+ if (pcwidth > 0 || bcwidth > 0) {
+ printf(" ");
+ pr_u64(&d->pcnt, pcwidth);
+ pr_u64(&d->bcnt, bcwidth);
+ printf("(%ds)", d->expire);
+ }
switch (d->dyn_type) {
case O_LIMIT_PARENT:
printf(" PARENT %d", d->count);
} else if (_substrcmp(*av, "firewall") == 0) {
sysctlbyname("net.inet.ip.fw.enable", NULL, 0,
&which, sizeof(which));
+ sysctlbyname("net.inet6.ip6.fw.enable", NULL, 0,
+ &which, sizeof(which));
} else if (_substrcmp(*av, "one_pass") == 0) {
sysctlbyname("net.inet.ip.fw.one_pass", NULL, 0,
&which, sizeof(which));
continue;
/* packet counter */
-
- /* Tcc relies on msvcrt.dll for printf, and
- * it does not support ANSI %llu syntax
- */
-#ifndef TCC
- width = snprintf(NULL, 0, "%llu", align_uint64(&r->pcnt));
-#else
- width = snprintf(NULL, 0, "%I64u", align_uint64(&r->pcnt));
-#endif
+ width = pr_u64(&r->pcnt, 0);
if (width > pcwidth)
pcwidth = width;
/* byte counter */
-#ifndef TCC
- width = snprintf(NULL, 0, "%llu",align_uint64(&r->bcnt));
-#else
- width = snprintf(NULL, 0, "%I64u",align_uint64(&r->bcnt));
-#endif
+ width = pr_u64(&r->bcnt, 0);
if (width > bcwidth)
bcwidth = width;
}
if (set != co.use_set - 1)
continue;
}
-
- /* Tcc relies on msvcrt.dll for printf, and
- * it does not support ANSI %llu syntax
- */
-#ifndef TCC
- width = snprintf(NULL, 0, "%llu",align_uint64(&d->pcnt));
-#else
- width = snprintf(NULL, 0, "%I64u",align_uint64(&d->pcnt));
-#endif
+ width = pr_u64(&d->pcnt, 0);
if (width > pcwidth)
pcwidth = width;
-#ifndef TCC
- width = snprintf(NULL, 0, "%llu",align_uint64(&d->bcnt));
-#else
- width = snprintf(NULL, 0, "%I64u",align_uint64(&d->bcnt));
-#endif
+ width = pr_u64(&d->bcnt, 0);
if (width > bcwidth)
bcwidth = width;
}