]> The Tcpdump Group git mirrors - libpcap/blobdiff - pcap-pf.c
Update config.{guess,sub}, timestamps 2023-01-01,2023-01-21
[libpcap] / pcap-pf.c
index 59808647940ef496f0d09b0ba63dc6d1cfb87e78..bd27933eff69e312717d908b9202e1ed7fdb2c20 100644 (file)
--- a/pcap-pf.c
+++ b/pcap-pf.c
@@ -48,7 +48,6 @@ struct rtentry;
 #include <netinet/tcp.h>
 #include <netinet/tcpip.h>
 
-#include <ctype.h>
 #include <errno.h>
 #include <netdb.h>
 #include <stdio.h>
@@ -104,9 +103,7 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
        register u_char *p, *bp;
        register int cc, n, buflen, inc;
        register struct enstamp *sp;
-#ifdef LBL_ALIGN
        struct enstamp stamp;
-#endif
        register u_int pad;
 
  again:
@@ -136,6 +133,9 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
                bp = pc->bp;
        /*
         * Loop through each packet.
+        *
+        * This assumes that a single buffer of packets will have
+        * <= INT_MAX packets, so the packet count doesn't overflow.
         */
        n = 0;
        pad = pc->fddipad;
@@ -160,19 +160,17 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
                        }
                }
                if (cc < sizeof(*sp)) {
-                       pcap_snprintf(pc->errbuf, sizeof(pc->errbuf),
+                       snprintf(pc->errbuf, sizeof(pc->errbuf),
                            "pf short read (%d)", cc);
                        return (-1);
                }
-#ifdef LBL_ALIGN
                if ((long)bp & 3) {
                        sp = &stamp;
                        memcpy((char *)sp, (char *)bp, sizeof(*sp));
                } else
-#endif
                        sp = (struct enstamp *)bp;
                if (sp->ens_stamplen != sizeof(*sp)) {
-                       pcap_snprintf(pc->errbuf, sizeof(pc->errbuf),
+                       snprintf(pc->errbuf, sizeof(pc->errbuf),
                            "pf short stamplen (%d)",
                            sp->ens_stamplen);
                        return (-1);
@@ -205,7 +203,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;
@@ -226,7 +224,7 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
 }
 
 static int
-pcap_inject_pf(pcap_t *p, const void *buf, size_t size)
+pcap_inject_pf(pcap_t *p, const void *buf, int size)
 {
        int ret;
 
@@ -261,7 +259,7 @@ pcap_stats_pf(pcap_t *p, struct pcap_stat *ps)
         *      full.
         *
         *      "ps_ifdrop" counts packets dropped by the network
-        *      inteface (regardless of whether they would have passed
+        *      interface (regardless of whether they would have passed
         *      the input filter, of course).
         *
         * If packet filtering is not being done in the kernel:
@@ -273,7 +271,7 @@ pcap_stats_pf(pcap_t *p, struct pcap_stat *ps)
         *      the userland filter.
         *
         *      "ps_ifdrop" counts packets dropped by the network
-        *      inteface (regardless of whether they would have passed
+        *      interface (regardless of whether they would have passed
         *      the input filter, of course).
         *
         * These statistics don't include packets not yet read from
@@ -331,7 +329,7 @@ pcap_activate_pf(pcap_t *p)
                p->fd = pfopen(p->opt.device, O_RDONLY);
        if (p->fd < 0) {
                if (errno == EACCES) {
-                       pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+                       snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
                            "pf open: %s: Permission denied\n"
 "your system may not be properly configured; see the packetfilter(4) man page",
                            p->opt.device);
@@ -464,7 +462,7 @@ pcap_activate_pf(pcap_t *p)
                 * framing", there's not much we can do, as that
                 * doesn't specify a particular type of header.
                 */
-               pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+               snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
                    "unknown data-link type %u", devparams.end_dev_type);
                err = PCAP_ERROR;
                goto bad;
@@ -540,7 +538,7 @@ pcap_create_interface(const char *device _U_, char *ebuf)
 {
        pcap_t *p;
 
-       p = pcap_create_common(ebuf, sizeof (struct pcap_pf));
+       p = PCAP_CREATE_COMMON(ebuf, struct pcap_pf);
        if (p == NULL)
                return (NULL);
 
@@ -562,10 +560,20 @@ static int
 get_if_flags(const char *name _U_, bpf_u_int32 *flags _U_, char *errbuf _U_)
 {
        /*
-        * Nothing we can do.
+        * Nothing we can do other than mark loopback devices as "the
+        * connected/disconnected status doesn't apply".
+        *
         * XXX - is there a way to find out whether an adapter has
         * something plugged into it?
         */
+       if (*flags & PCAP_IF_LOOPBACK) {
+               /*
+                * Loopback devices aren't wireless, and "connected"/
+                * "disconnected" doesn't apply to them.
+                */
+               *flags |= PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE;
+               return (0);
+       }
        return (0);
 }