From: Yu Watanabe Date: Sat, 8 Jul 2023 03:23:27 +0000 (+0900) Subject: in-addr-util: introduce PTR_TO_IN4_ADDR() and IN4_ADDR_TO_PTR() X-Git-Tag: v255-rc1~884^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9701be563ac6413a93451c53957102201b00a8af;p=thirdparty%2Fsystemd.git in-addr-util: introduce PTR_TO_IN4_ADDR() and IN4_ADDR_TO_PTR() These should be useful when an IPv4 address is used as a key of a hashmap. --- diff --git a/src/basic/in-addr-util.h b/src/basic/in-addr-util.h index 95e73162b13..12720ca92f2 100644 --- a/src/basic/in-addr-util.h +++ b/src/basic/in-addr-util.h @@ -195,6 +195,16 @@ extern const struct hash_ops in_addr_data_hash_ops_free; extern const struct hash_ops in6_addr_hash_ops; extern const struct hash_ops in6_addr_hash_ops_free; +static inline void PTR_TO_IN4_ADDR(const void *p, struct in_addr *ret) { + assert(ret); + ret->s_addr = (uint32_t) ((uintptr_t) p); +} + +static inline void* IN4_ADDR_TO_PTR(const struct in_addr *a) { + assert(a); + return (void*) ((uintptr_t) a->s_addr); +} + #define IPV4_ADDRESS_FMT_STR "%u.%u.%u.%u" #define IPV4_ADDRESS_FMT_VAL(address) \ be32toh((address).s_addr) >> 24, \