GCC Code Coverage Report


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

Line Branch Exec Source
1 /* gcc nft-buffer.c -o nft-buffer -lnftables */
2 #include <stdlib.h>
3 #include <nftables/libnftables.h>
4
5 const char ruleset[] =
6 "flush ruleset;"
7 "add table x;"
8 "add chain x y { type filter hook input priority 0; };"
9 "add rule x y counter;";
10
11 ✗ int main(void)
12 {
13 struct nft_ctx *ctx;
14 int err;
15
16 ✗ ctx = nft_ctx_new(0);
17 ✗ if (!ctx) {
18 ✗ perror("cannot allocate nft context");
19 ✗ return EXIT_FAILURE;
20 }
21
22 /* create ruleset: all commands in the buffer are atomically applied */
23 ✗ err = nft_run_cmd_from_buffer(ctx, ruleset);
24 ✗ if (err < 0)
25 ✗ fprintf(stderr, "failed to run nftables command\n");
26
27 ✗ err = nft_run_cmd_from_buffer(ctx, "list ruleset");
28 ✗ if (err < 0)
29 ✗ fprintf(stderr, "failed to run nftables command\n");
30
31 ✗ nft_ctx_free(ctx);
32
33 ✗ return EXIT_SUCCESS;
34 }
35