GCC Code Coverage Report


Directory: ./
File: examples/nft-json-file.c
Date: 2026-01-20 23:48:36
Exec Total Coverage
Lines: 0 14 0.0%
Functions: 0 1 0.0%
Branches: 0 6 0.0%

Line Branch Exec Source
1 /* gcc nft-json-file.c -o nft-json-file -lnftables */
2 #include <stdlib.h>
3 #include <nftables/libnftables.h>
4
5 ✗ int main(void)
6 {
7 struct nft_ctx *ctx;
8 int err;
9
10 ✗ ctx = nft_ctx_new(0);
11 ✗ if (!ctx) {
12 ✗ perror("cannot allocate nft context");
13 ✗ return EXIT_FAILURE;
14 }
15
16 ✗ nft_ctx_output_set_flags(ctx, NFT_CTX_OUTPUT_JSON);
17
18 /* create ruleset: all commands in the buffer are atomically applied */
19 ✗ err = nft_run_cmd_from_filename(ctx, "json-ruleset.nft");
20 ✗ if (err < 0)
21 ✗ fprintf(stderr, "failed to run nftables command\n");
22
23 ✗ err = nft_run_cmd_from_buffer(ctx, "list ruleset");
24 ✗ if (err < 0)
25 ✗ fprintf(stderr, "failed to run nftables command\n");
26
27 ✗ nft_ctx_free(ctx);
28
29 ✗ return EXIT_SUCCESS;
30 }
31