mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-11-17 16:48:43 +00:00
Add get_u64() and put_u64() into lib/unaligned.h
This commit is contained in:
parent
fce764f90e
commit
75ff08022e
@ -35,6 +35,15 @@ get_u32(void *p)
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user