]> The Tcpdump Group git mirrors - libpcap/blobdiff - gencode.c
If parser debugging is enabled, ensure pcap_debug is exported.
[libpcap] / gencode.c
index 8c010e626be4d0f62b94fb89dc25148aa1361f70..481c4d9c358a5ade099ba458a907502b837c8139 100644 (file)
--- a/gencode.c
+++ b/gencode.c
@@ -74,6 +74,9 @@
 #include "pcap/ipnet.h"
 #include "arcnet.h"
 
+#include "grammar.h"
+#include "scanner.h"
+
 #if defined(linux) && defined(PF_PACKET) && defined(SO_ATTACH_FILTER)
 #include <linux/types.h>
 #include <linux/if_packet.h>
@@ -142,6 +145,8 @@ struct addrinfo {
 #endif /* INET6 */
 #include <pcap/namedb.h>
 
+#include "nametoaddr.h"
+
 #define ETHERMTU       1500
 
 #ifndef ETHERTYPE_TEB
@@ -472,6 +477,8 @@ pcap_compile(pcap_t *p, struct bpf_program *program,
 {
        extern int n_errors;
        const char * volatile xbuf = buf;
+       yyscan_t scanner = NULL;
+       YY_BUFFER_STATE in_buffer = NULL;
        u_int len;
        int  rc;
 
@@ -512,8 +519,6 @@ pcap_compile(pcap_t *p, struct bpf_program *program,
                        ai = NULL;
                }
 #endif
-               lex_cleanup();
-               freechunks();
                rc = -1;
                goto quit;
        }
@@ -528,9 +533,11 @@ pcap_compile(pcap_t *p, struct bpf_program *program,
                goto quit;
        }
 
-       lex_init(xbuf ? xbuf : "");
+       if (pcap_lex_init(&scanner) != 0)
+               bpf_error("can't initialize scanner: %s", pcap_strerror(errno));
+       in_buffer = pcap__scan_string(xbuf ? xbuf : "", scanner);
        init_linktype(p);
-       (void)pcap_parse();
+       (void)pcap_parse(scanner);
 
        if (n_errors)
                syntax();
@@ -547,12 +554,21 @@ pcap_compile(pcap_t *p, struct bpf_program *program,
        program->bf_insns = icode_to_fcode(root, &len);
        program->bf_len = len;
 
-       lex_cleanup();
-       freechunks();
-
        rc = 0;  /* We're all okay */
 
 quit:
+       /*
+        * Clean up everything for the lexical analyzer.
+        */
+       if (in_buffer != NULL)
+               pcap__delete_buffer(in_buffer, scanner);
+       if (scanner != NULL)
+               pcap_lex_destroy(scanner);
+
+       /*
+        * Clean up our own allocated memory.
+        */
+       freechunks();
 
 #ifdef _WIN32
        LeaveCriticalSection(&g_PcapCompileCriticalSection);
@@ -8311,7 +8327,7 @@ gen_geneve6(int vni)
                sappend(s, s1);
        } else {
                s = new_stmt(BPF_LD|BPF_IMM);
-               s->s.k = 40;;
+               s->s.k = 40;
        }
 
        /* Forcibly append these statements to the true condition