]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add some new nd_ types for use in structures for packet layouts.
authorGuy Harris <[email protected]>
Mon, 11 Dec 2017 08:08:25 +0000 (00:08 -0800)
committerGuy Harris <[email protected]>
Mon, 11 Dec 2017 08:08:25 +0000 (00:08 -0800)
Note that nd_ipv4 is used for IPv4 netmasks as well as IPv4 addresses.

netdissect.h

index 69d61ccc45d69a4e7c6cd0035b4cc89e4772dad7..4c98164aa952409a7c5a0465872be24eee3f66d6 100644 (file)
@@ -57,12 +57,14 @@ typedef unsigned char nd_uint64_t[8];
 typedef signed char nd_int8_t[1];
 
 /*
- * Use this for IPv4 addresses.  It's defined as an array of octets, so
- * that it's not aligned on its "natural" boundary, and it's defined as
- * a structure in the hopes that this makes it harder to naively use
- * EXTRACT_BE_U_4() to extract the value - in many cases you just want
- * to use UNALIGNED_MEMCPY() to copy its value, so that it remains in
- * network byte order.
+ * Use this for IPv4 addresses and netmasks.
+ *
+ * It's defined as an array of octets, so that it's not guaranteed to
+ * be aligned on its "natural" boundary (in some packet formats, it
+ * *isn't* so aligned), and it's defined as a structure in the hopes
+ * that this makes it harder to naively use EXTRACT_BE_U_4() to extract
+ * the value - in many cases you just want to use UNALIGNED_MEMCPY() to
+ * copy its value, so that it remains in network byte order.
  *
  * (Among other things, we don't want somebody thinking "IPv4 addresses,
  * they're in network byte order, so we want EXTRACT_BE_U_4(), right?"
@@ -78,6 +80,25 @@ typedef struct {
        unsigned char bytes[4];
 } nd_ipv4;
 
+/*
+ * Use this for IPv6 addresses and netmasks.
+ */
+typedef struct {
+       unsigned char bytes[16];
+} nd_ipv6;
+
+/*
+ * Use this for MAC addresses.
+ */
+typedef struct {
+       unsigned char bytes[6];
+} nd_mac_addr;
+
+/*
+ * Use this for blobs of bytes; make them arrays of nd_byte.
+ */
+typedef unsigned char nd_byte;
+
 /* snprintf et al */
 
 #include <stdarg.h>