summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorArturo Borrero <arturo.borrero.glez@gmail.com>2014-04-15 20:13:31 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2014-04-26 14:07:01 +0200
commitd42c8b2cb99800d519032eb43fce765c7c776e25 (patch)
tree9ea492ffede0efbba1deb13a43d24f4dd098eba8 /examples
parent612698d4cedb3fbc2a02480c05b9a9d8cb13d3a8 (diff)
examples: nft-events: use new events wrappers
Let's use the new event wrappers in the events example. Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'examples')
-rw-r--r--examples/nft-events.c46
1 files changed, 31 insertions, 15 deletions
diff --git a/examples/nft-events.c b/examples/nft-events.c
index 989f4bd..fc63650 100644
--- a/examples/nft-events.c
+++ b/examples/nft-events.c
@@ -22,11 +22,31 @@
#include <libnftnl/chain.h>
#include <libnftnl/rule.h>
#include <libnftnl/set.h>
+#include <libnftnl/common.h>
+
+static uint32_t event2flag(uint32_t event)
+{
+ switch (event) {
+ case NFT_MSG_NEWTABLE:
+ case NFT_MSG_NEWCHAIN:
+ case NFT_MSG_NEWRULE:
+ case NFT_MSG_NEWSET:
+ case NFT_MSG_NEWSETELEM:
+ return NFT_OF_EVENT_NEW;
+ case NFT_MSG_DELTABLE:
+ case NFT_MSG_DELCHAIN:
+ case NFT_MSG_DELRULE:
+ case NFT_MSG_DELSET:
+ case NFT_MSG_DELSETELEM:
+ return NFT_OF_EVENT_DEL;
+ }
+
+ return 0;
+}
static int table_cb(const struct nlmsghdr *nlh, int type)
{
struct nft_table *t;
- char buf[4096];
t = nft_table_alloc();
if (t == NULL) {
@@ -39,8 +59,8 @@ static int table_cb(const struct nlmsghdr *nlh, int type)
goto err_free;
}
- nft_table_snprintf(buf, sizeof(buf), t, NFT_OUTPUT_DEFAULT, 0);
- printf("[%s]\t%s\n", type == NFT_MSG_NEWTABLE ? "NEW" : "DEL", buf);
+ nft_table_fprintf(stdout, t, NFT_OUTPUT_DEFAULT, event2flag(type));
+ fprintf(stdout, "\n");
err_free:
nft_table_free(t);
@@ -51,7 +71,6 @@ err:
static int rule_cb(const struct nlmsghdr *nlh, int type)
{
struct nft_rule *t;
- char buf[4096];
t = nft_rule_alloc();
if (t == NULL) {
@@ -64,8 +83,8 @@ static int rule_cb(const struct nlmsghdr *nlh, int type)
goto err_free;
}
- nft_rule_snprintf(buf, sizeof(buf), t, NFT_OUTPUT_DEFAULT, 0);
- printf("[%s]\t%s\n", type == NFT_MSG_NEWRULE ? "NEW" : "DEL", buf);
+ nft_rule_fprintf(stdout, t, NFT_OUTPUT_DEFAULT, event2flag(type));
+ fprintf(stdout, "\n");
err_free:
nft_rule_free(t);
@@ -76,7 +95,6 @@ err:
static int chain_cb(const struct nlmsghdr *nlh, int type)
{
struct nft_chain *t;
- char buf[4096];
t = nft_chain_alloc();
if (t == NULL) {
@@ -89,8 +107,8 @@ static int chain_cb(const struct nlmsghdr *nlh, int type)
goto err_free;
}
- nft_chain_snprintf(buf, sizeof(buf), t, NFT_OUTPUT_DEFAULT, 0);
- printf("[%s]\t%s\n", type == NFT_MSG_NEWCHAIN ? "NEW" : "DEL", buf);
+ nft_chain_fprintf(stdout, t, NFT_OUTPUT_DEFAULT, event2flag(type));
+ fprintf(stdout, "\n");
err_free:
nft_chain_free(t);
@@ -101,7 +119,6 @@ err:
static int set_cb(const struct nlmsghdr *nlh, int type)
{
struct nft_set *t;
- char buf[4096];
t = nft_set_alloc();
if (t == NULL) {
@@ -114,8 +131,8 @@ static int set_cb(const struct nlmsghdr *nlh, int type)
goto err_free;
}
- nft_set_snprintf(buf, sizeof(buf), t, NFT_OUTPUT_DEFAULT, 0);
- printf("[%s]\t%s\n", type == NFT_MSG_NEWSET ? "NEW" : "DEL", buf);
+ nft_set_fprintf(stdout, t, NFT_OUTPUT_DEFAULT, event2flag(type));
+ fprintf(stdout, "\n");
err_free:
nft_set_free(t);
@@ -127,7 +144,6 @@ static int setelem_cb(const struct nlmsghdr *nlh, int type)
{
struct nft_set *s;
- char buf[4096];
s = nft_set_alloc();
if (s == NULL) {
@@ -140,8 +156,8 @@ static int setelem_cb(const struct nlmsghdr *nlh, int type)
goto err_free;
}
- nft_set_snprintf(buf, sizeof(buf), s, NFT_OUTPUT_DEFAULT, 0);
- printf("[%s]\t%s\n", type == NFT_MSG_NEWSETELEM ? "NEW" : "DEL", buf);
+ nft_set_fprintf(stdout, s, NFT_OUTPUT_DEFAULT, event2flag(type));
+ fprintf(stdout, "\n");
err_free:
nft_set_free(s);