byteorder: Add helpers to read from unaligned addresses without byte order changes

While utoh32/64 would also have been an option for the name, this is
more distinct to avoid confusion with the existing conversion functions.
This commit is contained in:
Tobias Brunner
2026-07-24 08:47:35 +02:00
parent d19591edda
commit d13b384536
+29 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008-2014 Tobias Brunner
* Copyright (C) 2008-2026 Tobias Brunner
* Copyright (C) 2008 Martin Willi
*
* Copyright (C) secunet Security Networks AG
@@ -246,4 +246,32 @@ static inline void htoule32(void *p, uint32_t v)
memcpy(p, &v, sizeof(v));
}
/**
* Read a 32-bit value from an unaligned address without byte order conversion.
*
* @param p unaligned address to read value from
* @return host order value
*/
static inline uint32_t uread32(void *p)
{
uint32_t ret;
memcpy(&ret, p, sizeof(ret));
return ret;
}
/**
* Read a 64-bit value from an unaligned address without byte order conversion.
*
* @param p unaligned address to read value from
* @return host order value
*/
static inline uint64_t uread64(void *p)
{
uint64_t ret;
memcpy(&ret, p, sizeof(ret));
return ret;
}
#endif /** BYTEORDER_H_ @} */