From 479ff56a6b16f67e5a446ea95ff563b60612228e Mon Sep 17 00:00:00 2001 From: "[anp/hsw]" Date: Fri, 16 Aug 2024 09:50:26 +0700 Subject: [PATCH] fixing -Wstrict-aliasing (try 2) --- tpws/helpers.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tpws/helpers.c b/tpws/helpers.c index 0c6e24b..59849cc 100644 --- a/tpws/helpers.c +++ b/tpws/helpers.c @@ -167,9 +167,13 @@ bool saconvmapped(struct sockaddr_storage *a) bool is_localnet(const struct sockaddr *a) { - // 127.0.0.0/8, ::1 = localhost - return (a->sa_family==AF_INET && IN_LOOPBACK(((struct sockaddr_in *)a)->sin_addr.s_addr)) || - (a->sa_family==AF_INET6 && IN6_IS_ADDR_LOOPBACK(((struct sockaddr_in6 *)a)->sin6_addr.s6_addr)); + // match 127.0.0.0/8, 0.0.0.0, ::1, ::0, :ffff:127.0.0.0/104, :ffff:0.0.0.0 + return (a->sa_family==AF_INET && (IN_LOOPBACK(((struct sockaddr_in *)a)->sin_addr.s_addr) || + INADDR_ANY == (((struct sockaddr_in *)a)->sin_addr.s_addr))) || + (a->sa_family==AF_INET6 && ((IN6_IS_ADDR_LOOPBACK(((struct sockaddr_in6 *)a)->sin6_addr.s6_addr)) || + IN6_IS_ADDR_UNSPECIFIED((((struct sockaddr_in6 *)a)->sin6_addr.s6_addr)) || + (saismapped((struct sockaddr_in6 *)a) && (IN_LOOPBACK(IN6_EXTRACT_MAP4(((struct sockaddr_in6*)a)->sin6_addr.s6_addr)) || + INADDR_ANY == IN6_EXTRACT_MAP4(((struct sockaddr_in6*)a)->sin6_addr.s6_addr))))); } bool is_linklocal(const struct sockaddr_in6 *a) {