@@ -341,8 +341,16 @@ void dtls_check_retransmit(dtls_context_t *context, clock_time_t *next);
341341#define DTLS_CT_HANDSHAKE 22
342342#define DTLS_CT_APPLICATION_DATA 23
343343
344+ #ifdef __GNUC__
345+ #define PACK ( __Declaration__ ) __Declaration__ __attribute__((__packed__))
346+ #elif defined(_MSC_VER )
347+ #define PACK ( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop))
348+ #else
349+ #error "Structure packing is not available for the used compiler."
350+ #endif
351+
344352/** Generic header structure of the DTLS record layer. */
345- typedef struct __attribute__(( __packed__ ) ) {
353+ PACK ( typedef struct ) {
346354 uint8 content_type ; /**< content type of the included message */
347355 uint16 version ; /**< Protocol version */
348356 uint16 epoch ; /**< counter for cipher state changes */
@@ -371,7 +379,7 @@ typedef struct __attribute__((__packed__)) {
371379#define DTLS_HT_NO_OPTIONAL_MESSAGE -1
372380
373381/** Header structure for the DTLS handshake protocol. */
374- typedef struct __attribute__(( __packed__ ) ) {
382+ PACK ( typedef struct ) {
375383 uint8 msg_type ; /**< Type of handshake message (one of DTLS_HT_) */
376384 uint24 length ; /**< length of this message */
377385 uint16 message_seq ; /**< Message sequence number */
@@ -381,7 +389,7 @@ typedef struct __attribute__((__packed__)) {
381389} dtls_handshake_header_t ;
382390
383391/** Structure of the Client Hello message. */
384- typedef struct __attribute__(( __packed__ ) ) {
392+ PACK ( typedef struct ) {
385393 uint16 version ; /**< Client version */
386394 uint32 gmt_random ; /**< GMT time of the random byte creation */
387395 unsigned char random [28 ]; /**< Client random bytes */
@@ -392,7 +400,7 @@ typedef struct __attribute__((__packed__)) {
392400} dtls_client_hello_t ;
393401
394402/** Structure of the Hello Verify Request. */
395- typedef struct __attribute__(( __packed__ ) ) {
403+ PACK ( typedef struct ) {
396404 uint16 version ; /**< Server version */
397405 uint8 cookie_length ; /**< Length of the included cookie */
398406 uint8 cookie []; /**< up to 32 bytes making up the cookie */
0 commit comments