From 2912b4dadbaba99fdb0743b2af4600419b7b1264 Mon Sep 17 00:00:00 2001 From: Pasukhin Dmitry Date: Sun, 23 Mar 2025 15:52:48 +0000 Subject: [PATCH] Foundation Classes - Host resolving by itself #457 Fixed issue when gethostbyname returns a nullptr, because the host can't resolve itself --- src/FoundationClasses/TKernel/OSD/OSD_Host.cxx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/FoundationClasses/TKernel/OSD/OSD_Host.cxx b/src/FoundationClasses/TKernel/OSD/OSD_Host.cxx index ea8b563acf..57a263f084 100644 --- a/src/FoundationClasses/TKernel/OSD/OSD_Host.cxx +++ b/src/FoundationClasses/TKernel/OSD/OSD_Host.cxx @@ -139,8 +139,13 @@ TCollection_AsciiString OSD_Host::InternetAddress() char buffer[16]; TCollection_AsciiString result, host; - host = HostName(); - memcpy(&internet_address, gethostbyname(host.ToCString()), sizeof(struct hostent)); + host = HostName(); + const auto* aHostByName = gethostbyname(host.ToCString()); + if (aHostByName == nullptr) + { + aHostByName = gethostbyname("localhost"); + } + memcpy(&internet_address, aHostByName, sizeof(struct hostent)); // Gets each bytes into integers a = (unsigned char)internet_address.h_addr_list[0][0];