diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2008-11-23 23:59:44 +0100 |
---|---|---|
committer | Eric Leblond <eric@inl.fr> | 2008-12-09 01:19:25 +0100 |
commit | d4cf078cb71a943af0dcaa51ed5f950df0fdeca3 (patch) | |
tree | 7a732b2f7526343f76ab71092bd6b7dccc233497 /filter/ulogd_filter_IFINDEX.c | |
parent | 8aa47fcd3c013913b5e553053e0098b6765e5544 (diff) |
add ukey_* function for key assignation
This patch cleans up the current key assignation by introducing a
set of functions ukey_* to set the key value as Eric Leblond and
we discussed during the latest Netfilter Workshop. This patch is
based on an idea from Holger Eitzenberger.
Signed-off-by: Eric Leblond <eric@inl.fr>
Diffstat (limited to 'filter/ulogd_filter_IFINDEX.c')
-rw-r--r-- | filter/ulogd_filter_IFINDEX.c | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/filter/ulogd_filter_IFINDEX.c b/filter/ulogd_filter_IFINDEX.c index f7571bd..f56ee0b 100644 --- a/filter/ulogd_filter_IFINDEX.c +++ b/filter/ulogd_filter_IFINDEX.c @@ -3,6 +3,7 @@ * ulogd interpreter plugin for ifindex to ifname conversion * * (C) 2005 by Harald Welte <laforge@gnumonks.org> + * (C) 2008 by Pablo Neira Ayuso <pablo@netfilter.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 @@ -61,20 +62,25 @@ static int interp_ifindex(struct ulogd_pluginstance *pi) { struct ulogd_key *ret = pi->output.keys; struct ulogd_key *inp = pi->input.keys; + void *ptr; - ret[0].u.value.ptr = calloc(IFNAMSIZ, sizeof(char)); - nlif_index2name(nlif_inst, inp[0].u.source->u.value.ui32, - ret[0].u.value.ptr); - if (((char *)ret[0].u.value.ptr)[0] == '*') - ((char *)(ret[0].u.value.ptr))[0] = 0; - ret[0].flags |= ULOGD_RETF_VALID; - - ret[1].u.value.ptr = calloc(IFNAMSIZ, sizeof(char)); - nlif_index2name(nlif_inst, inp[1].u.source->u.value.ui32, - ret[1].u.value.ptr); - if (((char *)ret[1].u.value.ptr)[0] == '*') - ((char *)(ret[1].u.value.ptr))[0] = 0; - ret[1].flags |= ULOGD_RETF_VALID; + ptr = calloc(IFNAMSIZ, sizeof(char)); + if (!ptr) + return ULOGD_IRET_ERR; + + nlif_index2name(nlif_inst, ikey_get_u32(&inp[0]), ptr); + if (((char *)ptr)[0] == '*') + ((char *)(ptr))[0] = 0; + okey_set_ptr(&ret[0], ptr); + + ptr = calloc(IFNAMSIZ, sizeof(char)); + if (!ptr) + return ULOGD_IRET_ERR; + + nlif_index2name(nlif_inst, ikey_get_u32(&inp[1]), ptr); + if (((char *)ptr)[0] == '*') + ((char *)(ptr))[0] = 0; + okey_set_ptr(&ret[1], ptr); return ULOGD_IRET_OK; } |