]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
utils: nfbpf_compile: Replace pcap_compile_nopcap()
authorPhil Sutter <phil@nwl.cc>
Fri, 21 Apr 2023 13:53:43 +0000 (15:53 +0200)
committerPhil Sutter <phil@nwl.cc>
Fri, 21 Apr 2023 16:03:13 +0000 (18:03 +0200)
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>
utils/nfbpf_compile.c

index 2c46c7b026cc833fe33b99cb4cc557d689a93308..c9e763dcf144c24fcf68551cd26e81fe5157176e 100644 (file)
@@ -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;
 }