summaryrefslogtreecommitdiff
path: root/m4/afunix.m4
blob: 46b3bf34430b686612741d2d5e2bb16947c2e273 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# afunix.m4 serial 5
dnl Copyright (C) 2011 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

AC_DEFUN([gl_SOCKET_AFUNIX],
[
  AC_REQUIRE([gl_HEADER_SYS_SOCKET])
  AC_REQUIRE([gl_SOCKET_FAMILY_UNIX])

  AC_MSG_CHECKING([for UNIX domain sockets SCM_RIGHTS])
  AC_CACHE_VAL([gl_cv_socket_unix_scm_rights],
    [AC_COMPILE_IFELSE(
       [AC_LANG_PROGRAM(
          [[#include <sys/types.h>
            #ifdef HAVE_SYS_SOCKET_H
            #include <sys/socket.h>
            #endif
            #ifdef HAVE_SYS_UN_H
            #include <sys/un.h>
            #endif
            #ifdef HAVE_WINSOCK2_H
            #include <winsock2.h>
            #endif
          ]],
          [[struct cmsghdr cmh;
            cmh.cmsg_level = SOL_SOCKET;
            cmh.cmsg_type = SCM_RIGHTS;
            if (&cmh) return 0;
          ]])],
       [gl_cv_socket_unix_scm_rights=yes],
       [gl_cv_socket_unix_scm_rights=no])
    ])
  AC_MSG_RESULT([$gl_cv_socket_unix_scm_rights])
  if test $gl_cv_socket_unix_scm_rights = yes; then
    AC_DEFINE([HAVE_UNIXSOCKET_SCM_RIGHTS], [1],
      [Define to 1 if <sys/socket.h> defines SCM_RIGHTS.])
  fi

  dnl Persuade AIX 5.2 <sys/socket.h> to declare CMSG_SPACE, CMSG_LEN.
  AC_DEFINE([_LINUX_SOURCE_COMPAT], [1],
    [Define in order to get some macros on AIX systems.])

  AC_MSG_CHECKING([for UNIX domain sockets SCM_RIGHTS that behave in BSD4.4 way])
  AC_CACHE_VAL([gl_cv_socket_unix_scm_rights_bsd44_way],
    [AC_COMPILE_IFELSE(
       [AC_LANG_PROGRAM(
          [[#include <sys/types.h>
            #include <stddef.h>
            #ifdef HAVE_SYS_SOCKET_H
            #include <sys/socket.h>
            #endif
            #ifdef HAVE_SYS_UN_H
            #include <sys/un.h>
            #endif
            #ifdef HAVE_WINSOCK2_H
            #include <winsock2.h>
            #endif
            ]],
            [[struct msghdr msg = {0};
              struct cmsghdr *cmsg;
              int myfds[1] = {0};
              char buf[CMSG_SPACE (sizeof (myfds))];

              msg.msg_control = buf;
              msg.msg_controllen = sizeof buf;
              cmsg = CMSG_FIRSTHDR (&msg);
              cmsg->cmsg_level = SOL_SOCKET;
              cmsg->cmsg_type = SCM_RIGHTS;
              cmsg->cmsg_len = CMSG_LEN (sizeof (int));
              /* fake Initialize the payload: */
              (void) CMSG_DATA (cmsg);
              /* Sum of the length of all control messages in the buffer: */
              msg.msg_controllen = cmsg->cmsg_len;
              return 0;
            ]])],
       [gl_cv_socket_unix_scm_rights_bsd44_way=yes],
       [gl_cv_socket_unix_scm_rights_bsd44_way=no])
    ])
  AC_MSG_RESULT([$gl_cv_socket_unix_scm_rights_bsd44_way])
  if test $gl_cv_socket_unix_scm_rights_bsd44_way = yes; then
    AC_DEFINE([HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY], [1],
      [Define to 1 if fd can be sent/received in the BSD4.4 way.])
  fi

  AC_MSG_CHECKING([for UNIX domain sockets SCM_RIGHTS that behave in BSD4.3 way])
  AC_CACHE_VAL([gl_cv_socket_unix_scm_rights_bsd43_way],
    [AC_COMPILE_IFELSE(
       [AC_LANG_PROGRAM(
          [[#include <sys/types.h>
            #ifdef HAVE_SYS_SOCKET_H
            #include <sys/socket.h>
            #endif
            #ifdef HAVE_SYS_UN_H
            #include <sys/un.h>
            #endif
            #ifdef HAVE_WINSOCK2_H
            #include <winsock2.h>
            #endif
            ]],
            [[struct msghdr msg;
              int fd = 0;
              msg.msg_accrights = &fd;
              msg.msg_accrightslen = sizeof (fd);
              if (&msg) return 0;
            ]])],
       [gl_cv_socket_unix_scm_rights_bsd43_way=yes],
       [gl_cv_socket_unix_scm_rights_bsd43_way=no])
    ])
  AC_MSG_RESULT([$gl_cv_socket_unix_scm_rights_bsd43_way])
  if test $gl_cv_socket_unix_scm_rights_bsd43_way = yes; then
    AC_DEFINE([HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43_WAY], [1],
      [Define to 1 if fd can be sent/received in the BSD4.3 way.])
  fi

  AC_MSG_CHECKING([for UNIX domain sockets recvmsg() MSG_CMSG_CLOEXEC flag])
  AC_CACHE_VAL([gl_cv_socket_unix_msg_cmsg_cloexec],
    [AC_COMPILE_IFELSE(
       [AC_LANG_PROGRAM(
          [[#include <sys/types.h>
            #ifdef HAVE_SYS_SOCKET_H
            #include <sys/socket.h>
            #endif
            #ifdef HAVE_SYS_UN_H
            #include <sys/un.h>
            #endif
            #ifdef HAVE_WINSOCK2_H
            #include <winsock2.h>
            #endif
            ]],
            [[int flags = MSG_CMSG_CLOEXEC;
              if (&flags) return 0;
            ]])],
       [gl_cv_socket_unix_msg_cmsg_cloexec=yes],
       [gl_cv_socket_unix_msg_cmsg_cloexec=no])
    ])
  AC_MSG_RESULT([$gl_cv_socket_unix_msg_cmsg_cloexec])
  if test $gl_cv_socket_unix_msg_cmsg_cloexec = yes; then
    AC_DEFINE([HAVE_MSG_CMSG_CLOEXEC], [1],
      [Define to 1 if recvmsg could be specified with MSG_CMSG_CLOEXEC.])
  fi
])