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 AC_MSG_CHECKING([for UNIX domain sockets SCM_RIGHTS that behave in BSD4.4 way])
42 AC_CACHE_VAL([gl_cv_socket_unix_scm_rights_bsd44_way],
45 [[#include <sys/types.h>
46 #ifdef HAVE_SYS_SOCKET_H
47 #include <sys/socket.h>
52 #ifdef HAVE_WINSOCK2_H
56 [[struct msghdr msg = {0};
59 char buf[CMSG_SPACE (sizeof (myfds))];
62 msg.msg_control = buf;
63 msg.msg_controllen = sizeof buf;
64 cmsg = CMSG_FIRSTHDR (&msg);
65 cmsg->cmsg_level = SOL_SOCKET;
66 cmsg->cmsg_type = SCM_RIGHTS;
67 cmsg->cmsg_len = CMSG_LEN (sizeof (int));
68 /* fake Initialize the payload: */
69 (void) CMSG_DATA (cmsg);
70 /* Sum of the length of all control messages in the buffer: */
71 msg.msg_controllen = cmsg->cmsg_len;
74 [gl_cv_socket_unix_scm_rights_bsd44_way=yes],
75 [gl_cv_socket_unix_scm_rights_bsd44_way=no])
77 AC_MSG_RESULT([$gl_cv_socket_unix_scm_rights_bsd44_way])
78 if test $gl_cv_socket_unix_scm_rights_bsd44_way = yes; then
79 AC_DEFINE([HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY], [1],
80 [Define to 1 if fd can be sent/received in the BSD4.4 way.])
83 AC_MSG_CHECKING([for UNIX domain sockets SCM_RIGHTS that behave in BSD4.3 way])
84 AC_CACHE_VAL([gl_cv_socket_unix_scm_rights_bsd43_way],
87 [[#include <sys/types.h>
88 #ifdef HAVE_SYS_SOCKET_H
89 #include <sys/socket.h>
94 #ifdef HAVE_WINSOCK2_H
100 msg.msg_accrights = &fd;
101 msg.msg_accrightslen = sizeof (fd);
104 [gl_cv_socket_unix_scm_rights_bsd43_way=yes],
105 [gl_cv_socket_unix_scm_rights_bsd43_way=no])
107 AC_MSG_RESULT([$gl_cv_socket_unix_scm_rights_bsd43_way])
108 if test $gl_cv_socket_unix_scm_rights_bsd43_way = yes; then
109 AC_DEFINE([HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43_WAY], [1],
110 [Define to 1 if fd can be sent/received in the BSD4.3 way.])
113 AC_MSG_CHECKING([for UNIX domain sockets recvmsg() MSG_CMSG_CLOEXEC flag])
114 AC_CACHE_VAL([gl_cv_socket_unix_msg_cmsg_cloexec],
117 [[#include <sys/types.h>
118 #ifdef HAVE_SYS_SOCKET_H
119 #include <sys/socket.h>
124 #ifdef HAVE_WINSOCK2_H
125 #include <winsock2.h>
128 [[int flags = MSG_CMSG_CLOEXEC;
129 if (&flags) return 0;
131 [gl_cv_socket_unix_msg_cmsg_cloexec=yes],
132 [gl_cv_socket_unix_msg_cmsg_cloexec=no])
134 AC_MSG_RESULT([$gl_cv_socket_unix_msg_cmsg_cloexec])
135 if test $gl_cv_socket_unix_msg_cmsg_cloexec = yes; then
136 AC_DEFINE([HAVE_MSG_CMSG_CLOEXEC], [1],
137 [Define to 1 if recvmsg could be specified with MSG_CMSG_CLOEXEC.])