2 dnl Copyright (C) 2011 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_SOCKET_AFUNIX],
9 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
10 AC_REQUIRE([gl_SOCKET_FAMILY_UNIX])
12 AC_MSG_CHECKING([for UNIX domain sockets SCM_RIGHTS])
13 AC_CACHE_VAL([gl_cv_socket_unix_scm_rights],
16 [[#include <sys/types.h>
17 #ifdef HAVE_SYS_SOCKET_H
18 #include <sys/socket.h>
23 #ifdef HAVE_WINSOCK2_H
28 cmh.cmsg_level = SOL_SOCKET;
29 cmh.cmsg_type = SCM_RIGHTS;
32 [gl_cv_socket_unix_scm_rights=yes],
33 [gl_cv_socket_unix_scm_rights=no])
35 AC_MSG_RESULT([$gl_cv_socket_unix_scm_rights])
36 if test $gl_cv_socket_unix_scm_rights = yes; then
37 AC_DEFINE([HAVE_UNIXSOCKET_SCM_RIGHTS], [1],
38 [Define to 1 if <sys/socket.h> defines SCM_RIGHTS.])
41 dnl Persuade AIX 5.2 <sys/socket.h> to declare CMSG_SPACE, CMSG_LEN.
42 AC_DEFINE([_LINUX_SOURCE_COMPAT], [1],
43 [Define in order to get some macros on AIX systems.])
45 AC_MSG_CHECKING([for UNIX domain sockets SCM_RIGHTS that behave in BSD4.4 way])
46 AC_CACHE_VAL([gl_cv_socket_unix_scm_rights_bsd44_way],
49 [[#include <sys/types.h>
51 #ifdef HAVE_SYS_SOCKET_H
52 #include <sys/socket.h>
57 #ifdef HAVE_WINSOCK2_H
61 [[struct msghdr msg = {0};
64 char buf[CMSG_SPACE (sizeof (myfds))];
66 msg.msg_control = buf;
67 msg.msg_controllen = sizeof buf;
68 cmsg = CMSG_FIRSTHDR (&msg);
69 cmsg->cmsg_level = SOL_SOCKET;
70 cmsg->cmsg_type = SCM_RIGHTS;
71 cmsg->cmsg_len = CMSG_LEN (sizeof (int));
72 /* fake Initialize the payload: */
73 (void) CMSG_DATA (cmsg);
74 /* Sum of the length of all control messages in the buffer: */
75 msg.msg_controllen = cmsg->cmsg_len;
78 [gl_cv_socket_unix_scm_rights_bsd44_way=yes],
79 [gl_cv_socket_unix_scm_rights_bsd44_way=no])
81 AC_MSG_RESULT([$gl_cv_socket_unix_scm_rights_bsd44_way])
82 if test $gl_cv_socket_unix_scm_rights_bsd44_way = yes; then
83 AC_DEFINE([HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY], [1],
84 [Define to 1 if fd can be sent/received in the BSD4.4 way.])
87 AC_MSG_CHECKING([for UNIX domain sockets SCM_RIGHTS that behave in BSD4.3 way])
88 AC_CACHE_VAL([gl_cv_socket_unix_scm_rights_bsd43_way],
91 [[#include <sys/types.h>
92 #ifdef HAVE_SYS_SOCKET_H
93 #include <sys/socket.h>
98 #ifdef HAVE_WINSOCK2_H
104 msg.msg_accrights = &fd;
105 msg.msg_accrightslen = sizeof (fd);
108 [gl_cv_socket_unix_scm_rights_bsd43_way=yes],
109 [gl_cv_socket_unix_scm_rights_bsd43_way=no])
111 AC_MSG_RESULT([$gl_cv_socket_unix_scm_rights_bsd43_way])
112 if test $gl_cv_socket_unix_scm_rights_bsd43_way = yes; then
113 AC_DEFINE([HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43_WAY], [1],
114 [Define to 1 if fd can be sent/received in the BSD4.3 way.])
117 AC_MSG_CHECKING([for UNIX domain sockets recvmsg() MSG_CMSG_CLOEXEC flag])
118 AC_CACHE_VAL([gl_cv_socket_unix_msg_cmsg_cloexec],
121 [[#include <sys/types.h>
122 #ifdef HAVE_SYS_SOCKET_H
123 #include <sys/socket.h>
128 #ifdef HAVE_WINSOCK2_H
129 #include <winsock2.h>
132 [[int flags = MSG_CMSG_CLOEXEC;
133 if (&flags) return 0;
135 [gl_cv_socket_unix_msg_cmsg_cloexec=yes],
136 [gl_cv_socket_unix_msg_cmsg_cloexec=no])
138 AC_MSG_RESULT([$gl_cv_socket_unix_msg_cmsg_cloexec])
139 if test $gl_cv_socket_unix_msg_cmsg_cloexec = yes; then
140 AC_DEFINE([HAVE_MSG_CMSG_CLOEXEC], [1],
141 [Define to 1 if recvmsg could be specified with MSG_CMSG_CLOEXEC.])