From 9621565b74bc105b43c57ca7b41babb73eddf3a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20L=C3=A9caille?= Date: Tue, 6 Jul 2021 14:34:46 +0200 Subject: [PATCH] MINOR: net_helper: add functions for pointers Add two functions to read/write pointer values to/from vectors. --- include/haproxy/net_helper.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/haproxy/net_helper.h b/include/haproxy/net_helper.h index 8b9f68b40..f019d30ff 100644 --- a/include/haproxy/net_helper.h +++ b/include/haproxy/net_helper.h @@ -75,6 +75,22 @@ static inline void write_u64(void *p, const uint64_t u64) u->u64 = u64; } +/* Read a void* in native host order */ +static inline void *read_ptr(const void *p) +{ + const union { void *ptr; } __attribute__((packed))*u = p; + return u->ptr; +} + +/* Write a void* in native host order */ +static inline void write_ptr(void *p, const void *ptr) +{ + if (sizeof(ptr) == 4) + return write_u32(p, (uintptr_t)ptr); + else + return write_u64(p, (uintptr_t)ptr); +} + /* Read a possibly wrapping number of bytes into destination . The * first segment is composed of bytes at p1. The remaining byte(s), if any, * are read from . may be zero and may also be larger than . The