From 5eb0b00c875b8406f430573bdaf9eab5d4a0c99e Mon Sep 17 00:00:00 2001 From: myd7349 Date: Wed, 24 Nov 2021 22:55:45 +0800 Subject: [PATCH] Problem: In rare cases, afunix.h doesn't contain a definition for struct sockaddr_un (#4310) * Problem: In rare cases, afunix.h doesn't contain a definition for struct sockaddr_un According to https://github.com/microsoft/vcpkg/issues/21623, struct sockaddr_un might be unavailable on some machines even afunix.h exists. For example, on some machines, the content of afunix.h looks like this: typedef struct _SOCKADDR_UN { ADDRESS_FAMILY Family; wchar_t Path[63]; } SOCKADDR_UN, *PSOCKADDR_UN; but on other machines, it may looks like this: #define UNIX_PATH_MAX 108 typedef struct sockaddr_un { ADDRESS_FAMILY sun_family; char sun_path[UNIX_PATH_MAX]; } SOCKADDR_UN, *PSOCKADDR_UN; Fixes #3949 References: - [Enable Unix-domain sockets support on Windows](https://git.furworks.de/opensourcemirror/postgresql/commit/8f3ec75de4060d86176ad4ac998eeb87a39748c2) - [AF_UNIX equivalent for Windows](https://stackoverflow.com/questions/9029174/af-unix-equivalent-for-windows) - https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/ --- CMakeLists.txt | 5 +++++ builds/cmake/platform.hpp.in | 1 + src/windows.hpp | 10 ++++++++++ 3 files changed, 16 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c983c66..21bcd414 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ include(CheckCSourceCompiles) include(CheckCSourceRuns) include(CMakeDependentOption) include(CheckCXXSymbolExists) +include(CheckStructHasMember) include(CheckTypeSize) include(FindThreads) include(GNUInstallDirs) @@ -495,8 +496,12 @@ endif() if(NOT WIN32) set(ZMQ_HAVE_IPC 1) + set(ZMQ_HAVE_STRUCT_SOCKADDR_UN 1) else() check_include_files("winsock2.h;afunix.h" ZMQ_HAVE_IPC) + if(ZMQ_HAVE_IPC) + check_struct_has_member("struct sockaddr_un" sun_path "winsock2.h;afunix.h" ZMQ_HAVE_STRUCT_SOCKADDR_UN) + endif() endif() # ##################### BEGIN condition_variable_t selection diff --git a/builds/cmake/platform.hpp.in b/builds/cmake/platform.hpp.in index 2d23e8b2..18064362 100644 --- a/builds/cmake/platform.hpp.in +++ b/builds/cmake/platform.hpp.in @@ -59,6 +59,7 @@ #cmakedefine ZMQ_HAVE_LIBBSD #cmakedefine ZMQ_HAVE_IPC +#cmakedefine ZMQ_HAVE_STRUCT_SOCKADDR_UN #cmakedefine ZMQ_USE_BUILTIN_SHA1 #cmakedefine ZMQ_USE_NSS diff --git a/src/windows.hpp b/src/windows.hpp index 11c7581d..24cce83d 100644 --- a/src/windows.hpp +++ b/src/windows.hpp @@ -98,3 +98,13 @@ static inline int poll (struct pollfd *pfd, unsigned long nfds, int timeout) #define snprintf(buffer_, count_, format_, ...) \ _snprintf_s (buffer_, count_, _TRUNCATE, format_, __VA_ARGS__) #endif + +// Workaround missing struct sockaddr_un in afunix.h. +// Fix #3949. +#if defined(ZMQ_HAVE_IPC) && !defined(ZMQ_HAVE_STRUCT_SOCKADDR_UN) +struct sockaddr_un +{ + ADDRESS_FAMILY sun_family; /* AF_UNIX */ + char sun_path[108]; /* pathname */ +}; +#endif