diff options
author | Phil Sutter <phil@nwl.cc> | 2023-04-21 15:53:43 +0200 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2023-04-21 18:03:13 +0200 |
commit | a591f48302e459d079e052b423885ae5eef4fa63 (patch) | |
tree | 0a081c72756c877965c9d84503af88e3f5d09f24 /utils | |
parent | 0c2dcbf984939d8473e0b429b41e41a36c8a64da (diff) |
utils: nfbpf_compile: Replace pcap_compile_nopcap()
The function is deprecated. Eliminate the warning by use of
pcap_open_dead(), pcap_compile() and pcap_close() just how
pcap_compile_nopcap() is implemented internally in libpcap.
Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'utils')
-rw-r--r-- | utils/nfbpf_compile.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/utils/nfbpf_compile.c b/utils/nfbpf_compile.c index 2c46c7b0..c9e763dc 100644 --- a/utils/nfbpf_compile.c +++ b/utils/nfbpf_compile.c @@ -17,6 +17,7 @@ int main(int argc, char **argv) struct bpf_program program; struct bpf_insn *ins; int i, dlt = DLT_RAW; + pcap_t *pcap; if (argc < 2 || argc > 3) { fprintf(stderr, "Usage: %s [link] '<program>'\n\n" @@ -36,9 +37,15 @@ int main(int argc, char **argv) } } - if (pcap_compile_nopcap(65535, dlt, &program, argv[argc - 1], 1, + pcap = pcap_open_dead(dlt, 65535); + if (!pcap) { + fprintf(stderr, "Memory allocation failure\n"); + return 1; + } + if (pcap_compile(pcap, &program, argv[argc - 1], 1, PCAP_NETMASK_UNKNOWN)) { fprintf(stderr, "Compilation error\n"); + pcap_close(pcap); return 1; } @@ -50,6 +57,7 @@ int main(int argc, char **argv) printf("%u %u %u %u\n", ins->code, ins->jt, ins->jf, ins->k); pcap_freecode(&program); + pcap_close(pcap); return 0; } |