Windows has supported socket (AF_UNIX, SOCK_STREAM, ...) since 2017 [1]. The checks in m4/sockpfaf.m4 where written before then. I've committed this patch to support Windows.
On Windows version that support it, afunix.h is a small file with the following type: typedef struct sockaddr_un { ADDRESS_FAMILY sun_family; char sun_path[UNIX_PATH_MAX]; } SOCKADDR_UN, *PSOCKADDR_UN; And AF_UNIX is defined in winsock2.h. Since Gnulib's sys/socket.h includes this winsock2.h on Windows it will be defined in the proper place if supported. I'll write a sys_un module to deal with including afunix.h tomorrow. Collin [1] https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/
>From d3efdd55f36a01118ed936da25633858a5757897 Mon Sep 17 00:00:00 2001 From: Collin Funk <collin.fu...@gmail.com> Date: Tue, 23 Jul 2024 21:31:06 -0700 Subject: [PATCH] Detect UNIX domain sockets supported by recent Windows versions. * m4/sockpfaf.m4 (gl_SOCKET_FAMILY_UNIX): Check for afunix.h if winsock2.h is found. Include it in the compile check. --- ChangeLog | 4 ++++ m4/sockpfaf.m4 | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5910b4699c..3e9d691efa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2024-07-23 Collin Funk <collin.fu...@gmail.com> + Detect UNIX domain sockets supported by recent Windows versions. + * m4/sockpfaf.m4 (gl_SOCKET_FAMILY_UNIX): Check for afunix.h if + winsock2.h is found. Include it in the compile check. + sys_socket tests: Fix mistake in previous commit. * modules/sys_socket-tests (configure.ac): Invoke gl_SOCKET_FAMILY_UNIX. diff --git a/m4/sockpfaf.m4 b/m4/sockpfaf.m4 index c68b3abbce..44ac7fd947 100644 --- a/m4/sockpfaf.m4 +++ b/m4/sockpfaf.m4 @@ -1,5 +1,5 @@ # sockpfaf.m4 -# serial 10 +# serial 11 dnl Copyright (C) 2004, 2006, 2009-2024 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -64,6 +64,13 @@ AC_DEFUN([gl_SOCKET_FAMILY_UNIX] AC_REQUIRE([gl_SYS_SOCKET_H]) AC_CHECK_HEADERS_ONCE([sys/un.h]) + dnl Windows versions released after 2017 may have support for AF_UNIX. + dnl Including it requires types from <winsock2.h> to be defined. + dnl <https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/>. + if test "$ac_cv_header_winsock2_h" = yes; then + AC_CHECK_HEADERS([afunix.h], [], [], [#include <winsock2.h>]) + fi + AC_CACHE_CHECK([for UNIX domain sockets], [gl_cv_socket_unix], [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h> @@ -75,6 +82,9 @@ AC_DEFUN([gl_SOCKET_FAMILY_UNIX] #endif #ifdef HAVE_WINSOCK2_H #include <winsock2.h> +#endif +#ifdef HAVE_AFUNIX_H +#include <afunix.h> #endif]], [[int x = AF_UNIX; struct sockaddr_un y; if (&x && &y) return 0;]])], -- 2.45.2