summaryrefslogtreecommitdiffstats
path: root/xtoptions.c
diff options
context:
space:
mode:
authorJan Engelhardt <jengelh@medozas.de>2011-02-15 22:09:21 +0100
committerJan Engelhardt <jengelh@medozas.de>2011-04-06 13:12:55 +0200
commit4a0a17620017c1f45946b2cde7139ef18ea3d93c (patch)
tree04f15b14ac4946ac9a43e2736cd7f1e2d779b290 /xtoptions.c
parenta3876fa13ffe792e209cc1a8ac1214946c898eea (diff)
libxtables: XTTYPE_STRING support
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
Diffstat (limited to 'xtoptions.c')
-rw-r--r--xtoptions.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/xtoptions.c b/xtoptions.c
index 03c629e0..631e7a3c 100644
--- a/xtoptions.c
+++ b/xtoptions.c
@@ -163,16 +163,41 @@ static void xtopt_parse_mint(struct xt_option_call *cb)
}
}
+static void xtopt_parse_string(struct xt_option_call *cb)
+{
+ const struct xt_option_entry *entry = cb->entry;
+ size_t z = strlen(cb->arg);
+ char *p;
+
+ if (entry->min != 0 && z < entry->min)
+ xt_params->exit_err(PARAMETER_PROBLEM,
+ "Argument must have a minimum length of "
+ "%u characters\n", entry->min);
+ if (entry->max != 0 && z > entry->max)
+ xt_params->exit_err(PARAMETER_PROBLEM,
+ "Argument must have a maximum length of "
+ "%u characters\n", entry->max);
+ if (!(entry->flags & XTOPT_PUT))
+ return;
+ if (z >= entry->size)
+ z = entry->size - 1;
+ p = XTOPT_MKPTR(cb);
+ strncpy(p, cb->arg, z);
+ p[z] = '\0';
+}
+
static void (*const xtopt_subparse[])(struct xt_option_call *) = {
[XTTYPE_UINT8] = xtopt_parse_int,
[XTTYPE_UINT32] = xtopt_parse_int,
[XTTYPE_UINT32RC] = xtopt_parse_mint,
+ [XTTYPE_STRING] = xtopt_parse_string,
};
static const size_t xtopt_psize[] = {
[XTTYPE_UINT8] = sizeof(uint8_t),
[XTTYPE_UINT32] = sizeof(uint32_t),
[XTTYPE_UINT32RC] = sizeof(uint32_t[2]),
+ [XTTYPE_STRING] = -1,
};
/**