From abc36471d99db83c317410bc31468b275e62ef5e Mon Sep 17 00:00:00 2001 From: goldsimon Date: Tue, 4 May 2010 18:59:52 +0000 Subject: [PATCH] Fixed bug #29763 (CHECKSUM_GEN_IP_INLINE), added macro LWIP_MAKE_U16() that's improved for endianess --- src/core/ipv4/ip.c | 2 +- src/include/lwip/def.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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 */