From 2535ba7006f22a6470f4c88ea7d30c343a1d8799 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 28 Sep 2017 17:17:45 +0200 Subject: src: get rid of printf This patch introduces nft_print()/nft_gmp_print() functions which have to be used instead of printf to output information that were previously send to stdout. These functions print to a FILE pointer defined in struct output_ctx. It is set by calling: | old_fp = nft_ctx_set_output(ctx, new_fp); Having an application-defined FILE pointer is actually quite flexible: Using fmemopen() or even fopencookie(), an application gains full control over what is printed and where it should go to. Signed-off-by: Eric Leblond Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- src/exthdr.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/exthdr.c') diff --git a/src/exthdr.c b/src/exthdr.c index 37c76884..ac3e1632 100644 --- a/src/exthdr.c +++ b/src/exthdr.c @@ -32,18 +32,19 @@ static void exthdr_expr_print(const struct expr *expr, struct output_ctx *octx) */ unsigned int offset = expr->exthdr.offset / 64; - printf("tcp option %s", expr->exthdr.desc->name); + nft_print(octx, "tcp option %s", expr->exthdr.desc->name); if (expr->exthdr.flags & NFT_EXTHDR_F_PRESENT) return; if (offset) - printf("%d", offset); - printf(" %s", expr->exthdr.tmpl->token); + nft_print(octx, "%d", offset); + nft_print(octx, " %s", expr->exthdr.tmpl->token); } else { if (expr->exthdr.flags & NFT_EXTHDR_F_PRESENT) - printf("exthdr %s", expr->exthdr.desc->name); + nft_print(octx, "exthdr %s", expr->exthdr.desc->name); else { - printf("%s %s", expr->exthdr.desc ? expr->exthdr.desc->name : "unknown-exthdr", - expr->exthdr.tmpl->token); + nft_print(octx, "%s %s", + expr->exthdr.desc ? expr->exthdr.desc->name : "unknown-exthdr", + expr->exthdr.tmpl->token); } } } @@ -98,7 +99,7 @@ struct expr *exthdr_expr_alloc(const struct location *loc, static void exthdr_stmt_print(const struct stmt *stmt, struct output_ctx *octx) { expr_print(stmt->exthdr.expr, octx); - printf(" set "); + nft_print(octx, " set "); expr_print(stmt->exthdr.val, octx); } -- cgit v1.2.3