]>
git.ipfire.org Git - people/mfischer/ipfire-2.x.git/blob - src/misc-progs/getipstat.c
1 /* IPFire helper program - IPStat
3 * Get the list from IPTABLES -L
5 * Optional commandline parameters:
7 * instruct iptables to expand numbers
13 * display mangle table
20 #include <sys/types.h>
23 int main(int argc
, char** argv
)
26 // first argument has to be "iptables" since execve executes the program pointed to by filename
27 // but /sbin/iptables is actually a symlink to /sbin/xtables-legacy-multi hence that program is executed
28 // however without the notion that it was called as "iptables". So we have to pass "iptables" as first
30 char *args
[10] = {"iptables", "--list", "--verbose", "--numeric", "--wait", "5", NULL
, NULL
, NULL
, NULL
};
31 char *usage
= "getipstat [-x][-f|-n|-m]";
32 unsigned int pcount
= 6;
33 unsigned int table_set
= 0;
40 // Parse command line arguments
42 while ((opt
= getopt(argc
, argv
, "xfnm")) != -1) {
45 args
[pcount
++] = "--exact";
52 args
[pcount
++] = "--table";
53 args
[pcount
++] = "nat";
59 args
[pcount
++] = "--table";
60 args
[pcount
++] = "mangle";
65 fprintf(stderr
, "\nBad argument given.\n\n%s\n", usage
);
70 fprintf(stderr
, "\nArguments -f/-n/-m are mutualy exclusive.\n\n%s\n", usage
);
75 return run("/sbin/iptables", args
);