From bd28075ee0bf121ef4fe50e34146efe14acee07b Mon Sep 17 00:00:00 2001 From: Arturo Borrero Date: Tue, 29 Oct 2013 23:44:25 +0100 Subject: src: add fprintf API functions Now it's possible to print directly from libnftables to a file or other stream. The caller must explicitly print the trailing '\n' in this call. The error reporting of fprintf (< 0) is respected. However, we have already print some information in case that the default (plain text) output is used, that output is mostly intended for debugging so it should not be a problem. Signed-off-by: Arturo Borrero Gonzalez Signed-off-by: Pablo Neira Ayuso --- include/libnftables/chain.h | 2 ++ include/libnftables/rule.h | 2 ++ include/libnftables/ruleset.h | 3 +++ include/libnftables/set.h | 3 +++ include/libnftables/table.h | 2 ++ 5 files changed, 12 insertions(+) (limited to 'include/libnftables') diff --git a/include/libnftables/chain.h b/include/libnftables/chain.h index d85a2a2..66f19c0 100644 --- a/include/libnftables/chain.h +++ b/include/libnftables/chain.h @@ -1,6 +1,7 @@ #ifndef _CHAIN_H_ #define _CHAIN_H_ +#include #include #include @@ -60,6 +61,7 @@ enum nft_chain_parse_type { int nft_chain_parse(struct nft_chain *c, enum nft_chain_parse_type type, const char *data); int nft_chain_snprintf(char *buf, size_t size, struct nft_chain *t, uint32_t type, uint32_t flags); +int nft_chain_fprintf(FILE *fp, struct nft_chain *c, uint32_t type, uint32_t flags); struct nlmsghdr *nft_chain_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family, uint16_t type, uint32_t seq); int nft_chain_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_chain *t); diff --git a/include/libnftables/rule.h b/include/libnftables/rule.h index a501d2d..cdbd8d2 100644 --- a/include/libnftables/rule.h +++ b/include/libnftables/rule.h @@ -1,6 +1,7 @@ #ifndef _RULE_H_ #define _RULE_H_ +#include #include #include @@ -58,6 +59,7 @@ enum nft_rule_parse_type { int nft_rule_parse(struct nft_rule *r, enum nft_rule_parse_type type, const char *data); int nft_rule_snprintf(char *buf, size_t size, struct nft_rule *t, uint32_t type, uint32_t flags); +int nft_rule_fprintf(FILE *fp, struct nft_rule *r, uint32_t type, uint32_t flags); struct nlmsghdr *nft_rule_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family, uint16_t type, uint32_t seq); int nft_rule_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_rule *t); diff --git a/include/libnftables/ruleset.h b/include/libnftables/ruleset.h index a4a1279..35e4d71 100644 --- a/include/libnftables/ruleset.h +++ b/include/libnftables/ruleset.h @@ -1,6 +1,8 @@ #ifndef _RULESET_H_ #define _RULESET_H_ +#include + #ifdef __cplusplus extern "C" { #endif @@ -37,6 +39,7 @@ enum nft_ruleset_parse_type { int nft_ruleset_parse(struct nft_ruleset *rs, enum nft_ruleset_parse_type type, const char *data); int nft_ruleset_snprintf(char *buf, size_t size, const struct nft_ruleset *rs, uint32_t type, uint32_t flags); +int nft_ruleset_fprintf(FILE *fp, const struct nft_ruleset *rs, uint32_t type, uint32_t flags); #ifdef __cplusplus } /* extern "C" */ diff --git a/include/libnftables/set.h b/include/libnftables/set.h index 14a6327..a087009 100644 --- a/include/libnftables/set.h +++ b/include/libnftables/set.h @@ -1,6 +1,7 @@ #ifndef _NFT_SET_H_ #define _NFT_SET_H_ +#include #include #include @@ -38,6 +39,7 @@ int nft_set_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_set *s); int nft_set_elems_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_set *s); int nft_set_snprintf(char *buf, size_t size, struct nft_set *s, uint32_t type, uint32_t flags); +int nft_set_fprintf(FILE *fp, struct nft_set *s, uint32_t type, uint32_t flags); struct nft_set_list; @@ -108,6 +110,7 @@ int nft_set_elem_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_set_elem *s) int nft_set_elem_parse(struct nft_set_elem *e, enum nft_set_parse_type type, const char *data); int nft_set_elem_snprintf(char *buf, size_t size, struct nft_set_elem *s, uint32_t type, uint32_t flags); +int nft_set_elem_fprintf(FILE *fp, struct nft_set_elem *se, uint32_t type, uint32_t flags); int nft_set_elem_foreach(struct nft_set *s, int (*cb)(struct nft_set_elem *e, void *data), void *data); diff --git a/include/libnftables/table.h b/include/libnftables/table.h index 42a4aa7..4a323bd 100644 --- a/include/libnftables/table.h +++ b/include/libnftables/table.h @@ -1,6 +1,7 @@ #ifndef _TABLE_H_ #define _TABLE_H_ +#include #include #include @@ -48,6 +49,7 @@ enum nft_table_parse_type { int nft_table_parse(struct nft_table *t, enum nft_table_parse_type type, const char *data); int nft_table_snprintf(char *buf, size_t size, struct nft_table *t, uint32_t type, uint32_t flags); +int nft_table_fprintf(FILE *fp, struct nft_table *t, uint32_t type, uint32_t flags); struct nlmsghdr *nft_table_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family, uint16_t type, uint32_t seq); int nft_table_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_table *t); -- cgit v1.2.3