From 88074f8eeb84fc87eeb2c408d3b90c4977e3f188 Mon Sep 17 00:00:00 2001 From: rcbellN51 <130078525+rcbellN51@users.noreply.github.com> Date: Wed, 7 Jan 2026 07:58:58 -0600 Subject: [PATCH] illumos/SunOS: fix gethostbyname_r and link socket/nsl --- CMakeLists.txt | 4 ++++ SpeedTestClient.cpp | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f8b4d34..05f0c2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,10 @@ include_directories("${PROJECT_BINARY_DIR}") add_executable(SpeedTest ${SOURCE_FILES}) +if(CMAKE_SYSTEM_NAME STREQUAL "SunOS") + target_link_libraries(SpeedTest socket nsl) +endif() + INCLUDE (CheckIncludeFiles) find_package(CURL REQUIRED) find_package(LibXml2 REQUIRED) diff --git a/SpeedTestClient.cpp b/SpeedTestClient.cpp index 39ffc14..c29b399 100644 --- a/SpeedTestClient.cpp +++ b/SpeedTestClient.cpp @@ -189,6 +189,18 @@ bool SpeedTestClient::mkSocket() { if (server == nullptr) { return false; } +#elif defined(__sun) || defined(__illumos__) + struct hostent server; + char tmpbuf[BUFSIZ]; + int errnop = 0; + + /* illumos/Solaris: gethostbyname_r returns hostent* and takes (.., int *h_errnop) */ + struct hostent *result = gethostbyname_r( + hostp.first.c_str(), &server, (char *)&tmpbuf, BUFSIZ, &errnop + ); + if (result == nullptr) { + return false; + } #else struct hostent server; char tmpbuf[BUFSIZ];