diff options
Diffstat (limited to 'iptables/iptables-save.c')
-rw-r--r-- | iptables/iptables-save.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/iptables/iptables-save.c b/iptables/iptables-save.c index 52929b09..d59bd34a 100644 --- a/iptables/iptables-save.c +++ b/iptables/iptables-save.c @@ -13,6 +13,7 @@ #include <string.h> #include <time.h> #include <netdb.h> +#include <unistd.h> #include "libiptc/libiptc.h" #include "iptables.h" #include "iptables-multi.h" @@ -24,6 +25,7 @@ static const struct option options[] = { {.name = "dump", .has_arg = false, .val = 'd'}, {.name = "table", .has_arg = true, .val = 't'}, {.name = "modprobe", .has_arg = true, .val = 'M'}, + {.name = "file", .has_arg = true, .val = 'f'}, {NULL}, }; @@ -127,7 +129,8 @@ int iptables_save_main(int argc, char *argv[]) { const char *tablename = NULL; - int c; + FILE *file = NULL; + int ret, c; iptables_globals.program_name = "iptables-save"; c = xtables_init_all(&iptables_globals, NFPROTO_IPV4); @@ -142,7 +145,7 @@ iptables_save_main(int argc, char *argv[]) init_extensions4(); #endif - while ((c = getopt_long(argc, argv, "bcdt:M:", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "bcdt:M:f:", options, NULL)) != -1) { switch (c) { case 'b': fprintf(stderr, "-b/--binary option is not implemented\n"); @@ -158,6 +161,21 @@ iptables_save_main(int argc, char *argv[]) case 'M': xtables_modprobe_program = optarg; break; + case 'f': + file = fopen(optarg, "w"); + if (file == NULL) { + fprintf(stderr, "Failed to open file, error: %s\n", + strerror(errno)); + exit(1); + } + ret = dup2(fileno(file), STDOUT_FILENO); + if (ret == -1) { + fprintf(stderr, "Failed to redirect stdout, error: %s\n", + strerror(errno)); + exit(1); + } + fclose(file); + break; case 'd': do_output(tablename); exit(0); |