Skip to content

Commit 570bb7d

Browse files
committed
CONTRIBUTION: mention the nd_ types.
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.
1 parent 9ab359e commit 570bb7d

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

CONTRIBUTING.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,39 @@ and ask!
323323
the string is a sequence of XX:XX:... values for the bytes
324324
of the address.
325325

326+
* When defining a structure corresponding to a packet or part of a
327+
packet, so that a pointer to packet data can be cast to a pointer to
328+
that structure and that structure pointer used to refer to fields in
329+
the packet, use the `nd_*` types for the structure members.
330+
331+
Those types all are aligned only on a 1-byte boundary, so a
332+
compiler will not assume that the structure is aligned on a boundary
333+
stricter than one byte; there is no guarantee that fields in packets
334+
are aligned on any particular boundary.
335+
336+
This means that all padding in the structure must be explicitly
337+
declared as fields in the structure.
338+
339+
The `nd_*` types for integral values are:
340+
341+
* `nd_uintN_t`, for unsigned integral values, where *N* is the number
342+
of bytes in the value.
343+
* `nd_intN_t`, for signed integral values, where *N* is the number
344+
of bytes in the value.
345+
346+
The `nd_*` types for IP addresses are:
347+
348+
* `nd_ipv4`, for IPv4 addresses;
349+
* `nd_ipv6`, for IPv6 addresses.
350+
351+
The `nd_*` types for link-layer addresses are:
352+
353+
* `nd_mac48`, for MAC-48 (Ethernet, 802.11, etc.) addresses;
354+
* `nd_eui64`, for EUI-64 values.
355+
356+
The `nd_*` type for a byte in a sequence of bytes is `nd_byte`; an
357+
*N*-byte sequence should be declared as `nd_byte[N]`.
358+
326359
* Do invalid packet checks in code: Think that your code can receive in input
327360
not only a valid packet but any arbitrary random sequence of octets (packet
328361
* built malformed originally by the sender or by a fuzz tester,

netdissect.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,16 @@ typedef signed char nd_int8_t[1];
5959

6060
/*
6161
* "unsigned char" so that sign extension isn't done on the
62-
* individual bytes while they're being assembled.
62+
* individual bytes while they're being assembled. Use
63+
* GET_S_BE_n() and GET_S_LE_n() macros to extract the value
64+
* as a signed integer.
6365
*/
66+
typedef unsigned char nd_int16_t[2];
67+
typedef unsigned char nd_int24_t[3];
6468
typedef unsigned char nd_int32_t[4];
69+
typedef unsigned char nd_int40_t[5];
70+
typedef unsigned char nd_int48_t[6];
71+
typedef unsigned char nd_int56_t[7];
6572
typedef unsigned char nd_int64_t[8];
6673

6774
#define FMAXINT (4294967296.0) /* floating point rep. of MAXINT */

0 commit comments

Comments
 (0)