]> The Tcpdump Group git mirrors - libpcap/commitdiff
Clean up the declaration of the packet-filtering routines.
authorGuy Harris <[email protected]>
Sat, 1 Sep 2018 03:08:50 +0000 (20:08 -0700)
committerGuy Harris <[email protected]>
Sat, 1 Sep 2018 03:08:50 +0000 (20:08 -0700)
If net/bpf.h declares bpf_filter() one way and libpcap defines it
another way, even pcap-bpf.c needs a declaration that matches how
libpcap defines it, not how net/bpf.h (mistakenly) declares it.
("Mistakenly" because it should *not* be declaring the kernel's version
of bpf_filter() unless it's being used in a *kernel* build; other *BSDs,
and macOS, declare it only in kernel builds by testing for a #define
such as KERNEL or KERNEL_PRIVATE, but NetBSD doesn't - it *should*, but
it doesn't.)

So we rename the internal-to-pcap filtering routine as pcap_filter(),
which is not exported from libpcap, and have bpf_filter() be a wrapper
around pcap_filter() that is exported.

Use pcap_filter(), rather than bpf_filter(), for all filtering inside
libpcap (except for filtering that uses bpf_filter_with_aux_data(),
which we rename pcap_filter_with_aux_data()).

Do the same for bpf_validate(), which is *also* declared in net/bpf.h,
even for non-kernel builds, in NetBSD.

As we're not exporting pcap_filter_with_aux_data(), don't even *declare*
it in a public header; don't declare struct bpf_aux_data in a public
header, either.  That way we can change it without worrying about
breaking APIs or ABIs; we may do that if, for example, we want to
support the "inbound" and "outbound" filters when reading pcapng files,
adding a direction indicator to that structure.

Declare bpf_filter() in pcap/bpf.h even on NetBSD and QNX; pcap-bpf.c
doesn't include pcap/bpf.h (it sets a #define to force pcap/pcap.h not
to include it), so we won't get any collisions if net/bpf.h (which it
does include) declares it.  The only collisions will occur in programs
that include *both* pcap/pcap.h or pcap/bpf.h *and* net/bpf.h, and that
will occur only if net/bpf.h declares bpf_filter() even when building
userland code, and the correct fix for *that* is to fix net/bpf.h not to
declare them in non-kernel builds.

28 files changed:
bpf_filter.c
dlpisubs.c
optimize.c
pcap-bpf.c
pcap-bt-linux.c
pcap-bt-monitor-linux.c
pcap-dag.c
pcap-dbus.c
pcap-dos.c
pcap-enet.c
pcap-int.h
pcap-linux.c
pcap-netfilter-linux.c
pcap-netmap.c
pcap-nit.c
pcap-npf.c
pcap-pf.c
pcap-rdmasniff.c
pcap-septel.c
pcap-snf.c
pcap-snit.c
pcap-snoop.c
pcap-tc.c
pcap-usb-linux.c
pcap.c
pcap/bpf.h
savefile.c
testprogs/filtertest.c

index 93c337643ee8baf327202fd481c484a8a198562f..e5c286b58c4573e8f9fa978399ea8c7420fb3057 100644 (file)
@@ -85,11 +85,11 @@ enum {
  */
 #if defined(SKF_AD_VLAN_TAG_PRESENT)
 u_int
-bpf_filter_with_aux_data(const struct bpf_insn *pc, const u_char *p,
+pcap_filter_with_aux_data(const struct bpf_insn *pc, const u_char *p,
     u_int wirelen, u_int buflen, const struct bpf_aux_data *aux_data)
 #else
 u_int
-bpf_filter_with_aux_data(const struct bpf_insn *pc, const u_char *p,
+pcap_filter_with_aux_data(const struct bpf_insn *pc, const u_char *p,
     u_int wirelen, u_int buflen, const struct bpf_aux_data *aux_data _U_)
 #endif
 {
@@ -370,10 +370,10 @@ bpf_filter_with_aux_data(const struct bpf_insn *pc, const u_char *p,
 }
 
 u_int
-bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
+pcap_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
     u_int buflen)
 {
-       return bpf_filter_with_aux_data(pc, p, wirelen, buflen, NULL);
+       return pcap_filter_with_aux_data(pc, p, wirelen, buflen, NULL);
 }
 
 /*
@@ -388,7 +388,7 @@ bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
  * Otherwise, a bogus program could easily crash the system.
  */
 int
-bpf_validate(const struct bpf_insn *f, int len)
+pcap_validate_filter(const struct bpf_insn *f, int len)
 {
        u_int i, from;
        const struct bpf_insn *p;
@@ -510,3 +510,19 @@ bpf_validate(const struct bpf_insn *f, int len)
        }
        return BPF_CLASS(f[len - 1].code) == BPF_RET;
 }
+
+/*
+ * Exported because older versions of libpcap exported them.
+ */
+u_int
+bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
+    u_int buflen)
+{
+       return pcap_filter(pc, p, wirelen, buflen);
+}
+
+int
+bpf_validate(const struct bpf_insn *f, int len)
+{
+       return pcap_validate_filter(f, len);
+}
index a049ef87e1c7ae83114012282e212830b7bdcbd0..b39c3d341982efe9852ec72aa6ba5413b0f3852d 100644 (file)
@@ -190,7 +190,7 @@ pcap_process_pkts(pcap_t *p, pcap_handler callback, u_char *user,
                bufp += caplen;
 #endif
                ++pd->stat.ps_recv;
-               if (bpf_filter(p->fcode.bf_insns, pk, origlen, caplen)) {
+               if (pcap_filter(p->fcode.bf_insns, pk, origlen, caplen)) {
 #ifdef HAVE_SYS_BUFMOD_H
                        pkthdr.ts.tv_sec = sbp->sbh_timestamp.tv_sec;
                        pkthdr.ts.tv_usec = sbp->sbh_timestamp.tv_usec;
index 947a39933f669aa91ecbb30c1b73b0436067375f..fa8e0ac1feb2bd1008496eb22b57a80c9767a63b 100644 (file)
@@ -2359,7 +2359,7 @@ install_bpf_program(pcap_t *p, struct bpf_program *fp)
        /*
         * Validate the program.
         */
-       if (!bpf_validate(fp->bf_insns, fp->bf_len)) {
+       if (!pcap_validate_filter(fp->bf_insns, fp->bf_len)) {
                pcap_snprintf(p->errbuf, sizeof(p->errbuf),
                        "BPF program is not valid");
                return (-1);
index 6ce383b0f605b9576f3fea04c5309fcbaef12961..5e9f68992eede21a475dc5eec487d8c13e176120 100644 (file)
@@ -1116,7 +1116,7 @@ pcap_read_bpf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
 #endif
                 */
                if (pb->filtering_in_kernel ||
-                   bpf_filter(p->fcode.bf_insns, datap, bhp->bh_datalen, caplen)) {
+                   pcap_filter(p->fcode.bf_insns, datap, bhp->bh_datalen, caplen)) {
                        struct pcap_pkthdr pkthdr;
 #ifdef BIOCSTSTAMP
                        struct bintime bt;
index 15c2c1c520c7c5ee89aa89f4e47cced53f05c84b..0c21d9c1a196a144bb06c85709c71e8015ea34b3 100644 (file)
@@ -370,7 +370,7 @@ bt_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char
        pkth.caplen+=sizeof(pcap_bluetooth_h4_header);
        pkth.len = pkth.caplen;
        if (handle->fcode.bf_insns == NULL ||
-           bpf_filter(handle->fcode.bf_insns, pktd, pkth.len, pkth.caplen)) {
+           pcap_filter(handle->fcode.bf_insns, pktd, pkth.len, pkth.caplen)) {
                callback(user, &pkth, pktd);
                return 1;
        }
index c222c100edb23f86cda3e93265a5451a72cafb0e..4f12712753baa8c271b8eb3302f1785a1f7ab8a3 100644 (file)
@@ -139,7 +139,7 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch
     bthdr->opcode = htons(hdr.opcode);
 
     if (handle->fcode.bf_insns == NULL ||
-        bpf_filter(handle->fcode.bf_insns, pktd, pkth.len, pkth.caplen)) {
+        pcap_filter(handle->fcode.bf_insns, pktd, pkth.len, pkth.caplen)) {
         callback(user, &pkth, pktd);
         return 1;
     }
index 30983a693e1c1de23b1df813753ebf8dcc43755c..be784b46011dad7491d72a0559d9a021f8360cc9 100644 (file)
@@ -672,7 +672,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
                        caplen = p->snapshot;
 
                /* Run the packet filter if there is one. */
-               if ((p->fcode.bf_insns == NULL) || bpf_filter(p->fcode.bf_insns, dp, packet_len, caplen)) {
+               if ((p->fcode.bf_insns == NULL) || pcap_filter(p->fcode.bf_insns, dp, packet_len, caplen)) {
 
                        /* convert between timestamp formats */
                        register unsigned long long ts;
index 1252975e9ac7b31d71cf6270b98fcd8a25cbf8b6..9f426e671bb0fd1d1473e4734e4281ed85a81798 100644 (file)
@@ -91,7 +91,7 @@ dbus_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char *us
 
                gettimeofday(&pkth.ts, NULL);
                if (handle->fcode.bf_insns == NULL ||
-                   bpf_filter(handle->fcode.bf_insns, (u_char *)raw_msg, pkth.len, pkth.caplen)) {
+                   pcap_filter(handle->fcode.bf_insns, (u_char *)raw_msg, pkth.len, pkth.caplen)) {
                        handlep->packets_read++;
                        callback(user, &pkth, (u_char *)raw_msg);
                        count++;
index b1b9ecd72b16ef5967d3b42769fb7a1452768174..aafba0c6fceb24dcea9dc4d623beafaa09f57079 100644 (file)
@@ -283,7 +283,7 @@ pcap_read_one (pcap_t *p, pcap_handler callback, u_char *data)
       pcap.len    = rx_len;
 
       if (callback &&
-          (!p->fcode.bf_insns || bpf_filter(p->fcode.bf_insns, p->buffer, pcap.len, pcap.caplen)))
+          (!p->fcode.bf_insns || pcap_filter(p->fcode.bf_insns, p->buffer, pcap.len, pcap.caplen)))
       {
         filter_count++;
 
index cd8cdbbb78b4502b3157ad530412725bfd841a8c..6f0512f3594700a9beb01a811a41e33ed7d9ebf9 100644 (file)
@@ -75,7 +75,7 @@ readloop(int cnt, int if_fd, struct bpf_program *fp, printfunc printit)
                        ph = (struct packet_header *)bp;
                        caplen = ph->tap.th_wirelen > snaplen ? snaplen : ph->tap
 .th_wirelen ;
-                       if (bpf_filter(fcode, (char *)ph->packet,
+                       if (pcap_filter(fcode, (char *)ph->packet,
                                                ph->tap.th_wirelen, caplen)) {
                                if (cnt >= 0 && --cnt < 0)
                                        goto out;
@@ -89,7 +89,7 @@ readloop(int cnt, int if_fd, struct bpf_program *fp, printfunc printit)
                }
 #else  /* !IBMRTPC */
                caplen = cc > snaplen ? snaplen : cc ;
-               if (bpf_filter(fcode, buf.hdr.packet, cc, caplen)) {
+               if (pcap_filter(fcode, buf.hdr.packet, cc, caplen)) {
                        if (cnt >= 0 && --cnt < 0)
                                goto out;
                        (*printit)(buf.hdr.packet, &tv, cc, caplen);
index 9fbc6fb202ac0c1226d1cba19e2250fd8a15e28a..2426ab107d3b295e004d570b7bfc259218218325 100644 (file)
@@ -496,9 +496,19 @@ struct bpf_aux_data {
  * Filtering routine that takes the auxiliary data as an additional
  * argument.
  */
-u_int  bpf_filter_with_aux_data(const struct bpf_insn *,
+u_int  pcap_filter_with_aux_data(const struct bpf_insn *,
     const u_char *, u_int, u_int, const struct bpf_aux_data *);
 
+/*
+ * Filtering routine that doesn't.
+ */
+u_int  pcap_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
+
+/*
+ * Routine to validate a BPF program.
+ */
+int    pcap_validate_filter(const struct bpf_insn *, int);
+
 /*
  * Internal interfaces for both "pcap_create()" and routines that
  * open savefiles.
index 759440de1226ae38edab8e60b442f0a628d46896..54592e668fa04fc99aa7ffe9239d3e218f67a25e 100644 (file)
@@ -2045,7 +2045,7 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata)
 
        /* Run the packet filter if not using kernel filter */
        if (handlep->filter_in_userland && handle->fcode.bf_insns) {
-               if (bpf_filter_with_aux_data(handle->fcode.bf_insns, bp,
+               if (pcap_filter_with_aux_data(handle->fcode.bf_insns, bp,
                    packet_len, caplen, &aux_data) == 0) {
                        /* rejected by filter */
                        return 0;
@@ -5143,11 +5143,11 @@ static int pcap_handle_packet_mmap(
                aux_data.vlan_tag_present = tp_vlan_tci_valid;
                aux_data.vlan_tag = tp_vlan_tci & 0x0fff;
 
-               if (bpf_filter_with_aux_data(handle->fcode.bf_insns,
-                                            bp,
-                                            tp_len,
-                                            snaplen,
-                                            &aux_data) == 0)
+               if (pcap_filter_with_aux_data(handle->fcode.bf_insns,
+                                             bp,
+                                             tp_len,
+                                             snaplen,
+                                             &aux_data) == 0)
                        return 0;
        }
 
index d5c5dcdc485040adcbdf85805e600801e7092a6d..675df4aede0a26a308c683d9b6d5c42a19cb4444 100644 (file)
@@ -240,7 +240,7 @@ netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_c
 
                                gettimeofday(&pkth.ts, NULL);
                                if (handle->fcode.bf_insns == NULL ||
-                                               bpf_filter(handle->fcode.bf_insns, payload, pkth.len, pkth.caplen))
+                                               pcap_filter(handle->fcode.bf_insns, payload, pkth.len, pkth.caplen))
                                {
                                        handlep->packets_read++;
                                        callback(user, &pkth, payload);
index f1505633fcaa3e97cb56d82aa73da6e7949e2f9c..a577d2c6a716b4bbfcdf5d3ac1200e33bad72fa1 100644 (file)
@@ -82,7 +82,7 @@ pcap_netmap_filter(u_char *arg, struct pcap_pkthdr *h, const u_char *buf)
        const struct bpf_insn *pc = p->fcode.bf_insns;
 
        ++pn->rx_pkts;
-       if (pc == NULL || bpf_filter(pc, buf, h->len, h->caplen))
+       if (pc == NULL || pcap_filter(pc, buf, h->len, h->caplen))
                pn->cb(pn->cb_arg, h, buf);
 }
 
index 6a1a77c24c681585c3d54472839000cc3527a40f..c011a6a536faaf5c1b61af3677357ffe2dac9175 100644 (file)
@@ -179,7 +179,7 @@ pcap_read_nit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
                caplen = nh->nh_wirelen;
                if (caplen > p->snapshot)
                        caplen = p->snapshot;
-               if (bpf_filter(p->fcode.bf_insns, cp, nh->nh_wirelen, caplen)) {
+               if (pcap_filter(p->fcode.bf_insns, cp, nh->nh_wirelen, caplen)) {
                        struct pcap_pkthdr h;
                        h.ts = nh->nh_timestamp;
                        h.len = nh->nh_wirelen;
index a9ff0ff4d7dfc96ecb4d1a394fb9314a3bb9c15e..347c537a8655dcc40ccb7c48ac9283240da4a7ce 100644 (file)
@@ -585,13 +585,13 @@ pcap_read_npf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
                 * in kernel, no need to do it now - we already know
                 * the packet passed the filter.
                 *
-                * XXX - bpf_filter() should always return TRUE if
+                * XXX - pcap_filter() should always return TRUE if
                 * handed a null pointer for the program, but it might
                 * just try to "run" the filter, so we check here.
                 */
                if (pw->filtering_in_kernel ||
                    p->fcode.bf_insns == NULL ||
-                   bpf_filter(p->fcode.bf_insns, datap, bhp->bh_datalen, caplen)) {
+                   pcap_filter(p->fcode.bf_insns, datap, bhp->bh_datalen, caplen)) {
 #ifdef ENABLE_REMOTE
                        switch (p->rmt_samp.method) {
 
@@ -798,7 +798,7 @@ pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
                /* No underlaying filtering system. We need to filter on our own */
                if (p->fcode.bf_insns)
                {
-                       if (bpf_filter(p->fcode.bf_insns, dp, packet_len, caplen) == 0)
+                       if (pcap_filter(p->fcode.bf_insns, dp, packet_len, caplen) == 0)
                        {
                                /* Move to next packet */
                                header = (dag_record_t*)((char*)header + erf_record_len);
index 5cb9433ba83ddba52be66cf1dbeee0cac2f54139..c712460fb8a13b5aaa03fd8f60957d3795d69d78 100644 (file)
--- a/pcap-pf.c
+++ b/pcap-pf.c
@@ -201,7 +201,7 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
                 * skipping that padding.
                 */
                if (pf->filtering_in_kernel ||
-                   bpf_filter(pc->fcode.bf_insns, p, sp->ens_count, buflen)) {
+                   pcap_filter(pc->fcode.bf_insns, p, sp->ens_count, buflen)) {
                        struct pcap_pkthdr h;
                        pf->TotAccepted++;
                        h.ts = sp->ens_tstamp;
index c50fe3fd693f0e2cf6458bf2b0db05b5af12af1b..921e68c6c450b9f35111be0384441ee4f201ea0a 100644 (file)
@@ -156,7 +156,7 @@ rdmasniff_read(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
                pktd = (u_char *) handle->buffer + wc.wr_id * RDMASNIFF_RECEIVE_SIZE;
 
                if (handle->fcode.bf_insns == NULL ||
-                   bpf_filter(handle->fcode.bf_insns, pktd, pkth.len, pkth.caplen)) {
+                   pcap_filter(handle->fcode.bf_insns, pktd, pkth.len, pkth.caplen)) {
                        callback(user, &pkth, pktd);
                        ++priv->packets_recv;
                        ++count;
index 0471153fdc7a6a667fbad8667ecfe50ed9a9cc27..dd03e23e8f25b160dff3333524603c9fee2b1b55 100644 (file)
@@ -135,7 +135,7 @@ loop:
         caplen = packet_len;
       }
       /* Run the packet filter if there is one. */
-      if ((p->fcode.bf_insns == NULL) || bpf_filter(p->fcode.bf_insns, dp, packet_len, caplen)) {
+      if ((p->fcode.bf_insns == NULL) || pcap_filter(p->fcode.bf_insns, dp, packet_len, caplen)) {
 
 
         /*  get a time stamp , consisting of :
index 4eae0b3993161ab6ef6d593010c1125864e44e1d..3d4fea9ffc36fb8f0df7c8f877973fe815494cce 100644 (file)
@@ -177,7 +177,7 @@ snf_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
                        caplen = p->snapshot;
 
                if ((p->fcode.bf_insns == NULL) ||
-                    bpf_filter(p->fcode.bf_insns, req.pkt_addr, req.length, caplen)) {
+                    pcap_filter(p->fcode.bf_insns, req.pkt_addr, req.length, caplen)) {
                        hdr.ts = snf_timestamp_to_timeval(req.timestamp, p->opt.tstamp_precision);
                        hdr.caplen = caplen;
                        hdr.len = req.length;
index 9c6fbd48e7b83f62b2f7ff009537ec4ddf398dd9..8f2280f5069ca1ac0e6642c6e89df324e4c85ae4 100644 (file)
@@ -190,7 +190,7 @@ pcap_read_snit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
                if (caplen > p->snapshot)
                        caplen = p->snapshot;
 
-               if (bpf_filter(p->fcode.bf_insns, cp, nlp->nh_pktlen, caplen)) {
+               if (pcap_filter(p->fcode.bf_insns, cp, nlp->nh_pktlen, caplen)) {
                        struct pcap_pkthdr h;
                        h.ts = ntp->nh_timestamp;
                        h.len = nlp->nh_pktlen;
index a598bae5fe1f0d567ab10741430011c368c5971f..f140bfc5718dfaead3956b7cad9f97b926f547c7 100644 (file)
@@ -126,7 +126,7 @@ again:
        }
 
        if (p->fcode.bf_insns == NULL ||
-           bpf_filter(p->fcode.bf_insns, cp, datalen, caplen)) {
+           pcap_filter(p->fcode.bf_insns, cp, datalen, caplen)) {
                struct pcap_pkthdr h;
                ++psn->stat.ps_recv;
                h.ts.tv_sec = sh->snoop_timestamp.tv_sec;
index 38c7024504627e3ee2bdc59218e76e36b2aa0821..a1f5891169f15100f28882e335d9f51f92c52768 100644 (file)
--- a/pcap-tc.c
+++ b/pcap-tc.c
@@ -985,7 +985,7 @@ static int TcRead(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
                /* No underlaying filtering system. We need to filter on our own */
                if (p->fcode.bf_insns)
                {
-                       filterResult = bpf_filter(p->fcode.bf_insns, data, tcHeader.Length, tcHeader.CapturedLength);
+                       filterResult = pcap_filter(p->fcode.bf_insns, data, tcHeader.Length, tcHeader.CapturedLength);
 
                        if (filterResult == 0)
                        {
index b92c05ea18f488037c3c549deb7a27a7b9734f04..3412f2434ebacf5eb8c5382b815a8fac94508987 100644 (file)
@@ -912,7 +912,7 @@ got:
                pkth.caplen = (bpf_u_int32)handle->snapshot;
 
        if (handle->fcode.bf_insns == NULL ||
-           bpf_filter(handle->fcode.bf_insns, handle->buffer,
+           pcap_filter(handle->fcode.bf_insns, handle->buffer,
              pkth.len, pkth.caplen)) {
                handlep->packets_read++;
                callback(user, &pkth, handle->buffer);
@@ -1081,7 +1081,7 @@ usb_read_linux_bin(pcap_t *handle, int max_packets _U_, pcap_handler callback, u
        pkth.ts.tv_usec = info.hdr->ts_usec;
 
        if (handle->fcode.bf_insns == NULL ||
-           bpf_filter(handle->fcode.bf_insns, handle->buffer,
+           pcap_filter(handle->fcode.bf_insns, handle->buffer,
              pkth.len, pkth.caplen)) {
                handlep->packets_read++;
                callback(user, &pkth, handle->buffer);
@@ -1163,7 +1163,7 @@ usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_ch
                        pkth.ts.tv_usec = hdr->ts_usec;
 
                        if (handle->fcode.bf_insns == NULL ||
-                           bpf_filter(handle->fcode.bf_insns, (u_char*) hdr,
+                           pcap_filter(handle->fcode.bf_insns, (u_char*) hdr,
                              pkth.len, pkth.caplen)) {
                                handlep->packets_read++;
                                callback(user, &pkth, (u_char*) hdr);
diff --git a/pcap.c b/pcap.c
index 95a9f7c0b97531db99e171e01af908e3c7815d63..204408a7bb45d1ac8b75b2add808713de33a0f3b 100644 (file)
--- a/pcap.c
+++ b/pcap.c
@@ -3682,7 +3682,7 @@ pcap_offline_filter(const struct bpf_program *fp, const struct pcap_pkthdr *h,
        const struct bpf_insn *fcode = fp->bf_insns;
 
        if (fcode != NULL)
-               return (bpf_filter(fcode, pkt, h->len, h->caplen));
+               return (pcap_filter(fcode, pkt, h->len, h->caplen));
        else
                return (0);
 }
index 6cb5b7d21c08c5c62895b98b4c25e940eb4dc516..b37546bf13f6c45139c0e9ad85cc80b5e32794da 100644 (file)
@@ -244,16 +244,7 @@ struct bpf_insn {
 #define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
 #define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
 
-/*
- * On at least some versions of NetBSD and QNX, we don't want to declare
- * bpf_filter() here, as it's also be declared in <net/bpf.h>, with a
- * different signature, but, on other BSD-flavored UN*Xes, it's not
- * declared in <net/bpf.h>, so we *do* want to declare it here, so it's
- * declared when we build pcap-bpf.c.
- */
-#if !defined(__NetBSD__) && !defined(__QNX__)
-  PCAP_API u_int       bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
-#endif
+PCAP_API u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
 PCAP_API int   bpf_validate(const struct bpf_insn *f, int len);
 PCAP_API char  *bpf_image(const struct bpf_insn *, int);
 PCAP_API void  bpf_dump(const struct bpf_program *, int);
index 830669ec4a86f7231147fb763a8858d804923b8e..15b1f183b62d5b8e8a34cf5eb93cf5442d680607 100644 (file)
@@ -501,7 +501,7 @@ pcap_offline_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
                }
 
                if ((fcode = p->fcode.bf_insns) == NULL ||
-                   bpf_filter(fcode, data, h.len, h.caplen)) {
+                   pcap_filter(fcode, data, h.len, h.caplen)) {
                        (*callback)(user, &h, data);
                        if (++n >= cnt && cnt > 0)
                                break;
index 7e2d6d6e186d4989f4c694c5a0f7bf5d4f99eb0c..4fcf3ff0180b440b8e06ba0e2b7702d862873932 100644 (file)
@@ -318,7 +318,7 @@ main(int argc, char **argv)
                error("%s", pcap_geterr(pd));
 
        have_fcode = 1;
-       if (!bpf_validate(fcode.bf_insns, fcode.bf_len))
+       if (!pcap_validate_filter(fcode.bf_insns, fcode.bf_len))
                warn("Filter doesn't pass validation");
 
 #ifdef BDEBUG