Moving away from endian.h

master
Nicolas Favre-Felix 13 years ago
parent 712132ebc2
commit 54d0d45d8d

@ -18,13 +18,16 @@
#include <sys/param.h> #include <sys/param.h>
#ifdef __APPLE__ #ifdef __APPLE__
#include <machine/endian.h> # include <machine/endian.h>
#else #elif defined(__linux__)
#ifdef BSD /* depends on sys/param.h */ # include <endian.h>
#include <sys/endian.h> #elif defined(__FreeBSD__) || defined(__NetBSD__)
#else # include <sys/endian.h>
#include <endian.h> #elif defined(__OpenBSD__)
#endif # include <sys/types.h>
# define be16toh(x) betoh16(x)
# define be32toh(x) betoh32(x)
# define be64toh(x) betoh64(x)
#endif #endif
/** /**
@ -260,9 +263,7 @@ ws_parse_data(const char *frame, size_t sz, struct ws_msg **msg) {
p = frame + 4 + (has_mask ? 4 : 0); p = frame + 4 + (has_mask ? 4 : 0);
if(has_mask) memcpy(&mask, frame + 4, sizeof(mask)); if(has_mask) memcpy(&mask, frame + 4, sizeof(mask));
} else if(len == 127) { } else if(len == 127) {
uint64_t sz64; len = ntohl64(frame+2);
memcpy(&sz64, frame + 2, sizeof(uint64_t));
len = be64toh(sz64);
p = frame + 10 + (has_mask ? 4 : 0); p = frame + 10 + (has_mask ? 4 : 0);
if(has_mask) memcpy(&mask, frame + 10, sizeof(mask)); if(has_mask) memcpy(&mask, frame + 10, sizeof(mask));
} }

@ -7,6 +7,15 @@
struct http_client; struct http_client;
struct cmd; struct cmd;
#define ntohl64(p) ((p)[0] +\
(((int64_t)((p)[1])) << 8) +\
(((int64_t)((p)[2])) << 16) +\
(((int64_t)((p)[3])) << 24) +\
(((int64_t)((p)[4])) << 32) +\
(((int64_t)((p)[5])) << 40) +\
(((int64_t)((p)[6])) << 48) +\
(((int64_t)((p)[7])) << 56))
enum ws_state { enum ws_state {
WS_ERROR, WS_ERROR,
WS_READING, WS_READING,

Loading…
Cancel
Save