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/icmprd.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'lib/src/protocol/icmprd.h') diff --git a/lib/src/protocol/icmprd.h b/lib/src/protocol/icmprd.h index c2f27d673..aa1fa01ae 100644 --- a/lib/src/protocol/icmprd.h +++ b/lib/src/protocol/icmprd.h @@ -21,21 +21,46 @@ #define HICN_PROTOCOL_ICMPRD_H #include "../common.h" +#include "ipv4.h" -typedef struct __attribute__ ((__packed__)) +/* + * The length of the ICMPRD4 header struct must be 92 bytes. + */ +#define EXPECTED_ICMPRD4_HDRLEN 92 + +typedef struct { + u8 type; + u8 code; + u16 csum; ip4_address_t ip; _ipv4_header_t iph; u8 data[64]; } _icmprd4_header_t; -typedef struct __attribute__ ((__packed__)) +#define ICMPRD4_HDRLEN sizeof(_icmprd4_header_t) +static_assert (EXPECTED_ICMPRD4_HDRLEN == ICMPRD4_HDRLEN, + "Size of ICMPWLDR struct does not match its expected size."); + +/* + * The length of the ICMPRD header struct must be 40 bytes. + */ +#define EXPECTED_ICMPRD_HDRLEN 40 + +typedef struct { + u8 type; + u8 code; + u16 csum; u32 res; ip6_address_t tgt; ip6_address_t dst; } _icmprd_header_t; +#define ICMPRD_HDRLEN sizeof(_icmprd_header_t) +static_assert (EXPECTED_ICMPRD_HDRLEN == ICMPRD_HDRLEN, + "Size of ICMPWLDR struct does not match its expected size."); + #endif /* HICN_PROTOCOL_ICMPRD_H */ /* -- cgit 1.2.3-korg