From ef7cbc1ec95a141a27bc9e3f99c04d106fb3508a Mon Sep 17 00:00:00 2001 From: bol-van Date: Tue, 20 Aug 2024 20:49:52 +0300 Subject: [PATCH] tpws: is_localnet: convert network byte order --- tpws/helpers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tpws/helpers.c b/tpws/helpers.c index ea70898..7b01e85 100644 --- a/tpws/helpers.c +++ b/tpws/helpers.c @@ -167,11 +167,11 @@ bool saconvmapped(struct sockaddr_storage *a) bool is_localnet(const struct sockaddr *a) { // 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) || + return (a->sa_family==AF_INET && (IN_LOOPBACK(htonl(((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) || - (IN6_IS_ADDR_V4MAPPED(((struct sockaddr_in6 *)a)->sin6_addr.s6_addr) && (IN_LOOPBACK(IN6_EXTRACT_MAP4(((struct sockaddr_in6*)a)->sin6_addr.s6_addr)) || + (IN6_IS_ADDR_V4MAPPED(((struct sockaddr_in6 *)a)->sin6_addr.s6_addr) && (IN_LOOPBACK(htonl(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)