diff --git a/src/core/ipv4/ip.c b/src/core/ipv4/ip.c index fcca17c6..e780175d 100644 --- a/src/core/ipv4/ip.c +++ b/src/core/ipv4/ip.c @@ -597,7 +597,7 @@ err_t ip_output_if_opt(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, IPH_TTL_SET(iphdr, ttl); IPH_PROTO_SET(iphdr, proto); #if CHECKSUM_GEN_IP_INLINE - chk_sum = (proto << 8) | ttl; + chk_sum = LWIP_MAKE_U16(proto, ttl); #endif /* CHECKSUM_GEN_IP_INLINE */ /* dest cannot be NULL here */ diff --git a/src/include/lwip/def.h b/src/include/lwip/def.h index b500af2c..52d511af 100644 --- a/src/include/lwip/def.h +++ b/src/include/lwip/def.h @@ -47,6 +47,12 @@ extern "C" { #define NULL ((void *)0) #endif +#if BYTE_ORDER == LITTLE_ENDIAN +#define LWIP_MAKE_U16(a, b) ((a << 8) | b) +#else +#define LWIP_MAKE_U16(a, b) ((b << 8) | a) +#endif + #ifdef htons #undef htons #endif /* htons */