X-Git-Url: https://git.tcpdump.org/libpcap/blobdiff_plain/c3a9edf7ebc0d2bfaa269aceb4dddf980da771f9..09b51d326c38ea8e10ce4da09c09d50e08c5aeb8:/pcap/bpf.h diff --git a/pcap/bpf.h b/pcap/bpf.h index 92725884..3970d0a1 100644 --- a/pcap/bpf.h +++ b/pcap/bpf.h @@ -15,11 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -62,16 +58,30 @@ * I don't have earlier versions available to check), or QNX-style * multiple-include protection (as per GitHub pull request #394). * + * We trust that they will define structures and macros and types in + * a fashion that's source-compatible and binary-compatible with our + * definitions. + * * We do not check for BPF_MAJOR_VERSION, as that's defined by * , which is directly or indirectly included in some * programs that also include pcap.h, and doesn't - * define stuff we need. + * define stuff we need. We *do* protect against + * defining various macros for BPF code itself; says + * + * Try and keep these values and structures similar to BSD, especially + * the BPF code definitions which need to match so you can share filters + * + * so we trust that it will define them in a fashion that's source-compatible + * and binary-compatible with our definitions. * * This also provides our own multiple-include protection. */ #if !defined(_NET_BPF_H_) && !defined(_NET_BPF_H_INCLUDED) && !defined(_BPF_H_) && !defined(_H_BPF) && !defined(lib_pcap_bpf_h) #define lib_pcap_bpf_h +#include +#include + #ifdef __cplusplus extern "C" { #endif @@ -108,8 +118,6 @@ struct bpf_program { struct bpf_insn *bf_insns; }; -#include - /* * The instruction encodings. * @@ -141,7 +149,7 @@ struct bpf_program { #define BPF_B 0x10 /* 0x18 reserved; used by BSD/OS */ #define BPF_MODE(code) ((code) & 0xe0) -#define BPF_IMM 0x00 +#define BPF_IMM 0x00 #define BPF_ABS 0x20 #define BPF_IND 0x40 #define BPF_MEM 0x60 @@ -235,36 +243,41 @@ struct bpf_program { */ struct bpf_insn { u_short code; - u_char jt; - u_char jf; + u_char jt; + u_char jf; bpf_u_int32 k; }; -/* - * Auxiliary data, for use when interpreting a filter intended for the - * Linux kernel when the kernel rejects the filter (requiring us to - * run it in userland). It contains VLAN tag information. - */ -struct bpf_aux_data { - u_short vlan_tag_present; - u_short vlan_tag; -}; - /* * Macros for insn array initializers. + * + * In case somebody's included , or something else that + * gives the kernel's definitions of BPF statements, get rid of its + * definitions, so we can supply ours instead. If some kernel's + * definitions aren't *binary-compatible* with what BPF has had + * since it first sprung from the brows of Van Jacobson and Steve + * McCanne, that kernel should be fixed. */ +#ifdef BPF_STMT +#undef BPF_STMT +#endif #define BPF_STMT(code, k) { (u_short)(code), 0, 0, k } +#ifdef BPF_JUMP +#undef BPF_JUMP +#endif #define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k } -#if __STDC__ || defined(__cplusplus) -extern int bpf_validate(const struct bpf_insn *, int); -extern u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int); -extern u_int bpf_filter_with_aux_data(const struct bpf_insn *, const u_char *, u_int, u_int, const struct bpf_aux_data *); -#else -extern int bpf_validate(); -extern u_int bpf_filter(); -extern u_int bpf_filter(); -#endif +PCAP_AVAILABLE_0_4 +PCAP_API u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int); + +PCAP_AVAILABLE_0_6 +PCAP_API int bpf_validate(const struct bpf_insn *f, int len); + +PCAP_AVAILABLE_0_4 +PCAP_API char *bpf_image(const struct bpf_insn *, int); + +PCAP_AVAILABLE_0_6 +PCAP_API void bpf_dump(const struct bpf_program *, int); /* * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).