| 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 |