]> The Tcpdump Group git mirrors - libpcap/blobdiff - pcap/bpf.h
Update config.{guess,sub}, timestamps 2023-01-01,2023-01-21
[libpcap] / pcap / bpf.h
index 6cb5b7d21c08c5c62895b98b4c25e940eb4dc516..3970d0a18426321a2ad1d8278488521df2dc18bb 100644 (file)
  * 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
  * <linux/filter.h>, which is directly or indirectly included in some
  * programs that also include pcap.h, and <linux/filter.h> doesn't
- * define stuff we need.
+ * define stuff we need.  We *do* protect against <linux/filter.h>
+ * defining various macros for BPF code itself; <linux/filter.h> 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.
  */
@@ -69,6 +80,7 @@
 #define lib_pcap_bpf_h
 
 #include <pcap/funcattrs.h>
+#include <pcap/dlt.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -106,8 +118,6 @@ struct bpf_program {
        struct bpf_insn *bf_insns;
 };
 
-#include <pcap/dlt.h>
-
 /*
  * The instruction encodings.
  *
@@ -139,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
@@ -233,29 +243,40 @@ 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;
 };
 
 /*
  * Macros for insn array initializers.
+ *
+ * In case somebody's included <linux/filter.h>, 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 }
 
-/*
- * On at least some versions of NetBSD and QNX, we don't want to declare
- * bpf_filter() here, as it's also be declared in <net/bpf.h>, with a
- * different signature, but, on other BSD-flavored UN*Xes, it's not
- * declared in <net/bpf.h>, so we *do* want to declare it here, so it's
- * declared when we build pcap-bpf.c.
- */
-#if !defined(__NetBSD__) && !defined(__QNX__)
-  PCAP_API u_int       bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
-#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);
 
 /*