summaryrefslogtreecommitdiffstats
path: root/iptables
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2019-07-18 14:44:09 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2019-07-18 17:00:17 +0200
commit427deccbd4479dcb943bc7eab14f228c23b264b6 (patch)
treed917e6d8570bf133e00723e9d036ede89eea0607 /iptables
parente5cab728c40be88c541f68e4601d39178c36111f (diff)
xtables-save: Use argv[0] as program name
Don't hard-code program names. This also fixes for bogus 'xtables-save' name which is no longer used. Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'iptables')
-rw-r--r--iptables/xtables-save.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/iptables/xtables-save.c b/iptables/xtables-save.c
index 98e004af..b8d19705 100644
--- a/iptables/xtables-save.c
+++ b/iptables/xtables-save.c
@@ -9,6 +9,7 @@
#include "config.h"
#include <getopt.h>
#include <errno.h>
+#include <libgen.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
@@ -80,8 +81,8 @@ __do_output(struct nft_handle *h, const char *tablename, bool counters)
time_t now = time(NULL);
- printf("# Generated by xtables-save v%s on %s",
- PACKAGE_VERSION, ctime(&now));
+ printf("# Generated by %s v%s on %s", prog_name,
+ prog_vers, ctime(&now));
printf("*%s\n", tablename);
/* Dump out chain names first,
@@ -122,7 +123,7 @@ do_output(struct nft_handle *h, const char *tablename, bool counters)
* rule
*/
static int
-xtables_save_main(int family, const char *progname, int argc, char *argv[])
+xtables_save_main(int family, int argc, char *argv[])
{
const struct builtin_table *tables;
const char *tablename = NULL;
@@ -133,7 +134,7 @@ xtables_save_main(int family, const char *progname, int argc, char *argv[])
FILE *file = NULL;
int ret, c;
- xtables_globals.program_name = progname;
+ xtables_globals.program_name = basename(*argv);;
c = xtables_init_all(&xtables_globals, family);
if (c < 0) {
fprintf(stderr, "%s/%s Failed to initialize xtables\n",
@@ -237,12 +238,12 @@ xtables_save_main(int family, const char *progname, int argc, char *argv[])
int xtables_ip4_save_main(int argc, char *argv[])
{
- return xtables_save_main(NFPROTO_IPV4, "iptables-save", argc, argv);
+ return xtables_save_main(NFPROTO_IPV4, argc, argv);
}
int xtables_ip6_save_main(int argc, char *argv[])
{
- return xtables_save_main(NFPROTO_IPV6, "ip6tables-save", argc, argv);
+ return xtables_save_main(NFPROTO_IPV6, argc, argv);
}
static int __ebt_save(struct nft_handle *h, const char *tablename, bool counters)
@@ -266,8 +267,8 @@ static int __ebt_save(struct nft_handle *h, const char *tablename, bool counters
if (first) {
now = time(NULL);
- printf("# Generated by ebtables-save v%s on %s",
- PACKAGE_VERSION, ctime(&now));
+ printf("# Generated by %s v%s on %s", prog_name,
+ prog_vers, ctime(&now));
first = false;
}
printf("*%s\n", tablename);
@@ -307,7 +308,7 @@ int xtables_eb_save_main(int argc_, char *argv_[])
}
}
- xtables_globals.program_name = "ebtables-save";
+ xtables_globals.program_name = basename(*argv_);
c = xtables_init_all(&xtables_globals, h.family);
if (c < 0) {
fprintf(stderr, "%s/%s Failed to initialize xtables\n",
@@ -361,7 +362,7 @@ int xtables_arp_save_main(int argc, char **argv)
};
int c;
- xtables_globals.program_name = "arptables-save";
+ xtables_globals.program_name = basename(*argv);;
c = xtables_init_all(&xtables_globals, h.family);
if (c < 0) {
fprintf(stderr, "%s/%s Failed to initialize xtables\n",