From d13b384536f6b2265025801abeec272c6df4f47d Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Fri, 19 Jun 2026 15:46:24 +0200 Subject: [PATCH] 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. --- src/libstrongswan/utils/utils/byteorder.h | 30 ++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/libstrongswan/utils/utils/byteorder.h b/src/libstrongswan/utils/utils/byteorder.h index af000615b..a0c81e14c 100644 --- a/src/libstrongswan/utils/utils/byteorder.h +++ b/src/libstrongswan/utils/utils/byteorder.h @@ -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_ @} */