From 70779e43ededd459625938bfd234b1ff2f006fca Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Sun, 24 Dec 2023 19:22:52 +0200 Subject: [PATCH] LibC: Set sin_port in network order in getaddrinfo results This is required by POSIX, and we were already doing it for the numeric service case, but not for the named service case. --- Userland/Libraries/LibC/netdb.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibC/netdb.cpp b/Userland/Libraries/LibC/netdb.cpp index 86cb9d2f1e..64b9ea32ef 100644 --- a/Userland/Libraries/LibC/netdb.cpp +++ b/Userland/Libraries/LibC/netdb.cpp @@ -891,11 +891,11 @@ int getaddrinfo(char const* __restrict node, char const* __restrict service, con if (!service_file_line.has_value()) { if (service) { char* end; - port = htons(strtol(service, &end, 10)); + port = strtol(service, &end, 10); if (*end) return EAI_FAIL; } else { - port = htons(0); + port = 0; } if (hints && hints->ai_socktype != 0) @@ -913,7 +913,7 @@ int getaddrinfo(char const* __restrict node, char const* __restrict service, con for (int host_index = 0; host_ent->h_addr_list[host_index]; host_index++) { sockaddr_in* sin = new sockaddr_in; sin->sin_family = AF_INET; - sin->sin_port = port; + sin->sin_port = htons(port); memcpy(&sin->sin_addr.s_addr, host_ent->h_addr_list[host_index], host_ent->h_length); addrinfo* info = new addrinfo;