From 5aa99ecb01be38a81301051be222568aa37b6507 Mon Sep 17 00:00:00 2001 From: DcruBro Date: Mon, 27 Jul 2026 12:31:03 +0200 Subject: [PATCH] Change functions IsValidIPv4/v6 to use addrinfo instead of custom logic --- include/utils.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/include/utils.h b/include/utils.h index 8c60a7a..3e7f0c7 100644 --- a/include/utils.h +++ b/include/utils.h @@ -258,9 +258,14 @@ static inline bool IsValidIPv4(const char* ip) { struct addrinfo hints, *res; int status; + if (!ip || *ip == '\0') { + return false; + } + memset(&hints, 0, sizeof hints); hints.ai_family = AF_INET; // Only IPv4 - hints.ai_socktype = AI_NUMERICHOST; // Only numeric addresses + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_NUMERICHOST; // Only numeric addresses, no DNS lookups status = getaddrinfo(ip, NULL, &hints, &res); if (status == 0) { @@ -274,9 +279,14 @@ static inline bool IsValidIPv6(const char* ip) { struct addrinfo hints, *res; int status; + if (!ip || *ip == '\0') { + return false; + } + memset(&hints, 0, sizeof hints); hints.ai_family = AF_INET6; // Only IPv6 - hints.ai_socktype = AI_NUMERICHOST; // Only numeric addresses + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_NUMERICHOST; // Only numeric addresses, no DNS lookups status = getaddrinfo(ip, NULL, &hints, &res); if (status == 0) {