diff --git a/sbin/ipfw/ipfw.8 b/sbin/ipfw/ipfw.8 index 67ed26225d04..0ea3b7af55ab 100644 --- a/sbin/ipfw/ipfw.8 +++ b/sbin/ipfw/ipfw.8 @@ -218,6 +218,11 @@ Do not ask for confirmation for commands that can cause problems if misused, .No i.e. Cm flush . If there is no tty associated with the process, this is implied. +.It Fl i +While listing a table (see the +.Sx LOOKUP TABLES +section below for more information on lookup tables), format values +as IP addresses. By default, values are shown as integers. .It Fl n Only check syntax of the command strings, without actually passing them to the kernel. diff --git a/sbin/ipfw/ipfw2.c b/sbin/ipfw/ipfw2.c index f5b3ae9a9071..1366ab2e20ff 100644 --- a/sbin/ipfw/ipfw2.c +++ b/sbin/ipfw/ipfw2.c @@ -66,6 +66,7 @@ #include int + do_value_as_ip, /* show table value as IP */ do_resolv, /* Would try to resolve all */ do_time, /* Show time stamps */ do_quiet, /* Be quiet in add and flush */ @@ -5898,22 +5899,20 @@ table_handler(int ac, char *av[]) if (do_cmd(IP_FW_TABLE_LIST, tbl, (uintptr_t)&l) < 0) err(EX_OSERR, "getsockopt(IP_FW_TABLE_LIST)"); for (a = 0; a < tbl->cnt; a++) { - /* Heuristic to print it the right way */ - /* values < 64k are printed as numbers */ unsigned int tval; tval = tbl->ent[a].value; - if (tval > 0xffff) { + if (do_value_as_ip) { char tbuf[128]; strncpy(tbuf, inet_ntoa(*(struct in_addr *) &tbl->ent[a].addr), 127); - /* inet_ntoa expects host order */ + /* inet_ntoa expects network order */ tval = htonl(tval); printf("%s/%u %s\n", tbuf, tbl->ent[a].masklen, inet_ntoa(*(struct in_addr *)&tval)); } else { printf("%s/%u %u\n", inet_ntoa(*(struct in_addr *)&tbl->ent[a].addr), - tbl->ent[a].masklen, tbl->ent[a].value); + tbl->ent[a].masklen, tval); } } } else @@ -6096,7 +6095,7 @@ ipfw_main(int oldac, char **oldav) save_av = av; optind = optreset = 0; - while ((ch = getopt(ac, av, "abcdefhnNqs:STtv")) != -1) + while ((ch = getopt(ac, av, "abcdefhinNqs:STtv")) != -1) switch (ch) { case 'a': do_acct = 1; @@ -6128,6 +6127,10 @@ ipfw_main(int oldac, char **oldav) help(); break; /* NOTREACHED */ + case 'i': + do_value_as_ip = 1; + break; + case 'n': test_only = 1; break;