diff --git a/CMakeLists.txt b/CMakeLists.txt index 4badbe996..ffdc01c3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -807,7 +807,11 @@ endif() option(ENABLE_UNIX_SOCKETS "Define if you want Unix domain sockets support" ON) if(ENABLE_UNIX_SOCKETS) include(CheckStructHasMember) - check_struct_has_member("struct sockaddr_un" sun_path "sys/un.h" USE_UNIX_SOCKETS) + if(WIN32) + set(USE_UNIX_SOCKETS ON) + else() + check_struct_has_member("struct sockaddr_un" sun_path "sys/un.h" USE_UNIX_SOCKETS) + endif() else() unset(USE_UNIX_SOCKETS CACHE) endif() diff --git a/lib/config-win32.h b/lib/config-win32.h index 317513324..244e5ae72 100644 --- a/lib/config-win32.h +++ b/lib/config-win32.h @@ -678,22 +678,8 @@ Vista #define USE_WIN32_CRYPTO #endif -/* On MinGW the ADDRESS_FAMILY typedef was committed alongside LUP_SECURE, - so we use it to check for the presence of the typedef. */ -#include -#if !defined(__MINGW32__) || defined(LUP_SECURE) /* Define to use Unix sockets. */ #define USE_UNIX_SOCKETS -#if !defined(UNIX_PATH_MAX) - /* Replicating logic present in afunix.h of newer Windows 10 SDK versions */ -# define UNIX_PATH_MAX 108 - /* !checksrc! disable TYPEDEFSTRUCT 1 */ - typedef struct sockaddr_un { - ADDRESS_FAMILY sun_family; - char sun_path[UNIX_PATH_MAX]; - } SOCKADDR_UN, *PSOCKADDR_UN; -#endif -#endif /* ---------------------------------------------------------------- */ /* ADDITIONAL DEFINITIONS */ diff --git a/lib/curl_addrinfo.c b/lib/curl_addrinfo.c index 1d5067bc0..842fd7fe2 100644 --- a/lib/curl_addrinfo.c +++ b/lib/curl_addrinfo.c @@ -50,12 +50,6 @@ # define in_addr_t unsigned long #endif -#if defined(USE_UNIX_SOCKETS) && defined(WINAPI_FAMILY) && \ - (WINAPI_FAMILY == WINAPI_FAMILY_APP) - /* Required for sockaddr_un type */ -# include -#endif - #include #include "curl_addrinfo.h" diff --git a/lib/curl_setup.h b/lib/curl_setup.h index 85139c8d9..4382aeed2 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -824,4 +824,20 @@ int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf, #define ENABLE_QUIC #endif +#if defined(USE_UNIX_SOCKETS) && defined(WIN32) +# if defined(__MINGW32__) && !defined(LUP_SECURE) + typedef u_short ADDRESS_FAMILY; /* Classic mingw, 11y+ old mingw-w64 */ +# endif +# if !defined(UNIX_PATH_MAX) + /* Replicating logic present in afunix.h + (distributed with newer Windows 10 SDK versions only) */ +# define UNIX_PATH_MAX 108 + /* !checksrc! disable TYPEDEFSTRUCT 1 */ + typedef struct sockaddr_un { + ADDRESS_FAMILY sun_family; + char sun_path[UNIX_PATH_MAX]; + } SOCKADDR_UN, *PSOCKADDR_UN; +# endif +#endif + #endif /* HEADER_CURL_SETUP_H */ diff --git a/tests/server/sws.c b/tests/server/sws.c index 9c609a23f..010e5ae1d 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -2072,9 +2072,9 @@ int main(int argc, char *argv[]) strncpy(me.sau.sun_path, unix_socket, sizeof(me.sau.sun_path) - 1); rc = bind(sock, &me.sa, sizeof(me.sau)); if(0 != rc && errno == EADDRINUSE) { - struct stat statbuf; + struct_stat statbuf; /* socket already exists. Perhaps it is stale? */ - int unixfd = socket(AF_UNIX, SOCK_STREAM, 0); + curl_socket_t unixfd = socket(AF_UNIX, SOCK_STREAM, 0); if(CURL_SOCKET_BAD == unixfd) { error = SOCKERRNO; logmsg("Error binding socket, failed to create socket at %s: (%d) %s", @@ -2084,15 +2084,19 @@ int main(int argc, char *argv[]) /* check whether the server is alive */ rc = connect(unixfd, &me.sa, sizeof(me.sau)); error = errno; - close(unixfd); + sclose(unixfd); if(ECONNREFUSED != error) { logmsg("Error binding socket, failed to connect to %s: (%d) %s", unix_socket, error, strerror(error)); goto sws_cleanup; } - /* socket server is not alive, now check if it was actually a socket. - * Systems which have Unix sockets will also have lstat */ + /* socket server is not alive, now check if it was actually a socket. */ +#ifdef WIN32 + /* Windows does not have lstat function. */ + rc = curlx_win32_stat(unix_socket, &statbuf); +#else rc = lstat(unix_socket, &statbuf); +#endif if(0 != rc) { logmsg("Error binding socket, failed to stat %s: (%d) %s", unix_socket, errno, strerror(errno));