From f31641369fa75e7b420c1f925cdf16503e974c42 Mon Sep 17 00:00:00 2001 From: Gordon Ross Date: Mon, 2 Mar 2026 00:01:14 -0500 Subject: [PATCH 1/2] Fix getdomainname for SunOS --- .../libs/System.Native/extra_libs.cmake | 2 +- .../libs/System.Native/pal_networking.c | 4 ++ src/native/libs/configure.cmake | 55 ++++++++++++------- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/native/libs/System.Native/extra_libs.cmake b/src/native/libs/System.Native/extra_libs.cmake index 68c2c128105b50..df3a6136c66fa5 100644 --- a/src/native/libs/System.Native/extra_libs.cmake +++ b/src/native/libs/System.Native/extra_libs.cmake @@ -7,7 +7,7 @@ macro(append_extra_system_libs NativeLibsExtra) find_library(INOTIFY_LIBRARY inotify HINTS ${CROSS_ROOTFS}/usr/local/lib) list(APPEND ${NativeLibsExtra} ${INOTIFY_LIBRARY}) elseif (CLR_CMAKE_TARGET_SUNOS) - list(APPEND ${NativeLibsExtra} socket) + list(APPEND ${NativeLibsExtra} socket nsl) elseif (CLR_CMAKE_TARGET_HAIKU) list (APPEND ${NativeLibsExtra} network bsd) endif () diff --git a/src/native/libs/System.Native/pal_networking.c b/src/native/libs/System.Native/pal_networking.c index 3b460d4c4e8296..1c2ad8643bca27 100644 --- a/src/native/libs/System.Native/pal_networking.c +++ b/src/native/libs/System.Native/pal_networking.c @@ -52,6 +52,10 @@ #include #endif #include +#if defined(TARGET_SUNOS) && HAVE_GETDOMAINNAME +// SunOS has getdomainname in libnsl but no header declaration +extern int getdomainname(char *name, int namelen); +#endif #ifdef HAVE_PWD_H #include #endif diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake index 4da74e115c6db8..a8ea3ce052c22f 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -978,29 +978,44 @@ check_symbol_exists( unistd.h HAVE_GETPEEREID) -check_symbol_exists( - getdomainname - unistd.h - HAVE_GETDOMAINNAME) +set (PREVIOUS_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) +if (CLR_CMAKE_TARGET_SUNOS) + # On SunOS, getdomainname is in libnsl but not declared in any header + set(CMAKE_REQUIRED_LIBRARIES socket nsl) + check_function_exists( + getdomainname + HAVE_GETDOMAINNAME) +else() + check_symbol_exists( + getdomainname + unistd.h + HAVE_GETDOMAINNAME) +endif() # getdomainname on OSX takes an 'int' instead of a 'size_t' # check if compiling with 'size_t' would cause a warning -set (PREVIOUS_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) -set (CMAKE_REQUIRED_FLAGS "-Werror -Weverything") -check_c_source_compiles( - " - #include - int main(void) - { - size_t namelen = 20; - char name[20]; - int dummy = getdomainname(name, namelen); - (void)dummy; - return 0; - } - " - HAVE_GETDOMAINNAME_SIZET) -set (CMAKE_REQUIRED_FLAGS ${PREVIOUS_CMAKE_REQUIRED_FLAGS}) +if (CLR_CMAKE_TARGET_SUNOS) + # SunOS uses int, not size_t + set (HAVE_GETDOMAINNAME_SIZET 0) +else() + set (PREVIOUS_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set (CMAKE_REQUIRED_FLAGS "-Werror -Weverything") + check_c_source_compiles( + " + #include + int main(void) + { + size_t namelen = 20; + char name[20]; + int dummy = getdomainname(name, namelen); + (void)dummy; + return 0; + } + " + HAVE_GETDOMAINNAME_SIZET) + set (CMAKE_REQUIRED_FLAGS ${PREVIOUS_CMAKE_REQUIRED_FLAGS}) +endif() +set (CMAKE_REQUIRED_LIBRARIES ${PREVIOUS_CMAKE_REQUIRED_LIBRARIES}) set (PREVIOUS_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) if (HAVE_SYS_INOTIFY_H AND CLR_CMAKE_TARGET_FREEBSD) From 715ecb5a42fbbc86d01e8ec900aa05a98459c3ff Mon Sep 17 00:00:00 2001 From: Radek Zikmund <32671551+rzikm@users.noreply.github.com> Date: Mon, 16 Mar 2026 11:53:50 +0100 Subject: [PATCH 2/2] Apply code review suggestion Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/native/libs/configure.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake index 03974f4c652b8f..726cad88f48d09 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -991,8 +991,8 @@ else() HAVE_GETDOMAINNAME) endif() -# getdomainname on OSX takes an 'int' instead of a 'size_t' -# check if compiling with 'size_t' would cause a warning +# Some platforms (e.g. macOS, SunOS) define getdomainname with an 'int' length parameter +# Check whether using 'size_t' for the length parameter would cause a warning if (CLR_CMAKE_TARGET_SUNOS) # SunOS uses int, not size_t set (HAVE_GETDOMAINNAME_SIZET 0)