sys_socket_h.m4 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. # sys_socket_h.m4 serial 23
  2. dnl Copyright (C) 2005-2013 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([gl_HEADER_SYS_SOCKET],
  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. AC_CACHE_CHECK([whether <sys/socket.h> is self-contained],
  22. [gl_cv_header_sys_socket_h_selfcontained],
  23. [
  24. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>]], [[]])],
  25. [gl_cv_header_sys_socket_h_selfcontained=yes],
  26. [gl_cv_header_sys_socket_h_selfcontained=no])
  27. ])
  28. if test $gl_cv_header_sys_socket_h_selfcontained = yes; then
  29. dnl If the shutdown function exists, <sys/socket.h> should define
  30. dnl SHUT_RD, SHUT_WR, SHUT_RDWR.
  31. AC_CHECK_FUNCS([shutdown])
  32. if test $ac_cv_func_shutdown = yes; then
  33. AC_CACHE_CHECK([whether <sys/socket.h> defines the SHUT_* macros],
  34. [gl_cv_header_sys_socket_h_shut],
  35. [
  36. AC_COMPILE_IFELSE(
  37. [AC_LANG_PROGRAM([[#include <sys/socket.h>]],
  38. [[int a[] = { SHUT_RD, SHUT_WR, SHUT_RDWR };]])],
  39. [gl_cv_header_sys_socket_h_shut=yes],
  40. [gl_cv_header_sys_socket_h_shut=no])
  41. ])
  42. if test $gl_cv_header_sys_socket_h_shut = no; then
  43. SYS_SOCKET_H='sys/socket.h'
  44. fi
  45. fi
  46. fi
  47. # We need to check for ws2tcpip.h now.
  48. gl_PREREQ_SYS_H_SOCKET
  49. AC_CHECK_TYPES([struct sockaddr_storage, sa_family_t],,,[
  50. /* sys/types.h is not needed according to POSIX, but the
  51. sys/socket.h in i386-unknown-freebsd4.10 and
  52. powerpc-apple-darwin5.5 required it. */
  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. if test $ac_cv_type_struct_sockaddr_storage = no; then
  62. HAVE_STRUCT_SOCKADDR_STORAGE=0
  63. fi
  64. if test $ac_cv_type_sa_family_t = no; then
  65. HAVE_SA_FAMILY_T=0
  66. fi
  67. if test $ac_cv_type_struct_sockaddr_storage != no; then
  68. AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family],
  69. [],
  70. [HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=0],
  71. [#include <sys/types.h>
  72. #ifdef HAVE_SYS_SOCKET_H
  73. #include <sys/socket.h>
  74. #endif
  75. #ifdef HAVE_WS2TCPIP_H
  76. #include <ws2tcpip.h>
  77. #endif
  78. ])
  79. fi
  80. if test $HAVE_STRUCT_SOCKADDR_STORAGE = 0 || test $HAVE_SA_FAMILY_T = 0 \
  81. || test $HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY = 0; then
  82. SYS_SOCKET_H='sys/socket.h'
  83. fi
  84. gl_PREREQ_SYS_H_WINSOCK2
  85. dnl Check for declarations of anything we want to poison if the
  86. dnl corresponding gnulib module is not in use.
  87. gl_WARN_ON_USE_PREPARE([[
  88. /* Some systems require prerequisite headers. */
  89. #include <sys/types.h>
  90. #include <sys/socket.h>
  91. ]], [socket connect accept bind getpeername getsockname getsockopt
  92. listen recv send recvfrom sendto setsockopt shutdown accept4])
  93. ])
  94. AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
  95. [
  96. dnl Check prerequisites of the <sys/socket.h> replacement.
  97. AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])
  98. gl_CHECK_NEXT_HEADERS([sys/socket.h])
  99. if test $ac_cv_header_sys_socket_h = yes; then
  100. HAVE_SYS_SOCKET_H=1
  101. HAVE_WS2TCPIP_H=0
  102. else
  103. HAVE_SYS_SOCKET_H=0
  104. if test $ac_cv_header_ws2tcpip_h = yes; then
  105. HAVE_WS2TCPIP_H=1
  106. else
  107. HAVE_WS2TCPIP_H=0
  108. fi
  109. fi
  110. AC_SUBST([HAVE_SYS_SOCKET_H])
  111. AC_SUBST([HAVE_WS2TCPIP_H])
  112. ])
  113. # Common prerequisites of the <sys/socket.h> replacement and of the
  114. # <sys/select.h> replacement.
  115. # Sets and substitutes HAVE_WINSOCK2_H.
  116. AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2],
  117. [
  118. m4_ifdef([gl_UNISTD_H_DEFAULTS], [AC_REQUIRE([gl_UNISTD_H_DEFAULTS])])
  119. m4_ifdef([gl_SYS_IOCTL_H_DEFAULTS], [AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])])
  120. AC_CHECK_HEADERS_ONCE([sys/socket.h])
  121. if test $ac_cv_header_sys_socket_h != yes; then
  122. dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
  123. dnl the check for those headers unconditional; yet cygwin reports
  124. dnl that the headers are present but cannot be compiled (since on
  125. dnl cygwin, all socket information should come from sys/socket.h).
  126. AC_CHECK_HEADERS([winsock2.h])
  127. fi
  128. if test "$ac_cv_header_winsock2_h" = yes; then
  129. HAVE_WINSOCK2_H=1
  130. UNISTD_H_HAVE_WINSOCK2_H=1
  131. SYS_IOCTL_H_HAVE_WINSOCK2_H=1
  132. else
  133. HAVE_WINSOCK2_H=0
  134. fi
  135. AC_SUBST([HAVE_WINSOCK2_H])
  136. ])
  137. AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR],
  138. [
  139. dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
  140. AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
  141. gl_MODULE_INDICATOR_SET_VARIABLE([$1])
  142. dnl Define it also as a C macro, for the benefit of the unit tests.
  143. gl_MODULE_INDICATOR_FOR_TESTS([$1])
  144. ])
  145. AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
  146. [
  147. GNULIB_SOCKET=0; AC_SUBST([GNULIB_SOCKET])
  148. GNULIB_CONNECT=0; AC_SUBST([GNULIB_CONNECT])
  149. GNULIB_ACCEPT=0; AC_SUBST([GNULIB_ACCEPT])
  150. GNULIB_BIND=0; AC_SUBST([GNULIB_BIND])
  151. GNULIB_GETPEERNAME=0; AC_SUBST([GNULIB_GETPEERNAME])
  152. GNULIB_GETSOCKNAME=0; AC_SUBST([GNULIB_GETSOCKNAME])
  153. GNULIB_GETSOCKOPT=0; AC_SUBST([GNULIB_GETSOCKOPT])
  154. GNULIB_LISTEN=0; AC_SUBST([GNULIB_LISTEN])
  155. GNULIB_RECV=0; AC_SUBST([GNULIB_RECV])
  156. GNULIB_SEND=0; AC_SUBST([GNULIB_SEND])
  157. GNULIB_RECVFROM=0; AC_SUBST([GNULIB_RECVFROM])
  158. GNULIB_SENDTO=0; AC_SUBST([GNULIB_SENDTO])
  159. GNULIB_SETSOCKOPT=0; AC_SUBST([GNULIB_SETSOCKOPT])
  160. GNULIB_SHUTDOWN=0; AC_SUBST([GNULIB_SHUTDOWN])
  161. GNULIB_ACCEPT4=0; AC_SUBST([GNULIB_ACCEPT4])
  162. HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE])
  163. HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=1;
  164. AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY])
  165. HAVE_SA_FAMILY_T=1; AC_SUBST([HAVE_SA_FAMILY_T])
  166. HAVE_ACCEPT4=1; AC_SUBST([HAVE_ACCEPT4])
  167. ])