From cd432860d85e8a98b6ab5e94b916293914006833 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 19 Apr 2021 20:33:33 +0200 Subject: [PATCH] LibC: Additional functionality for getaddrinfo() When node is NULL and AI_PASSIVE is specified we are supposed to use the "any" address, otherwise we should use the loopback address. --- Userland/Libraries/LibC/netdb.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Userland/Libraries/LibC/netdb.cpp b/Userland/Libraries/LibC/netdb.cpp index 7231a1ac69..cd43bb834b 100644 --- a/Userland/Libraries/LibC/netdb.cpp +++ b/Userland/Libraries/LibC/netdb.cpp @@ -667,6 +667,13 @@ int getaddrinfo(const char* __restrict node, const char* __restrict service, con if (hints && hints->ai_family != AF_INET && hints->ai_family != AF_UNSPEC) return EAI_FAMILY; + if (!node) { + if (hints && hints->ai_flags & AI_PASSIVE) + node = "0.0.0.0"; + else + node = "127.0.0.1"; + } + auto host_ent = gethostbyname(node); if (!host_ent) return EAI_FAIL;