summaryrefslogtreecommitdiffstats
path: root/ip6tables-multi.c
diff options
context:
space:
mode:
authorStefan Tomanek <stefan.tomanek@wertarbyte.de>2011-03-07 18:30:27 +0100
committerJan Engelhardt <jengelh@medozas.de>2011-03-07 20:07:55 +0100
commit9cc4f24e72f87ca191c2e723e7cd293f6477481c (patch)
tree04d0e4229715449f1c5786535d14e7142c809e24 /ip6tables-multi.c
parentf96cb8094ceffb9ffe8e94b4ee6800aa581dd021 (diff)
ip(6)tables-multi: unify subcommand handling
I found the subcommand handling and naming done by iptables-multi and ip6tables-multi very confusing and complicated; this patch reorganizes the subcommands in a single table, allowing both variants of them to be used (iptables/main) and also prints a list of the allowed commands if an unknown command is entered by the user. Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
Diffstat (limited to 'ip6tables-multi.c')
-rw-r--r--ip6tables-multi.c46
1 files changed, 12 insertions, 34 deletions
diff --git a/ip6tables-multi.c b/ip6tables-multi.c
index 671558c5..7e6603f8 100644
--- a/ip6tables-multi.c
+++ b/ip6tables-multi.c
@@ -1,45 +1,23 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <libgen.h>
+#include "xshared.h"
int ip6tables_main(int argc, char **argv);
int ip6tables_save_main(int argc, char **argv);
int ip6tables_restore_main(int argc, char **argv);
+static const struct subcommand multi6_subcommands[] = {
+ {"ip6tables", ip6tables_main},
+ {"main", ip6tables_main},
+ {"ip6tables-save", ip6tables_save_main},
+ {"save", ip6tables_save_main},
+ {"ip6tables-restore", ip6tables_restore_main},
+ {"restore", ip6tables_restore_main},
+ {NULL},
+};
+
int main(int argc, char **argv)
{
- char *progname;
-
- if (argc < 1) {
- fprintf(stderr, "ERROR: This should not happen.\n");
- exit(EXIT_FAILURE);
- }
-
- progname = basename(argv[0]);
- if (strcmp(progname, "ip6tables") == 0)
- return ip6tables_main(argc, argv);
- if (strcmp(progname, "ip6tables-save") == 0)
- return ip6tables_save_main(argc, argv);
- if (strcmp(progname, "ip6tables-restore") == 0)
- return ip6tables_restore_main(argc, argv);
-
- ++argv;
- --argc;
- if (argc < 1) {
- fprintf(stderr, "ERROR: No subcommand given.\n");
- exit(EXIT_FAILURE);
- }
-
- progname = basename(argv[0]);
- if (strcmp(progname, "main") == 0)
- return ip6tables_main(argc, argv);
- if (strcmp(progname, "save") == 0)
- return ip6tables_save_main(argc, argv);
- if (strcmp(progname, "restore") == 0)
- return ip6tables_restore_main(argc, argv);
-
- fprintf(stderr, "ip6tables multi-purpose version: "
- "unknown subcommand \"%s\"\n", progname);
- exit(EXIT_FAILURE);
+ return subcmd_main(argc, argv, multi6_subcommands);
}