in-addr-util: introduce FAMILY_ADDRESS_SIZE_SAFE() macro

This commit is contained in:
Yu Watanabe
2021-11-25 22:34:29 +09:00
parent 9df247da28
commit f9930401d5
+7
View File
@@ -114,6 +114,13 @@ static inline size_t FAMILY_ADDRESS_SIZE(int family) {
return family == AF_INET6 ? 16 : 4;
}
#define FAMILY_ADDRESS_SIZE_SAFE(f) \
({ \
int _f = (f); \
_f == AF_INET ? sizeof(struct in_addr) : \
_f == AF_INET6 ? sizeof(struct in6_addr) : 0; \
})
/* Workaround for clang, explicitly specify the maximum-size element here.
* See also oss-fuzz#11344. */
#define IN_ADDR_NULL ((union in_addr_union) { .in6 = {} })