]> The Tcpdump Group git mirrors - tcpdump/commitdiff
CONTRIBUTION: mention the nd_ types.
authorGuy Harris <[email protected]>
Wed, 9 Aug 2023 07:39:56 +0000 (00:39 -0700)
committerFrancois-Xavier Le Bail <[email protected]>
Sat, 14 Oct 2023 18:38:32 +0000 (20:38 +0200)
While we're at it, define a complete set of nd_intN_t types, for all
values of N between 1 and 8, just as we have a complete set of
nd_uintN_t types.

(cherry picked from commit 570bb7d1f8f87be048e8299a4c38b82b092a9b7b)

CONTRIBUTING.md
netdissect.h

index faa0f13d519f2856607ed58839672909228ef481..c76330784bdf0dc8422500cf37d132598041bb55 100644 (file)
@@ -285,6 +285,39 @@ and ask!
    the string is a sequence of XX:XX:... values for the bytes
    of the address.
 
    the string is a sequence of XX:XX:... values for the bytes
    of the address.
 
+*  When defining a structure corresponding to a packet or part of a
+   packet, so that a pointer to packet data can be cast to a pointer to
+   that structure and that structure pointer used to refer to fields in
+   the packet, use the `nd_*` types for the structure members.
+
+   Those types all are aligned only on a 1-byte boundary, so a
+   compiler will not assume that the structure is aligned on a boundary
+   stricter than one byte; there is no guarantee that fields in packets
+   are aligned on any particular boundary.
+
+   This means that all padding in the structure must be explicitly
+   declared as fields in the structure.
+
+   The `nd_*` types for integral values are:
+
+   * `nd_uintN_t`, for unsigned integral values, where *N* is the number
+      of bytes in the value.
+   * `nd_intN_t`, for signed integral values, where *N* is the number
+      of bytes in the value.
+
+   The `nd_*` types for IP addresses are:
+
+   * `nd_ipv4`, for IPv4 addresses;
+   * `nd_ipv6`, for IPv6 addresses.
+
+   The `nd_*` types for link-layer addresses are:
+
+   * `nd_mac48`, for MAC-48 (Ethernet, 802.11, etc.) addresses;
+   * `nd_eui64`, for EUI-64 values.
+
+   The `nd_*` type for a byte in a sequence of bytes is `nd_byte`; an
+   *N*-byte sequence should be declared as `nd_byte[N]`.
+
 *  Do invalid packet checks in code: Think that your code can receive in input
    not only a valid packet but any arbitrary random sequence of octets (packet
    * built malformed originally by the sender or by a fuzz tester,
 *  Do invalid packet checks in code: Think that your code can receive in input
    not only a valid packet but any arbitrary random sequence of octets (packet
    * built malformed originally by the sender or by a fuzz tester,
index 0eaf8eb2d6215e4ebb7a130848cd0912d3351d36..e49fef42ab088cc76af4f633e2c809a3b428d880 100644 (file)
@@ -59,9 +59,16 @@ typedef signed char nd_int8_t[1];
 
 /*
  * "unsigned char" so that sign extension isn't done on the
 
 /*
  * "unsigned char" so that sign extension isn't done on the
- * individual bytes while they're being assembled.
+ * individual bytes while they're being assembled.  Use
+ * GET_S_BE_n() and GET_S_LE_n() macros to extract the value
+ * as a signed integer.
  */
  */
+typedef unsigned char nd_int16_t[2];
+typedef unsigned char nd_int24_t[3];
 typedef unsigned char nd_int32_t[4];
 typedef unsigned char nd_int32_t[4];
+typedef unsigned char nd_int40_t[5];
+typedef unsigned char nd_int48_t[6];
+typedef unsigned char nd_int56_t[7];
 typedef unsigned char nd_int64_t[8];
 
 #define        FMAXINT (4294967296.0)  /* floating point rep. of MAXINT */
 typedef unsigned char nd_int64_t[8];
 
 #define        FMAXINT (4294967296.0)  /* floating point rep. of MAXINT */