#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>
#endif /* INET6 */
#include <pcap/namedb.h>
+#include "nametoaddr.h"
+
#define ETHERMTU 1500
#ifndef ETHERTYPE_TEB
va_start(ap, fmt);
if (bpf_pcap != NULL)
- (void)vsnprintf(pcap_geterr(bpf_pcap), PCAP_ERRBUF_SIZE,
+ (void)pcap_vsnprintf(pcap_geterr(bpf_pcap), PCAP_ERRBUF_SIZE,
fmt, ap);
va_end(ap);
longjmp(top_ctx, 1);
{
extern int n_errors;
const char * volatile xbuf = buf;
+ yyscan_t scanner = NULL;
+ YY_BUFFER_STATE in_buffer = NULL;
u_int len;
int rc;
* link-layer type, so we can't use it.
*/
if (!p->activated) {
- snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"not-yet-activated pcap_t passed to pcap_compile");
rc = -1;
goto quit;
ai = NULL;
}
#endif
- lex_cleanup();
- freechunks();
rc = -1;
goto quit;
}
snaplen = pcap_snapshot(p);
if (snaplen == 0) {
- snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"snaplen of 0 rejects all packets");
rc = -1;
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();
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);
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