Moving away from endian.h

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

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

@ -7,6 +7,15 @@
struct http_client;
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 {
WS_ERROR,
WS_READING,

Loading…
Cancel
Save