diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2008-09-28 22:46:15 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2008-09-28 22:46:15 +0200 |
commit | 1c2772d3e5f77022649410d9f5787221cc38573f (patch) | |
tree | 120c1a598ef5b8f5a4c56487839d2ace1fa42f46 | |
parent | 7a399ccded7086436dff2b55e6461b520cc952f6 (diff) | |
download | conntrack-tools-1c2772d3e5f77022649410d9f5787221cc38573f.tar.gz conntrack-tools-1c2772d3e5f77022649410d9f5787221cc38573f.zip |
conntrack: cleanup XML header handling
This patch removes the use of snprintf and directly print the XML header
to the standard output. This simplifies the handling.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r-- | include/conntrack.h | 6 | ||||
-rw-r--r-- | src/conntrack.c | 28 |
2 files changed, 6 insertions, 28 deletions
diff --git a/include/conntrack.h b/include/conntrack.h index e8059c8..69c2317 100644 --- a/include/conntrack.h +++ b/include/conntrack.h @@ -192,10 +192,4 @@ extern void register_udp(void); extern void register_icmp(void); extern void register_icmpv6(void); -#define BUFFER_SIZE(ret, len, offset) \ - if (ret > len) \ - ret = len; \ - offset += ret; \ - len -= ret; - #endif diff --git a/src/conntrack.c b/src/conntrack.c index 568307a..f7b9363 100644 --- a/src/conntrack.c +++ b/src/conntrack.c @@ -627,7 +627,6 @@ static int event_cb(enum nf_conntrack_msg_type type, void *data) { char buf[1024]; - int ret, offset = 0, len = sizeof(buf); struct nf_conntrack *obj = data; unsigned int op_type = NFCT_O_DEFAULT; unsigned int op_flags = 0; @@ -642,15 +641,8 @@ static int event_cb(enum nf_conntrack_msg_type type, op_type = NFCT_O_XML; if (dump_xml_header_done) { dump_xml_header_done = 0; - ret = snprintf(buf, len, "<?xml version=\"1.0\" " - "encoding=\"utf-8\"?>\n" - "<conntrack>\n"); - if (ret == -1) { - fprintf(stderr, "evil! snprintf fails\n"); - return NFCT_CB_CONTINUE; - } - - BUFFER_SIZE(ret, len, offset); + printf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<conntrack>\n"); } } if (output_mask & _O_EXT) @@ -666,7 +658,7 @@ static int event_cb(enum nf_conntrack_msg_type type, if (output_mask & _O_ID) op_flags |= NFCT_OF_ID; - nfct_snprintf(buf+offset, len, ct, type, op_type, op_flags); + nfct_snprintf(buf, sizeof(buf), ct, type, op_type, op_flags); printf("%s\n", buf); fflush(stdout); @@ -681,7 +673,6 @@ static int dump_cb(enum nf_conntrack_msg_type type, void *data) { char buf[1024]; - int ret, offset = 0, len = sizeof(buf); struct nf_conntrack *obj = data; unsigned int op_type = NFCT_O_DEFAULT; unsigned int op_flags = 0; @@ -696,15 +687,8 @@ static int dump_cb(enum nf_conntrack_msg_type type, op_type = NFCT_O_XML; if (dump_xml_header_done) { dump_xml_header_done = 0; - ret = snprintf(buf, len, "<?xml version=\"1.0\" " - "encoding=\"utf-8\"?>\n" - "<conntrack>\n"); - if (ret == -1) { - fprintf(stderr, "evil! snprintf fails\n"); - return NFCT_CB_CONTINUE; - } - - BUFFER_SIZE(ret, len, offset); + printf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<conntrack>\n"); } } if (output_mask & _O_EXT) @@ -712,7 +696,7 @@ static int dump_cb(enum nf_conntrack_msg_type type, if (output_mask & _O_ID) op_flags |= NFCT_OF_ID; - nfct_snprintf(buf+offset, len, ct, NFCT_T_UNKNOWN, op_type, op_flags); + nfct_snprintf(buf, sizeof(buf), ct, NFCT_T_UNKNOWN, op_type, op_flags); printf("%s\n", buf); counter++; |