Debian Codegraph @

m4/sys_socket_h.m4

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