Debian Codegraph @

m4/sys_socket_h.m4

raw
1 # sys_socket_h.m4
2 # serial 32
3 dnl Copyright (C) 2005-2026 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 dnl From Simon Josefsson.
10
11 AC_DEFUN_ONCE([gl_SYS_SOCKET_H],
12 [
13 AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
14 AC_REQUIRE([AC_CANONICAL_HOST])
15
16 GL_GENERATE_SYS_SOCKET_H=false
17 AC_CACHE_CHECK([whether <sys/socket.h> is self-contained],
18 [gl_cv_header_sys_socket_h_selfcontained],
19 [
20 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>]], [[]])],
21 [gl_cv_header_sys_socket_h_selfcontained=yes],
22 [gl_cv_header_sys_socket_h_selfcontained=no])
23 ])
24 if test $gl_cv_header_sys_socket_h_selfcontained = yes; then
25 dnl If the shutdown function exists, <sys/socket.h> should define
26 dnl SHUT_RD, SHUT_WR, SHUT_RDWR.
27 AC_CHECK_FUNCS([shutdown])
28 if test $ac_cv_func_shutdown = yes; then
29 AC_CACHE_CHECK([whether <sys/socket.h> defines the SHUT_* macros],
30 [gl_cv_header_sys_socket_h_shut],
31 [
32 AC_COMPILE_IFELSE(
33 [AC_LANG_PROGRAM([[#include <sys/socket.h>]],
34 [[int a[] = { SHUT_RD, SHUT_WR, SHUT_RDWR };]])],
35 [gl_cv_header_sys_socket_h_shut=yes],
36 [gl_cv_header_sys_socket_h_shut=no])
37 ])
38 if test $gl_cv_header_sys_socket_h_shut = no; then
39 GL_GENERATE_SYS_SOCKET_H=true
40 fi
41 fi
42 fi
43 # We need to check for ws2tcpip.h now.
44 gl_PREREQ_SYS_H_SOCKET
45 gl_PREREQ_SYS_SA_FAMILY
46 if test $ac_cv_type_struct_sockaddr_storage = no; then
47 HAVE_STRUCT_SOCKADDR_STORAGE=0
48 fi
49 if test $ac_cv_type_struct_sockaddr_storage != no; then
50 AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family],
51 [],
52 [HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=0],
53 [#include <sys/types.h>
54 #ifdef HAVE_SYS_SOCKET_H
55 #include <sys/socket.h>
56 #endif
57 #ifdef HAVE_WS2TCPIP_H
58 #include <ws2tcpip.h>
59 #endif
60 ])
61 fi
62 if test $HAVE_STRUCT_SOCKADDR_STORAGE = 0 || test $HAVE_SA_FAMILY_T = 0 \
63 || test $HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY = 0; then
64 GL_GENERATE_SYS_SOCKET_H=true
65 fi
66 gl_PREREQ_SYS_H_WINSOCK2
67
68 dnl Check for declarations of anything we want to poison if the
69 dnl corresponding gnulib module is not in use.
70 gl_WARN_ON_USE_PREPARE([[
71 /* Some systems require prerequisite headers. */
72 #include <sys/types.h>
73 #include <sys/socket.h>
74 ]], [socket connect accept bind getpeername getsockname getsockopt
75 listen recv send recvfrom sendto setsockopt shutdown accept4])
76
77 AC_REQUIRE([AC_C_RESTRICT])
78 ])
79
80 AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
81 [
82 dnl Check prerequisites of the <sys/socket.h> replacement.
83 AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])
84 gl_CHECK_NEXT_HEADERS([sys/socket.h])
85 if test $ac_cv_header_sys_socket_h = yes; then
86 HAVE_SYS_SOCKET_H=1
87 else
88 HAVE_SYS_SOCKET_H=0
89 fi
90 AC_SUBST([HAVE_SYS_SOCKET_H])
91 gl_PREREQ_SYS_H_WS2TCPIP
92 ])
93
94 # Common prerequisites of the <sys/socket.h> replacement and of the
95 # <sys/select.h> replacement.
96 # Sets and substitutes HAVE_WINSOCK2_H.
97 AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2],
98 [
99 m4_ifdef([gl_UNISTD_H_DEFAULTS], [AC_REQUIRE([gl_UNISTD_H_DEFAULTS])])
100 m4_ifdef([gl_SYS_IOCTL_H_DEFAULTS], [AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])])
101 AC_CHECK_HEADERS_ONCE([sys/socket.h])
102 if test $ac_cv_header_sys_socket_h != yes; then
103 dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
104 dnl the check for those headers unconditional; yet cygwin reports
105 dnl that the headers are present but cannot be compiled (since on
106 dnl cygwin, all socket information should come from sys/socket.h).
107 AC_CHECK_HEADERS([winsock2.h])
108 fi
109 if test "$ac_cv_header_winsock2_h" = yes; then
110 HAVE_WINSOCK2_H=1
111 UNISTD_H_HAVE_WINSOCK2_H=1
112 SYS_IOCTL_H_HAVE_WINSOCK2_H=1
113 else
114 HAVE_WINSOCK2_H=0
115 fi
116 AC_SUBST([HAVE_WINSOCK2_H])
117 ])
118
119 # Common prerequisites of the <sys/socket.h> replacement and of the
120 # <arpa/inet.h> replacement.
121 # Sets and substitutes HAVE_WS2TCPIP_H.
122 AC_DEFUN([gl_PREREQ_SYS_H_WS2TCPIP],
123 [
124 AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])
125 if test $ac_cv_header_sys_socket_h = yes; then
126 HAVE_WS2TCPIP_H=0
127 else
128 if test $ac_cv_header_ws2tcpip_h = yes; then
129 HAVE_WS2TCPIP_H=1
130 else
131 HAVE_WS2TCPIP_H=0
132 fi
133 fi
134 AC_SUBST([HAVE_WS2TCPIP_H])
135 ])
136
137 # Common prerequisites of the <sys/socket.h> replacement and of the <sys/un.h>
138 # replacement.
139 # Sets and substitutes HAVE_SA_FAMILY_T.
140 AC_DEFUN([gl_PREREQ_SYS_SA_FAMILY],
141 [
142 AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])
143 AC_CHECK_TYPES([struct sockaddr_storage, sa_family_t],,,[
144 /* sys/types.h is not needed according to POSIX, but the
145 sys/socket.h in i386-unknown-freebsd4.10 and
146 powerpc-apple-darwin5.5 required it. */
147 #include <sys/types.h>
148 #ifdef HAVE_SYS_SOCKET_H
149 #include <sys/socket.h>
150 #endif
151 #ifdef HAVE_WS2TCPIP_H
152 #include <ws2tcpip.h>
153 #endif
154 ])
155 if test $ac_cv_type_sa_family_t = yes; then
156 HAVE_SA_FAMILY_T=1
157 else
158 HAVE_SA_FAMILY_T=0
159 fi
160 AC_SUBST([HAVE_SA_FAMILY_T])
161 ])
162
163 # gl_SYS_SOCKET_MODULE_INDICATOR([modulename])
164 # sets the shell variable that indicates the presence of the given module
165 # to a C preprocessor expression that will evaluate to 1.
166 # This macro invocation must not occur in macros that are AC_REQUIREd.
167 AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR],
168 [
169 dnl Ensure to expand the default settings once only.
170 gl_SYS_SOCKET_H_REQUIRE_DEFAULTS
171 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
172 dnl Define it also as a C macro, for the benefit of the unit tests.
173 gl_MODULE_INDICATOR_FOR_TESTS([$1])
174 ])
175
176 # Initializes the default values for AC_SUBSTed shell variables.
177 # This macro must not be AC_REQUIREd. It must only be invoked, and only
178 # outside of macros or in macros that are not AC_REQUIREd.
179 AC_DEFUN([gl_SYS_SOCKET_H_REQUIRE_DEFAULTS],
180 [
181 m4_defun(GL_MODULE_INDICATOR_PREFIX[_SYS_SOCKET_H_MODULE_INDICATOR_DEFAULTS], [
182 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SOCKET])
183 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CONNECT])
184 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ACCEPT])
185 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_BIND])
186 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETPEERNAME])
187 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETSOCKNAME])
188 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETSOCKOPT])
189 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LISTEN])
190 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RECV])
191 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SEND])
192 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RECVFROM])
193 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SENDTO])
194 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SETSOCKOPT])
195 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SHUTDOWN])
196 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ACCEPT4])
197 ])
198 m4_require(GL_MODULE_INDICATOR_PREFIX[_SYS_SOCKET_H_MODULE_INDICATOR_DEFAULTS])
199 AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
200 ])
201
202 AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
203 [
204 HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE])
205 HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=1;
206 AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY])
207 HAVE_ACCEPT4=1; AC_SUBST([HAVE_ACCEPT4])
208 ])