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/icmp.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'lib/src/protocol/icmp.h') diff --git a/lib/src/protocol/icmp.h b/lib/src/protocol/icmp.h index 5a84995b6..36954bb6d 100644 --- a/lib/src/protocol/icmp.h +++ b/lib/src/protocol/icmp.h @@ -22,6 +22,11 @@ #include "../common.h" +/* + * The length of the ICMP header struct must be 4 bytes. + */ +#define EXPECTED_ICMP_HDRLEN 4 + typedef struct { u8 type; @@ -29,6 +34,15 @@ typedef struct u16 csum; } _icmp_header_t; +#define ICMP_HDRLEN sizeof(_icmp_header_t) +static_assert (EXPECTED_ICMP_HDRLEN == ICMP_HDRLEN, + "Size of ICMP struct does not match its expected size."); + +/* + * The length of the ICMPWLDR header struct must be 4 bytes. + */ +#define EXPECTED_ICMPWLDR_HDRLEN 8 + typedef struct { u8 type; @@ -55,7 +69,9 @@ typedef struct }; } _icmp_wldr_header_t; -#define ICMP_HDRLEN sizeof(_icmp_header_t) +#define ICMPWLDR_HDRLEN sizeof(_icmp_wldr_header_t) +static_assert (EXPECTED_ICMPWLDR_HDRLEN == ICMPWLDR_HDRLEN, + "Size of ICMPWLDR struct does not match its expected size."); #endif /* HICN_PROTOCOL_ICMP_H */ -- cgit 1.2.3-korg