Skip to content

Commit 207260a

Browse files
Inet implementations assume BYTE_ORDER is defined. make sure that it is (project-chip#26460)
* BYTE_ORDER must be defined in the project * fix typo * Remove BYTE_ORDER from the file. Only use __BYTE_ORDER__ and relative checks * Apply suggestions from code review Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> --------- Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent ec11881 commit 207260a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/inet/arpa-inet-compatibility.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#else // !CHIP_SYSTEM_CONFIG_USE_SOCKETS
2727

2828
#if CHIP_SYSTEM_CONFIG_USE_LWIP
29-
3029
#include <lwip/def.h>
3130
#include <lwip/opt.h>
3231

@@ -49,7 +48,11 @@
4948

5049
#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
5150

52-
#if BYTE_ORDER == BIG_ENDIAN
51+
#ifndef __BYTE_ORDER__
52+
#error Endianness is not defined
53+
#endif // BYTE_ORDER
54+
55+
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
5356
#ifndef htons
5457
#define htons(x) (x)
5558
#endif
@@ -63,7 +66,7 @@
6366
#define ntohl(x) (x)
6467
#endif
6568

66-
#else // BYTE_ORDER != BIG_ENDIAN
69+
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
6770
#ifndef htons
6871
#define htons(x) ((u16_t)((((x) & (u16_t) 0x00ffU) << 8) | (((x) & (u16_t) 0xff00U) >> 8)))
6972
#endif
@@ -78,7 +81,10 @@
7881
#ifndef ntohl
7982
#define ntohl(x) htonl(x)
8083
#endif
81-
#endif // BYTE_ORDER == BIG_ENDIAN
84+
85+
#else
86+
#error __BYTE_ORDER__ value not recognized
87+
#endif // __BYTE_ORDER__ ==
8288

8389
#endif // CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
8490

0 commit comments

Comments
 (0)