]> The Tcpdump Group git mirrors - libpcap/blobdiff - gencode.c
Merge pull request #1 from the-tcpdump-group/master
[libpcap] / gencode.c
index a887f2730f7ac55783d869467f7557629affc1f3..e59953fff426bd366d7a7d0415c906639a6ce207 100644 (file)
--- a/gencode.c
+++ b/gencode.c
@@ -523,7 +523,8 @@ static struct block *gen_host6(compiler_state_t *, struct in6_addr *,
     struct in6_addr *, int, int, int);
 #endif
 #ifndef INET6
-static struct block *gen_gateway(const u_char *, bpf_u_int32 **, int, int);
+static struct block *gen_gateway(compiler_state_t *, const u_char *,
+    bpf_u_int32 **, int, int);
 #endif
 static struct block *gen_ipfrag(compiler_state_t *);
 static struct block *gen_portatom(compiler_state_t *, int, bpf_int32);
@@ -663,6 +664,9 @@ int
 pcap_compile(pcap_t *p, struct bpf_program *program,
             const char *buf, int optimize, bpf_u_int32 mask)
 {
+#ifdef _WIN32
+       static int done = 0;
+#endif
        compiler_state_t cstate;
        const char * volatile xbuf = buf;
        yyscan_t scanner = NULL;
@@ -670,14 +674,6 @@ pcap_compile(pcap_t *p, struct bpf_program *program,
        u_int len;
        int  rc;
 
-#ifdef _WIN32
-       static int done = 0;
-
-       if (!done)
-               pcap_wsockinit();
-       done = 1;
-#endif
-
        /*
         * If this pcap_t hasn't been activated, it doesn't have a
         * link-layer type, so we can't use it.
@@ -685,12 +681,41 @@ pcap_compile(pcap_t *p, struct bpf_program *program,
        if (!p->activated) {
                pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
                    "not-yet-activated pcap_t passed to pcap_compile");
-               rc = -1;
-               goto quit;
+               return (-1);
        }
+
+#ifdef _WIN32
+       if (!done)
+               pcap_wsockinit();
+       done = 1;
+#endif
+
+#ifdef HAVE_REMOTE
+       /*
+        * If the device on which we're capturing need to be notified
+        * that a new filter is being compiled, do so.
+        *
+        * This allows them to save a copy of it, in case, for example,
+        * they're implementing a form of remote packet capture, and
+        * want the remote machine to filter out the packets in which
+        * it's sending the packets it's captured.
+        *
+        * XXX - the fact that we happen to be compiling a filter
+        * doesn't necessarily mean we'll be installing it as the
+        * filter for this pcap_t; we might be running it from userland
+        * on captured packets to do packet classification.  We really
+        * need a better way of handling this, but this is all that
+        * the WinPcap code did.
+        */
+       if (p->save_current_filter_op != NULL)
+               (p->save_current_filter_op)(p, buf);
+#endif
+
        initchunks(&cstate);
        cstate.no_optimize = 0;
+#ifdef INET6
        cstate.ai = NULL;
+#endif
        cstate.ic.root = NULL;
        cstate.ic.cur_mark = 0;
        cstate.bpf_pcap = p;
@@ -4902,11 +4927,8 @@ gen_host6(compiler_state_t *cstate, struct in6_addr *addr,
 
 #ifndef INET6
 static struct block *
-gen_gateway(eaddr, alist, proto, dir)
-       const u_char *eaddr;
-       bpf_u_int32 **alist;
-       int proto;
-       int dir;
+gen_gateway(compiler_state_t *cstate, const u_char *eaddr, bpf_u_int32 **alist,
+    int proto, int dir)
 {
        struct block *b0, *b1, *tmp;
 
@@ -6470,7 +6492,7 @@ gen_scode(compiler_state_t *cstate, const char *name, struct qual q)
                alist = pcap_nametoaddr(name);
                if (alist == NULL || *alist == NULL)
                        bpf_error(cstate, "unknown host '%s'", name);
-               b = gen_gateway(eaddr, alist, proto, dir);
+               b = gen_gateway(cstate, eaddr, alist, proto, dir);
                free(eaddr);
                return b;
 #else