diff --git a/src/native/libs/System.Native/extra_libs.cmake b/src/native/libs/System.Native/extra_libs.cmake index 8a3fa8a1006abd..b9d18b61a429bc 100644 --- a/src/native/libs/System.Native/extra_libs.cmake +++ b/src/native/libs/System.Native/extra_libs.cmake @@ -9,7 +9,7 @@ macro(append_extra_system_libs NativeLibsExtra) elseif (CLR_CMAKE_TARGET_OPENBSD) list(APPEND ${NativeLibsExtra} pthread) 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 5b39e586216f98..726cad88f48d09 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -977,29 +977,44 @@ check_symbol_exists( "unistd.h;sys/types.h;sys/socket.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}) +# 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) +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 OR CLR_CMAKE_TARGET_OPENBSD))