Permalink
Browse files

Moving away from endian.h

  • Loading branch information...
1 parent 712132e commit 54d0d45d8d84d965cb3d02741f357e5046e4a0bc @nicolasff committed Dec 29, 2011
Showing with 20 additions and 10 deletions.
  1. +11 −10 websocket.c
  2. +9 −0 websocket.h
View
@@ -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));
}
View
@@ -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,

0 comments on commit 54d0d45

Please sign in to comment.