diff options
author | rpaulo <rpaulo@FreeBSD.org> | 2009-03-21 22:58:08 +0000 |
---|---|---|
committer | rpaulo <rpaulo@FreeBSD.org> | 2009-03-21 22:58:08 +0000 |
commit | 3f19af99adb541ff811a6faaaae340e24ad313c5 (patch) | |
tree | 41d4ee124e8dc2938aa5559c6f422a7b778c807f /contrib/libpcap/optimize.c | |
parent | b0069d00e9ca6c9d90eb18267d0949527c0249e5 (diff) | |
parent | d8d18f6fbdf4f16ae4382f3d0a2d97953edd9b2c (diff) | |
download | FreeBSD-src-3f19af99adb541ff811a6faaaae340e24ad313c5.zip FreeBSD-src-3f19af99adb541ff811a6faaaae340e24ad313c5.tar.gz |
Merge libpcap 1.0.0.
Diffstat (limited to 'contrib/libpcap/optimize.c')
-rw-r--r-- | contrib/libpcap/optimize.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/contrib/libpcap/optimize.c b/contrib/libpcap/optimize.c index d39273b..475313f 100644 --- a/contrib/libpcap/optimize.c +++ b/contrib/libpcap/optimize.c @@ -22,7 +22,7 @@ */ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/optimize.c,v 1.85.2.3 2007/09/12 21:29:45 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/optimize.c,v 1.90.2.1 2008/01/02 04:22:16 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -53,6 +53,10 @@ extern int _w32_ffs (int mask); #define ffs _w32_ffs #endif +#if defined(WIN32) && defined (_MSC_VER) +int ffs(int mask); +#endif + /* * Represents a deleted instruction. */ @@ -906,6 +910,17 @@ opt_peep(b) JF(b) = JT(b); } /* + * If we're comparing against the index register, and the index + * register is a known constant, we can just compare against that + * constant. + */ + val = b->val[X_ATOM]; + if (vmap[val].is_const && BPF_SRC(b->s.code) == BPF_X) { + bpf_int32 v = vmap[val].const_val; + b->s.code &= ~BPF_X; + b->s.k = v; + } + /* * If the accumulator is a known constant, we can compute the * comparison result. */ @@ -2277,6 +2292,15 @@ install_bpf_program(pcap_t *p, struct bpf_program *fp) size_t prog_size; /* + * Validate the program. + */ + if (!bpf_validate(fp->bf_insns, fp->bf_len)) { + snprintf(p->errbuf, sizeof(p->errbuf), + "BPF program is not valid"); + return (-1); + } + + /* * Free up any already installed program. */ pcap_freecode(&p->fcode); |