From 8e7acbfae3017cd5f30e3b17ca16354f76b81b8a Mon Sep 17 00:00:00 2001 From: Arturo Borrero Date: Thu, 27 Jun 2013 18:56:38 +0200 Subject: 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 Signed-off-by: Pablo Neira Ayuso --- src/utils.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/utils.c (limited to 'src/utils.c') 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 + * (C) 2013 by Arturo Borrero Gonzalez + * + * 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 +#include +#include +#include +#include +#include + +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; +} -- cgit v1.2.3