diff --git a/hw/net/net_tx_pkt.c b/hw/net/net_tx_pkt.c index e29c881bc2c8a5e0968cf453115a92cf44d23fee..162f802dd77e09b89c0cb65583e82ddfcc1d3487 100644 --- a/hw/net/net_tx_pkt.c +++ b/hw/net/net_tx_pkt.c @@ -205,7 +205,7 @@ static bool net_tx_pkt_parse_headers(struct NetTxPkt *pkt) return false; } - pkt->l4proto = ((struct ip_header *) l3_hdr->iov_base)->ip_p; + pkt->l4proto = IP_HDR_GET_P(l3_hdr->iov_base); if (IP_HDR_GET_LEN(l3_hdr->iov_base) != sizeof(struct ip_header)) { /* copy optional IPv4 header data if any*/ diff --git a/include/net/eth.h b/include/net/eth.h index 09054a506d6e7dfeb59729c29054a37d1391eefe..e6dc8a7ba06fcfc7b36e18b5e0bda47662068f04 100644 --- a/include/net/eth.h +++ b/include/net/eth.h @@ -194,7 +194,9 @@ struct tcp_hdr { #define PKT_GET_IP_HDR(p) \ ((struct ip_header *)(((uint8_t *)(p)) + eth_get_l2_hdr_length(p))) #define IP_HDR_GET_LEN(p) \ - ((((struct ip_header *)(p))->ip_ver_len & 0x0F) << 2) + ((ldub_p(p + offsetof(struct ip_header, ip_ver_len)) & 0x0F) << 2) +#define IP_HDR_GET_P(p) \ + (ldub_p(p + offsetof(struct ip_header, ip_p))) #define PKT_GET_IP_HDR_LEN(p) \ (IP_HDR_GET_LEN(PKT_GET_IP_HDR(p))) #define PKT_GET_IP6_HDR(p) \