Skip to content

Commit 2c7e1bb

Browse files
committed
Fix endianness detection in nxt_websocket_header_t.
The nxt_websocket_header_t structure defines the layout of a websocket frame header. As the websocket frame is mapped directly onto this structure its layout needs to match how it's coming off the network. The network being big endian means on big endian systems the structure layout can simply match that of the websocket frame header. On little endian systems we need to reverse the two bytes. This was done via the BYTE_ORDER, BIG_ENDIAN and LITTLE_ENDIAN macros, however these are not universal, e.g they are _not_ defined on illumos (OpenSolaris / OpenIndiana) and so we get the following compiler errors In file included from src/nxt_h1proto.c:12:0: src/nxt_websocket_header.h:25:13: error: duplicate member 'opcode' uint8_t opcode:4; ^~~~~~ src/nxt_websocket_header.h:26:13: error: duplicate member 'rsv3' uint8_t rsv3:1; ^~~~ src/nxt_websocket_header.h:27:13: error: duplicate member 'rsv2' uint8_t rsv2:1; ^~~~ src/nxt_websocket_header.h:28:13: error: duplicate member 'rsv1' uint8_t rsv1:1; ^~~~ src/nxt_websocket_header.h:29:13: error: duplicate member 'fin' uint8_t fin:1; ^~~ src/nxt_websocket_header.h:31:13: error: duplicate member 'payload_len' uint8_t payload_len:7; ^~~~~~~~~~~ src/nxt_websocket_header.h:32:13: error: duplicate member 'mask' uint8_t mask:1; ^~~~ This commit fixes that by using the new NXT_HAVE_{BIG,LITTLE}_ENDIAN macros introduced in the previous commit. Closes: <#297> Fixes: e501c74 ("Introducing websocket support in router and libunit.") Reviewed-by: Alejandro Colomar <alx@nginx.com> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
1 parent ead3580 commit 2c7e1bb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/nxt_websocket_header.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
typedef struct {
13-
#if (BYTE_ORDER == BIG_ENDIAN)
13+
#if (NXT_HAVE_BIG_ENDIAN)
1414
uint8_t fin:1;
1515
uint8_t rsv1:1;
1616
uint8_t rsv2:1;
@@ -21,7 +21,7 @@ typedef struct {
2121
uint8_t payload_len:7;
2222
#endif
2323

24-
#if (BYTE_ORDER == LITTLE_ENDIAN)
24+
#if (NXT_HAVE_LITTLE_ENDIAN)
2525
uint8_t opcode:4;
2626
uint8_t rsv3:1;
2727
uint8_t rsv2:1;

0 commit comments

Comments
 (0)