]> The Tcpdump Group git mirrors - libpcap/commitdiff
Initialize snaplen.
authorGuy Harris <[email protected]>
Fri, 3 Jul 2020 12:33:46 +0000 (05:33 -0700)
committerGuy Harris <[email protected]>
Fri, 3 Jul 2020 12:33:46 +0000 (05:33 -0700)
That shouldn't be necessary, but it avoids compiler warnings with older
versions of Visual Studio.

pcap-npf.c
testprogs/writecaptest.c

index 2c7fd9f5f0589fa81bbed2fd0fb0eaeba535b66c..06f6bba0eb15c009cbee733490e9126b53371ed2 100644 (file)
@@ -908,6 +908,8 @@ pcap_activate_npf(pcap_t *p)
        NetType type;
        int res;
        int status = 0;
+       struct bpf_insn total_insn;
+       struct bpf_program total_prog;
 
        if (p->opt.rfmon) {
                /*
@@ -1231,6 +1233,29 @@ pcap_activate_npf(pcap_t *p)
 #endif /* HAVE_DAG_API */
        }
 
+       /*
+        * If there's no filter program installed, there's
+        * no indication to the kernel of what the snapshot
+        * length should be, so no snapshotting is done.
+        *
+        * Therefore, when we open the device, we install
+        * an "accept everything" filter with the specified
+        * snapshot length.
+        */
+       total_insn.code = (u_short)(BPF_RET | BPF_K);
+       total_insn.jt = 0;
+       total_insn.jf = 0;
+       total_insn.k = p->snapshot;
+
+       total_prog.bf_len = 1;
+       total_prog.bf_insns = &total_insn;
+       if (!PacketSetBpf(pw->adapter, &total_prog)) {
+               pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
+                   GetLastError(), "PacketSetBpf");
+               status = PCAP_ERROR;
+               goto bad;
+       }
+
        PacketSetReadTimeout(pw->adapter, p->opt.timeout);
 
        /* disable loopback capture if requested */
index 7d3177323bb981ee32d546fc23ae025503e043c0..38e2b4a1c28102cfe4d5633655bb08b212ab6abc 100644 (file)
@@ -83,7 +83,7 @@ main(int argc, char **argv)
 {
        int op;
        char *cp, *cmdbuf = NULL, *device, *end, *savefile = NULL;
-       int snaplen;
+       int snaplen = 0;
        int snaplen_set = 0;
        pcap_if_t *devlist;
        int show_dlt_types = 0;