6 /* Parts of the secnet key-exchange protocol require access to
7 unaligned big-endian quantities in buffers. These macros provide
8 convenient access, even on architectures that don't support unaligned
11 #define put_uint32(a,v) do { (a)[0]=(v)>>24; (a)[1]=((v)&0xff0000)>>16; \
12 (a)[2]=((v)&0xff00)>>8; (a)[3]=(v)&0xff; } while(0)
14 #define put_uint16(a,v) do {(a)[0]=((v)&0xff00)>>8; (a)[1]=(v)&0xff;} while(0)
16 #define get_uint32(a) \
17 (((uint32_t)(a)[0]<<24) | ((uint32_t)(a)[1]<<16) | \
18 ((uint32_t)(a)[2]<<8) | (uint32_t)(a)[3])
20 #define get_uint16(a) (((uint16_t)(a)[0]<<8)|(uint16_t)(a)[1])
22 #define buf_append_uint32(buf,v) do { uint8_t *c=buf_append((buf),4); \
23 put_uint32(c,(v)); } while(0)
25 #define buf_append_uint16(buf,v) do { uint8_t *c=buf_append((buf),2); \
26 put_uint16(c,(v)); } while(0)
28 #define buf_prepend_uint32(buf,v) do { uint8_t *c=buf_prepend((buf),4); \
29 put_uint32(c,(v)); } while(0)
31 #define buf_prepend_uint16(buf,v) do { uint8_t *c=buf_prepend((buf),2); \
32 put_uint16(c,(v)); } while(0)
34 #define buf_unappend_uint32(buf) ({uint8_t *c=buf_unappend((buf),4); \
37 #define buf_unappend_uint16(buf) ({uint8_t *c=buf_unappend((buf),2); \
40 #define buf_unprepend_uint32(buf) ({uint8_t *c=buf_unprepend((buf),4); \
43 #define buf_unprepend_uint16(buf) ({uint8_t *c=buf_unprepend((buf),2); \
46 #endif /* unaligned_h */