From: Lev Stipakov Date: Tue, 14 Jul 2026 09:25:46 +0000 (+0200) Subject: buffer: Add buf_read_u64() and buf_write_u64() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e8d39061007b0a29f78cecce72a0269d6dd3ecde;p=thirdparty%2Fopenvpn.git buffer: Add buf_read_u64() and buf_write_u64() Add 64-bit big-endian buffer accessors alongside the existing 8/16/32-bit helpers, using htonll()/ntohll() for the byte-order conversion. buf_read_u64() reports success via a bool out-parameter, mirroring buf_read_u32(). Change-Id: Ic677f43fc3eb0052f8e80d9a7f098d34ad03dfe1 Signed-off-by: Lev Stipakov Acked-by: Frank Lichtenheld Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1740 Message-Id: <20260714092552.18685-1-gert@greenie.muc.de> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg37578.html Signed-off-by: Gert Doering --- diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h index fcc923b77..1db9367e6 100644 --- a/src/openvpn/buffer.h +++ b/src/openvpn/buffer.h @@ -25,6 +25,7 @@ #include "basic.h" #include "error.h" +#include "integer.h" #define BUF_SIZE_MAX 1000000 @@ -701,6 +702,13 @@ buf_write_u32(struct buffer *dest, uint32_t data) return buf_write(dest, &u32, sizeof(uint32_t)); } +static inline bool +buf_write_u64(struct buffer *dest, uint64_t data) +{ + uint64_t u64 = htonll(data); + return buf_write(dest, &u64, sizeof(uint64_t)); +} + static inline bool buf_copy(struct buffer *dest, const struct buffer *src) { @@ -827,6 +835,30 @@ buf_read_u32(struct buffer *buf, bool *good) } } +/* Read a 64-bit big-endian value (see buf_write_u64()). Sets *good to indicate + * success, like buf_read_u32(). */ +static inline uint64_t +buf_read_u64(struct buffer *buf, bool *good) +{ + uint64_t ret; + if (!buf_read(buf, &ret, sizeof(uint64_t))) + { + if (good) + { + *good = false; + } + return 0; + } + else + { + if (good) + { + *good = true; + } + return ntohll(ret); + } +} + /** Return true if buffer contents are equal */ static inline bool buf_equal(const struct buffer *a, const struct buffer *b)