diff options
author | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2015-11-24 15:21:11 +0100 |
---|---|---|
committer | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2015-11-24 15:21:11 +0100 |
commit | 90f78507f4a13673ccf0ba7c786b43d9e882fca7 (patch) | |
tree | e7881d0b56a45609514a4aa9f75873fcad813f0e /lib/unaligned.h | |
parent | 8eb8e546dc8cc647fcfa4a3a17dfa8ab36b00958 (diff) | |
parent | ad27615760e2795da3efe5e97c0e888281d5ca59 (diff) |
Merge branch 'master' into rip-new
Diffstat (limited to 'lib/unaligned.h')
-rw-r--r-- | lib/unaligned.h | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/unaligned.h b/lib/unaligned.h index af655204..dc777fbf 100644 --- a/lib/unaligned.h +++ b/lib/unaligned.h @@ -20,7 +20,7 @@ #include "lib/string.h" static inline u16 -get_u16(void *p) +get_u16(const void *p) { u16 x; memcpy(&x, p, 2); @@ -28,13 +28,22 @@ get_u16(void *p) } static inline u32 -get_u32(void *p) +get_u32(const void *p) { u32 x; memcpy(&x, p, 4); return ntohl(x); } +static inline u64 +get_u64(const void *p) +{ + u32 xh, xl; + memcpy(&xh, p, 4); + memcpy(&xl, p+4, 4); + return (((u64) ntohl(xh)) << 32) | ntohl(xl); +} + static inline void put_u16(void *p, u16 x) { @@ -49,4 +58,14 @@ put_u32(void *p, u32 x) memcpy(p, &x, 4); } +static inline void +put_u64(void *p, u64 x) +{ + u32 xh, xl; + xh = htonl(x >> 32); + xl = htonl((u32) x); + memcpy(p, &xh, 4); + memcpy(p+4, &xl, 4); +} + #endif |