From 0907c31db34713f0e74b90f725fabb5c91c5f45f Mon Sep 17 00:00:00 2001 From: Jozsef Kadlecsik Date: Wed, 23 May 2012 23:27:42 +0200 Subject: Allow saving to/restoring from a file without shell redirection Mathieu Bridon suggested that in some environments where there is no access to a full shell with input/output redirection, it'd be useful to read from/write to directly a file (bugzilla #788). The patch adds the new "-file" option to specify a filename to print into when listing/saving sets or read from when restoring sets. --- src/ui.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/ui.c') diff --git a/src/ui.c b/src/ui.c index 7e40bde..0ebacbb 100644 --- a/src/ui.c +++ b/src/ui.c @@ -154,6 +154,37 @@ ipset_match_cmd(const char *arg, const char * const name[]) (name[1] != NULL && tolower(arg[0]) == name[1][0]); } +/* Used up so far + * + * -A add + * -D del + * -E rename + * -f -file + * -F flush + * -h help + * -H help + * -L list + * -n -name + * -N create + * -o -output + * -r -resolve + * -R restore + * -s -sorted + * -S save + * -t -terse + * -T test + * -q -quiet + * -X destroy + * -v version + * -V version + * -W swap + * -! -exist + */ + +int +ipset_parse_file(struct ipset_session *session, + int opt, const char *str); + const struct ipset_envopts ipset_envopts[] = { { .name = { "-o", "-output" }, .has_arg = IPSET_MANDATORY_ARG, .flag = IPSET_OPT_MAX, @@ -202,6 +233,14 @@ const struct ipset_envopts ipset_envopts[] = { " When listing, list setnames and set headers\n" " from kernel only.", }, + { .name = { "-f", "-file" }, + .parse = ipset_parse_file, + .has_arg = IPSET_MANDATORY_ARG, .flag = IPSET_OPT_MAX, + .help = "\n" + " Read from the given file instead of standard\n" + " input (restore) or write to given file instead\n" + " of standard output (list/save).", + }, { }, }; -- cgit v1.2.3