chiark / gitweb /
portability: Work around Apple's bizarrely deficient poll() implementation.
[secnet.git] / unaligned.h
index 45b0d3c079319e5e31b7c5c5da43b98a7ba9d1cf..a15043e56597eb4ad85ffb01391006c0ffaf5902 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef unaligned_h
 #define unaligned_h
 
+#include <stdint.h>
+
 /* Parts of the secnet key-exchange protocol require access to
    unaligned big-endian quantities in buffers. These macros provide
    convenient access, even on architectures that don't support unaligned
 
 #define put_uint16(a,v) do {(a)[0]=((v)&0xff00)>>8; (a)[1]=(v)&0xff;} while(0)
 
-#define get_uint32(a) (((a)[0]<<24)|((a)[1]<<16)|((a)[2])<<8|(a)[3])
+#define get_uint32(a)                                  \
+  (((uint32_t)(a)[0]<<24) | ((uint32_t)(a)[1]<<16) |   \
+   ((uint32_t)(a)[2]<<8)  |  (uint32_t)(a)[3])
 
-#define get_uint16(a) (((a)[0]<<8)|(a)[1])
+#define get_uint16(a) (((uint16_t)(a)[0]<<8)|(uint16_t)(a)[1])
 
 #define buf_append_uint32(buf,v) do { uint8_t *c=buf_append((buf),4); \
     put_uint32(c,(v)); } while(0)