From 1d71fdaf6b556546c6867bf7c6cdb0618a782e37 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 14 May 2022 16:36:28 +0200 Subject: Fix bitfields order for MSVC It uses a saner strictly "from low to high bit" rule. --- src/ip.h | 4 ++-- src/ip6.h | 13 +++++++------ src/ip6_icmp.c | 5 +++-- src/ip6_icmp.h | 14 ++++++++------ src/tcp.h | 2 +- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/ip.h b/src/ip.h index 2daa344..bfe1d36 100644 --- a/src/ip.h +++ b/src/ip.h @@ -73,7 +73,7 @@ typedef uint32_t n_long; /* long as received from the net */ */ SLIRP_PACKED_BEGIN struct ip { -#if G_BYTE_ORDER == G_BIG_ENDIAN +#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) uint8_t ip_v : 4, /* version */ ip_hl : 4; /* header length */ #else @@ -140,7 +140,7 @@ struct ip_timestamp { uint8_t ipt_code; /* IPOPT_TS */ uint8_t ipt_len; /* size of structure (variable) */ uint8_t ipt_ptr; /* index of current entry */ -#if G_BYTE_ORDER == G_BIG_ENDIAN +#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) uint8_t ipt_oflw : 4, /* overflow counter */ ipt_flg : 4; /* flags, see below */ #else diff --git a/src/ip6.h b/src/ip6.h index 0630309..96d3e2f 100644 --- a/src/ip6.h +++ b/src/ip6.h @@ -176,14 +176,15 @@ static inline void in6_compute_ethaddr(struct in6_addr ip, * Structure of an internet header, naked of options. */ struct ip6 { -#if G_BYTE_ORDER == G_BIG_ENDIAN - uint32_t ip_v : 4, /* version */ - ip_tc_hi : 4, /* traffic class */ - ip_tc_lo : 4, ip_fl_hi : 4, /* flow label */ - ip_fl_lo : 16; +#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) + uint8_t ip_v : 4, /* version */ + ip_tc_hi : 4; /* traffic class */ + uint8_t ip_tc_lo : 4, ip_fl_hi : 4; /* flow label */ #else - uint32_t ip_tc_hi : 4, ip_v : 4, ip_fl_hi : 4, ip_tc_lo : 4, ip_fl_lo : 16; + uint8_t ip_tc_hi : 4, ip_v : 4; + uint8_t ip_fl_hi : 4, ip_tc_lo : 4; #endif + uint16_t ip_fl_lo; uint16_t ip_pl; /* payload length */ uint8_t ip_nh; /* next header */ uint8_t ip_hl; /* hop limit */ diff --git a/src/ip6_icmp.c b/src/ip6_icmp.c index 0d7ee69..3168457 100644 --- a/src/ip6_icmp.c +++ b/src/ip6_icmp.c @@ -294,8 +294,9 @@ static void ndp_send_na(Slirp *slirp, struct ip6 *ip, struct icmp6 *icmp) ricmp->icmp6_nna.R = NDP_IsRouter; ricmp->icmp6_nna.S = !IN6_IS_ADDR_MULTICAST(&rip->ip_dst); ricmp->icmp6_nna.O = 1; - ricmp->icmp6_nna.reserved_hi = 0; - ricmp->icmp6_nna.reserved_lo = 0; + ricmp->icmp6_nna.reserved_1 = 0; + ricmp->icmp6_nna.reserved_2 = 0; + ricmp->icmp6_nna.reserved_3 = 0; ricmp->icmp6_nna.target = icmp->icmp6_nns.target; /* Build NDP option */ diff --git a/src/ip6_icmp.h b/src/ip6_icmp.h index 76517b3..9ae6266 100644 --- a/src/ip6_icmp.h +++ b/src/ip6_icmp.h @@ -35,7 +35,7 @@ struct ndp_rs { /* Router Solicitation Message */ struct ndp_ra { /* Router Advertisement Message */ uint8_t chl; /* Cur Hop Limit */ -#if G_BYTE_ORDER == G_BIG_ENDIAN +#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) uint8_t M : 1, O : 1, reserved : 6; #else uint8_t reserved : 6, O : 1, M : 1; @@ -55,14 +55,16 @@ struct ndp_ns { /* Neighbor Solicitation Message */ G_STATIC_ASSERT(sizeof(struct ndp_ns) == 20); struct ndp_na { /* Neighbor Advertisement Message */ -#if G_BYTE_ORDER == G_BIG_ENDIAN - uint32_t R : 1, /* Router Flag */ +#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) + uint8_t R : 1, /* Router Flag */ S : 1, /* Solicited Flag */ O : 1, /* Override Flag */ - reserved_hi : 5, reserved_lo : 24; + reserved_1 : 5 #else - uint32_t reserved_hi : 5, O : 1, S : 1, R : 1, reserved_lo : 24; + uint8_t reserved_1 : 5, O : 1, S : 1, R : 1; #endif + uint8_t reserved_2; + uint16_t reserved_3; struct in6_addr target; /* Target Address */ }; @@ -125,7 +127,7 @@ struct ndpopt { SLIRP_PACKED_BEGIN struct prefixinfo { /* Prefix Information */ uint8_t prefix_length; -#if G_BYTE_ORDER == G_BIG_ENDIAN +#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) uint8_t L : 1, A : 1, reserved1 : 6; #else uint8_t reserved1 : 6, A : 1, L : 1; diff --git a/src/tcp.h b/src/tcp.h index 70a9760..f678eae 100644 --- a/src/tcp.h +++ b/src/tcp.h @@ -55,7 +55,7 @@ struct tcphdr { uint16_t th_dport; /* destination port */ tcp_seq th_seq; /* sequence number */ tcp_seq th_ack; /* acknowledgement number */ -#if G_BYTE_ORDER == G_BIG_ENDIAN +#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) uint8_t th_off : 4, /* data offset */ th_x2 : 4; /* (unused) */ #else -- cgit v1.1