]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Declare ND_UNALIGNED in netdissect.h.
authorGuy Harris <[email protected]>
Mon, 29 Jan 2018 04:16:36 +0000 (20:16 -0800)
committerGuy Harris <[email protected]>
Mon, 29 Jan 2018 04:16:36 +0000 (20:16 -0800)
It's netdissect-specific, and there are some files that include
netdissect.h, that don't include netdissect-stdinc.h, and that include
files that define structures using ND_UNALIGNED.

netdissect-stdinc.h
netdissect.h

index a05e1cfecf08bafb63ebcfea8c717843e5b87c9f..8ef4e2a704326f1577f264e0c2af6c87f40e0e76 100644 (file)
@@ -277,55 +277,6 @@ typedef char* caddr_t;
 
 #endif /* _WIN32 */
 
-/*
- * Used to declare a structure unaligned, so that the C compiler,
- * if necessary, generates code that doesn't assume alignment.
- * This is required because there is no guarantee that the packet
- * data we get from libpcap/WinPcap is properly aligned.
- *
- * This assumes that, for all compilers that support __attribute__((packed)),
- * for all instruction set architectures requiring strict alignment, declaring
- * a structure with that attribute causes the compiler to generate code that
- * handles misaligned 2-byte, 4-byte, and 8-byte integral quantities.
- *
- * It does not (yet) handle compilers where you can get the compiler
- * to generate code of that sort by some other means.
- *
- * This is required in order to, for example, keep the compiler from
- * generating, for
- *
- *     if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) {
- *
- * in print-bootp.c, code that loads the first 4-byte word of a
- * "struct bootp", masking out the bp_hops field, and comparing the result
- * against 0x01010600.
- *
- * Note: this also requires that padding be put into the structure,
- * at least for compilers where it's implemented as __attribute__((packed)).
- *
- * XXX - now that we're using nd_ types that are just arrays of bytes, is
- * this still necessary?  Are there any compilers that align structures,
- * none of whose members require more than byte alignment, on more than
- * one-byte boundaries, and assume a structure is aligned on such a
- * boundary?  (I have vague memories of either m68k or ARM compilers
- * aligning on at least 2-byte boundaries.)
- */
-#if ND_IS_AT_LEAST_GNUC_VERSION(2,0) || \
-    ND_IS_AT_LEAST_XL_C_VERSION(6,0)
-  /*
-   * GCC 2.0 or later, or a compiler that claims to be GCC 2.0 or later,
-   * or IBM XL C 6.0 or later.
-   *
-   * Use __attribute__((packed)).
-   */
-  #define ND_UNALIGNED __attribute__((packed))
-#else
-  /*
-   * Nothing.
-   */
-  #define ND_UNALIGNED
-#endif
-
 /*
  * fopen() read and write modes for text files and binary files.
  */
index 2bbfda30248d611abec4437de06f1bcda852d55b..323343dc8f680c2810bdd84a6f3784493b4f6375 100644 (file)
 #endif
 #include <sys/types.h>
 
+/*
+ * Used to declare a structure unaligned, so that the C compiler,
+ * if necessary, generates code that doesn't assume alignment.
+ * This is required because there is no guarantee that the packet
+ * data we get from libpcap/WinPcap is properly aligned.
+ *
+ * This assumes that, for all compilers that support __attribute__((packed)),
+ * for all instruction set architectures requiring strict alignment, declaring
+ * a structure with that attribute causes the compiler to generate code that
+ * handles misaligned 2-byte, 4-byte, and 8-byte integral quantities.
+ *
+ * It does not (yet) handle compilers where you can get the compiler
+ * to generate code of that sort by some other means.
+ *
+ * This is required in order to, for example, keep the compiler from
+ * generating, for
+ *
+ *     if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) {
+ *
+ * in print-bootp.c, code that loads the first 4-byte word of a
+ * "struct bootp", masking out the bp_hops field, and comparing the result
+ * against 0x01010600.
+ *
+ * Note: this also requires that padding be put into the structure,
+ * at least for compilers where it's implemented as __attribute__((packed)).
+ *
+ * XXX - now that we're using nd_ types that are just arrays of bytes, is
+ * this still necessary?  Are there any compilers that align structures,
+ * none of whose members require more than byte alignment, on more than
+ * one-byte boundaries, and assume a structure is aligned on such a
+ * boundary?  (I have vague memories of either m68k or ARM compilers
+ * aligning on at least 2-byte boundaries.)
+ */
+#if ND_IS_AT_LEAST_GNUC_VERSION(2,0) || \
+    ND_IS_AT_LEAST_XL_C_VERSION(6,0)
+  /*
+   * GCC 2.0 or later, or a compiler that claims to be GCC 2.0 or later,
+   * or IBM XL C 6.0 or later.
+   *
+   * Use __attribute__((packed)).
+   */
+  #define ND_UNALIGNED __attribute__((packed))
+#else
+  /*
+   * Nothing.
+   */
+  #define ND_UNALIGNED
+#endif
+
 /*
  * Data types corresponding to multi-byte integral values within data
  * structures.  These are defined as arrays of octets, so that they're