Debian Codegraph @

m4/sys_socket_h.m4

raw
1 # sys_socket_h.m4
2 # serial 29
3 dnl Copyright (C) 2005-2024 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 AC_CHECK_TYPES([struct sockaddr_storage, sa_family_t],,,[
57 /* sys/types.h is not needed according to POSIX, but the
58 sys/socket.h in i386-unknown-freebsd4.10 and
59 powerpc-apple-darwin5.5 required it. */
60 #include <sys/types.h>
61 #ifdef HAVE_SYS_SOCKET_H
62 #include <sys/socket.h>
63 #endif
64 #ifdef HAVE_WS2TCPIP_H
65 #include <ws2tcpip.h>
66 #endif
67 ])
68 if test $ac_cv_type_struct_sockaddr_storage = no; then
69 HAVE_STRUCT_SOCKADDR_STORAGE=0
70 fi
71 if test $ac_cv_type_sa_family_t = no; then
72 HAVE_SA_FAMILY_T=0
73 fi
74 if test $ac_cv_type_struct_sockaddr_storage != no; then
75 AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family],
76 [],
77 [HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=0],
78 [#include <sys/types.h>
79 #ifdef HAVE_SYS_SOCKET_H
80 #include <sys/socket.h>
81 #endif
82 #ifdef HAVE_WS2TCPIP_H
83 #include <ws2tcpip.h>
84 #endif
85 ])
86 fi
87 if test $HAVE_STRUCT_SOCKADDR_STORAGE = 0 || test $HAVE_SA_FAMILY_T = 0 \
88 || test $HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY = 0; then
89 GL_GENERATE_SYS_SOCKET_H=true
90 fi
91 gl_PREREQ_SYS_H_WINSOCK2
92
93 dnl Check for declarations of anything we want to poison if the
94 dnl corresponding gnulib module is not in use.
95 gl_WARN_ON_USE_PREPARE([[
96 /* Some systems require prerequisite headers. */
97 #include <sys/types.h>
98 #include <sys/socket.h>
99 ]], [socket connect accept bind getpeername getsockname getsockopt
100 listen recv send recvfrom sendto setsockopt shutdown accept4])
101
102 AC_REQUIRE([AC_C_RESTRICT])
103 ])
104
105 AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
106 [
107 dnl Check prerequisites of the <sys/socket.h> replacement.
108 AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])
109 gl_CHECK_NEXT_HEADERS([sys/socket.h])
110 if test $ac_cv_header_sys_socket_h = yes; then
111 HAVE_SYS_SOCKET_H=1
112 else
113 HAVE_SYS_SOCKET_H=0
114 fi
115 AC_SUBST([HAVE_SYS_SOCKET_H])
116 gl_PREREQ_SYS_H_WS2TCPIP
117 ])
118
119 # Common prerequisites of the <sys/socket.h> replacement and of the
120 # <sys/select.h> replacement.
121 # Sets and substitutes HAVE_WINSOCK2_H.
122 AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2],
123 [
124 m4_ifdef([gl_UNISTD_H_DEFAULTS], [AC_REQUIRE([gl_UNISTD_H_DEFAULTS])])
125 m4_ifdef([gl_SYS_IOCTL_H_DEFAULTS], [AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])])
126 AC_CHECK_HEADERS_ONCE([sys/socket.h])
127 if test $ac_cv_header_sys_socket_h != yes; then
128 dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
129 dnl the check for those headers unconditional; yet cygwin reports
130 dnl that the headers are present but cannot be compiled (since on
131 dnl cygwin, all socket information should come from sys/socket.h).
132 AC_CHECK_HEADERS([winsock2.h])
133 fi
134 if test "$ac_cv_header_winsock2_h" = yes; then
135 HAVE_WINSOCK2_H=1
136 UNISTD_H_HAVE_WINSOCK2_H=1
137 SYS_IOCTL_H_HAVE_WINSOCK2_H=1
138 else
139 HAVE_WINSOCK2_H=0
140 fi
141 AC_SUBST([HAVE_WINSOCK2_H])
142 ])
143
144 # Common prerequisites of the <sys/socket.h> replacement and of the
145 # <arpa/inet.h> replacement.
146 # Sets and substitutes HAVE_WS2TCPIP_H.
147 AC_DEFUN([gl_PREREQ_SYS_H_WS2TCPIP],
148 [
149 AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])
150 if test $ac_cv_header_sys_socket_h = yes; then
151 HAVE_WS2TCPIP_H=0
152 else
153 if test $ac_cv_header_ws2tcpip_h = yes; then
154 HAVE_WS2TCPIP_H=1
155 else
156 HAVE_WS2TCPIP_H=0
157 fi
158 fi
159 AC_SUBST([HAVE_WS2TCPIP_H])
160 ])
161
162 # gl_SYS_SOCKET_MODULE_INDICATOR([modulename])
163 # sets the shell variable that indicates the presence of the given module
164 # to a C preprocessor expression that will evaluate to 1.
165 # This macro invocation must not occur in macros that are AC_REQUIREd.
166 AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR],
167 [
168 dnl Ensure to expand the default settings once only.
169 gl_SYS_SOCKET_H_REQUIRE_DEFAULTS
170 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
171 dnl Define it also as a C macro, for the benefit of the unit tests.
172 gl_MODULE_INDICATOR_FOR_TESTS([$1])
173 ])
174
175 # Initializes the default values for AC_SUBSTed shell variables.
176 # This macro must not be AC_REQUIREd. It must only be invoked, and only
177 # outside of macros or in macros that are not AC_REQUIREd.
178 AC_DEFUN([gl_SYS_SOCKET_H_REQUIRE_DEFAULTS],
179 [
180 m4_defun(GL_MODULE_INDICATOR_PREFIX[_SYS_SOCKET_H_MODULE_INDICATOR_DEFAULTS], [
181 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SOCKET])
182 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CONNECT])
183 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ACCEPT])
184 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_BIND])
185 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETPEERNAME])
186 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETSOCKNAME])
187 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETSOCKOPT])
188 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LISTEN])
189 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RECV])
190 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SEND])
191 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RECVFROM])
192 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SENDTO])
193 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SETSOCKOPT])
194 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SHUTDOWN])
195 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ACCEPT4])
196 ])
197 m4_require(GL_MODULE_INDICATOR_PREFIX[_SYS_SOCKET_H_MODULE_INDICATOR_DEFAULTS])
198 AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
199 ])
200
201 AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
202 [
203 HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE])
204 HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=1;
205 AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY])
206 HAVE_SA_FAMILY_T=1; AC_SUBST([HAVE_SA_FAMILY_T])
207 HAVE_ACCEPT4=1; AC_SUBST([HAVE_ACCEPT4])
208 ])