aboutsummaryrefslogtreecommitdiffstats
path: root/lib/src/protocol/ipv4.h
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2019-02-11 23:50:45 +0100
committerMauro Sardara <msardara@cisco.com>2019-02-12 13:15:47 +0000
commitfbd4dd9c5eba6f8f10bcc0db30a72ea3378c149b (patch)
treee65187748120c945e39256084d5614ed127b8383 /lib/src/protocol/ipv4.h
parentf126f86da5acf088f24e97ecb32f9ba5a1789aa4 (diff)
[HICN-51] Add static assert for ensuring correct struct size in libhicn definitions.
Change-Id: Ib41e9cbdd2ea84a40eb4e7b01da131cbad9575c4 Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'lib/src/protocol/ipv4.h')
-rw-r--r--lib/src/protocol/ipv4.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/src/protocol/ipv4.h b/lib/src/protocol/ipv4.h
index c57485b6c..8a5b6683b 100644
--- a/lib/src/protocol/ipv4.h
+++ b/lib/src/protocol/ipv4.h
@@ -22,6 +22,11 @@
/* Headers were adapted from linux' definitions in netinet/ip.h */
+/*
+ * The length of the IPV4 header struct must be 20 bytes.
+ */
+#define EXPECTED_IPV4_HDRLEN 20
+
typedef struct
{
union
@@ -55,6 +60,13 @@ typedef struct
#define ipv4_header_bytes(ipv4_header) (sizeof(u32) * (ipv4_header->version_ihl & 0xf))
#define IPV4_HDRLEN sizeof(_ipv4_header_t)
+static_assert (EXPECTED_IPV4_HDRLEN == IPV4_HDRLEN,
+ "Size of IPV4 struct does not match its expected size.");
+
+/*
+ * The length of the IPV4 pseudo header struct must be 12 bytes.
+ */
+#define EXPECTED_IPV4_PSHDRLEN 12
typedef struct
{
@@ -66,6 +78,8 @@ typedef struct
} ipv4_pseudo_header_t;
#define IPV4_PSHDRLEN sizeof(ipv4_pseudo_header_t)
+static_assert (EXPECTED_IPV4_PSHDRLEN == IPV4_PSHDRLEN,
+ "Size of IPV4_PSHDR struct does not match its expected size.");
/* Default field values */
#define IPV4_DEFAULT_VERSION 4