From fbd4dd9c5eba6f8f10bcc0db30a72ea3378c149b Mon Sep 17 00:00:00 2001 From: Mauro Sardara Date: Mon, 11 Feb 2019 23:50:45 +0100 Subject: [HICN-51] Add static assert for ensuring correct struct size in libhicn definitions. Change-Id: Ib41e9cbdd2ea84a40eb4e7b01da131cbad9575c4 Signed-off-by: Mauro Sardara --- lib/src/protocol/ipv4.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib/src/protocol/ipv4.h') 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 -- cgit 1.2.3-korg