]> 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)
committerGuy Harris <[email protected]>
Wed, 9 Aug 2023 07:39:56 +0000 (00:39 -0700)
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.

CONTRIBUTING.md
netdissect.h

index 5b9df8c9c17a6b6e11949ddcdfde2d0dafa0c046..879471beb3c7062330821fbf7a95767fe459656e 100644 (file)
@@ -323,6 +323,39 @@ and ask!
    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,
index 7255701ecfa05c1942f25af67c7cdf02aea814fc..6bbac0b10488a8126bd7ed6ef32a7b6908d96629 100644 (file)
@@ -59,9 +59,16 @@ typedef signed char nd_int8_t[1];
 
 /*
  * "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_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 */