diff options
author | Arturo Borrero <arturo.borrero.glez@gmail.com> | 2013-06-27 18:56:38 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-06-27 19:36:24 +0200 |
commit | 8e7acbfae3017cd5f30e3b17ca16354f76b81b8a (patch) | |
tree | 88164946f76b50c96ad9a08308988e434af429de /src/utils.c | |
parent | 04604b0373d907fefde0c3e13af68868f03e5d58 (diff) |
src: xml: convert family values to string
This patch translates family values to display a string:
* ip if AF_INET
* ip6 if AF_INET6
* bridge if AF_BRIDGE
* arp if 0
Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 0000000..9416540 --- /dev/null +++ b/src/utils.c @@ -0,0 +1,46 @@ +/* + * (C) 2012-2013 by Pablo Neira Ayuso <pablo@netfilter.org> + * (C) 2013 by Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include <internal.h> +#include <stdlib.h> +#include <string.h> +#include <limits.h> +#include <stdint.h> +#include <arpa/inet.h> + +const char *nft_family2str(uint32_t family) +{ + switch (family) { + case AF_INET: + return "ip"; + case AF_INET6: + return "ip6"; + case AF_BRIDGE: + return "bridge"; + case 0: + return "arp"; + default: + return "unknown"; + } +} + +int nft_str2family(const char *family) +{ + if (strcmp(family, "ip") == 0) + return AF_INET; + else if (strcmp(family, "ip6") == 0) + return AF_INET6; + else if (strcmp(family, "bridge") == 0) + return AF_BRIDGE; + else if (strcmp(family, "arp") == 0) + return 0; + + return -1; +} |