summaryrefslogtreecommitdiffstats
path: root/xtables.c
diff options
context:
space:
mode:
authorJamal Hadi Salim <hadi@cyberus.ca>2009-02-13 08:36:44 -0500
committerJan Engelhardt <jengelh@medozas.de>2009-02-13 14:57:01 +0100
commit70581922f873a88306dd5b1cb83c5081ee239eb8 (patch)
tree9f0168386cbc2b77ac49abde8509c999e940370a /xtables.c
parentae19604fe1c4ab02dfbcd450e73826111f0f2b27 (diff)
libxtables: consolidate merge_options into xtables_merge_options
Introduce xtables_merge_options() for re-use reasons. Apps can use it instead of each defining their own merge_options(). Made iptables and ip6tables use the new shared interface. Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
Diffstat (limited to 'xtables.c')
-rw-r--r--xtables.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/xtables.c b/xtables.c
index c8024bf2..bdb0133d 100644
--- a/xtables.c
+++ b/xtables.c
@@ -47,6 +47,7 @@
# define IP6T_SO_GET_REVISION_MATCH 68
# define IP6T_SO_GET_REVISION_TARGET 69
#endif
+#include <getopt.h>
#define NPROTO 255
@@ -107,6 +108,36 @@ void xtables_free_opts(int reset_offset)
}
}
+struct option *xtables_merge_options(struct option *oldopts,
+ const struct option *newopts,
+ unsigned int *option_offset)
+{
+ unsigned int num_old, num_new, i;
+ struct option *merge;
+
+ if (newopts == NULL)
+ return oldopts;
+
+ for (num_old = 0; oldopts[num_old].name; num_old++) ;
+ for (num_new = 0; newopts[num_new].name; num_new++) ;
+
+ xt_params->option_offset += OPTION_OFFSET;
+ *option_offset = xt_params->option_offset;
+
+ merge = malloc(sizeof(struct option) * (num_new + num_old + 1));
+ if (merge == NULL)
+ return NULL;
+ memcpy(merge, oldopts, num_old * sizeof(struct option));
+ xtables_free_opts(0); /* Release any old options merged */
+ for (i = 0; i < num_new; i++) {
+ merge[num_old + i] = newopts[i];
+ merge[num_old + i].val += *option_offset;
+ }
+ memset(merge + num_old + num_new, 0, sizeof(struct option));
+
+ return merge;
+}
+
void xtables_set_revision(char *name, u_int8_t revision)
{
/* Old kernel sources don't have ".revision" field,