sys_socket_h.m4 7.2 KB

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