From be37c541ae6482e2829990c12ee3bc5c7dd71e1e Mon Sep 17 00:00:00 2001 From: luigi Date: Mon, 14 Jul 2003 08:39:49 +0000 Subject: ccept of empty lines when reading from a file (this fixes a bug introduced in the latest commits). Also: * update the 'ipfw -h' output; * allow rules of the form "100 add allow ..." i.e. with the index first. (requested by Paul Richards). This was an undocumented ipfw1 behaviour, and it is left undocumented. and minor code cleanups. --- sbin/ipfw/ipfw2.c | 77 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 25 deletions(-) diff --git a/sbin/ipfw/ipfw2.c b/sbin/ipfw/ipfw2.c index 1c6f94e..17d98ba 100644 --- a/sbin/ipfw/ipfw2.c +++ b/sbin/ipfw/ipfw2.c @@ -59,7 +59,6 @@ int do_resolv, /* Would try to resolve all */ do_time, /* Show time stamps */ do_quiet, /* Be quiet in add and flush */ - do_force, /* Don't ask for confirmation */ do_pipe, /* this cmd refers to a pipe */ do_sort, /* field to sort results (0 = no) */ do_dynamic, /* display dynamic rules */ @@ -1845,7 +1844,7 @@ help(void) { fprintf(stderr, "ipfw syntax summary (but please do read the ipfw(8) manpage):\n" -"ipfw [-acdeftnNpqS] command:" +"ipfw [-acdeftTnNpqS] where 1 && isdigit(*av[0])) { + char *p = av[0]; + + av[0] = av[1]; + av[1] = p; + } + + /* * optional: pipe or queue */ - if (!strncmp(*av, "pipe", strlen(*av))) { + if (!strncmp(*av, "pipe", strlen(*av))) do_pipe = 1; - ac--; - av++; - } else if (!strncmp(*av, "queue", strlen(*av))) { + else if (!strncmp(*av, "queue", strlen(*av))) do_pipe = 2; + if (do_pipe) { ac--; av++; } @@ -3756,6 +3782,7 @@ ipfw_main(int oldac, char **oldav) */ if (do_pipe > 0 && ac > 1 && isdigit(*av[0])) { char *p = av[0]; + av[0] = av[1]; av[1] = p; } @@ -3767,7 +3794,7 @@ ipfw_main(int oldac, char **oldav) else if (!strncmp(*av, "delete", strlen(*av))) delete(ac, av); else if (!strncmp(*av, "flush", strlen(*av))) - flush(); + flush(do_force); else if (!strncmp(*av, "zero", strlen(*av))) zero(ac, av, IP_FW_ZERO); else if (!strncmp(*av, "resetlog", strlen(*av))) @@ -3787,9 +3814,7 @@ ipfw_main(int oldac, char **oldav) errx(EX_USAGE, "bad command `%s'", *av); /* Free memory allocated in the argument parsing. */ - for (ch=0; ch < save_ac; ch++) - free(save_av[ch]); - free(save_av); + free_args(save_ac, save_av); return 0; } @@ -3931,7 +3956,9 @@ main(int ac, char *av[]) if (ac > 1 && av[ac - 1][0] == '/' && access(av[ac - 1], R_OK) == 0) ipfw_readfile(ac, av); - else - ipfw_main(ac-1, av+1); + else { + if (ipfw_main(ac-1, av+1)) + show_usage(); + } return EX_OK; } -- cgit v1.1