sys_socket_h.m4 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. # sys_socket_h.m4 serial 22
  2. dnl Copyright (C) 2005-2011 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. AC_REQUIRE([AC_C_INLINE])
  12. dnl On OSF/1, the functions recv(), send(), recvfrom(), sendto() have
  13. dnl old-style declarations (with return type 'int' instead of 'ssize_t')
  14. dnl unless _POSIX_PII_SOCKET is defined.
  15. case "$host_os" in
  16. osf*)
  17. AC_DEFINE([_POSIX_PII_SOCKET], [1],
  18. [Define to 1 in order to get the POSIX compatible declarations
  19. of socket functions.])
  20. ;;
  21. esac
  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. SYS_SOCKET_H='sys/socket.h'
  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. SYS_SOCKET_H='sys/socket.h'
  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. ])
  95. AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
  96. [
  97. dnl Check prerequisites of the <sys/socket.h> replacement.
  98. AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])
  99. gl_CHECK_NEXT_HEADERS([sys/socket.h])
  100. if test $ac_cv_header_sys_socket_h = yes; then
  101. HAVE_SYS_SOCKET_H=1
  102. HAVE_WS2TCPIP_H=0
  103. else
  104. HAVE_SYS_SOCKET_H=0
  105. if test $ac_cv_header_ws2tcpip_h = yes; then
  106. HAVE_WS2TCPIP_H=1
  107. else
  108. HAVE_WS2TCPIP_H=0
  109. fi
  110. fi
  111. AC_SUBST([HAVE_SYS_SOCKET_H])
  112. AC_SUBST([HAVE_WS2TCPIP_H])
  113. ])
  114. # Common prerequisites of the <sys/socket.h> replacement and of the
  115. # <sys/select.h> replacement.
  116. # Sets and substitutes HAVE_WINSOCK2_H.
  117. AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2],
  118. [
  119. m4_ifdef([gl_UNISTD_H_DEFAULTS], [AC_REQUIRE([gl_UNISTD_H_DEFAULTS])])
  120. m4_ifdef([gl_SYS_IOCTL_H_DEFAULTS], [AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])])
  121. AC_CHECK_HEADERS_ONCE([sys/socket.h])
  122. if test $ac_cv_header_sys_socket_h != yes; then
  123. dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
  124. dnl the check for those headers unconditional; yet cygwin reports
  125. dnl that the headers are present but cannot be compiled (since on
  126. dnl cygwin, all socket information should come from sys/socket.h).
  127. AC_CHECK_HEADERS([winsock2.h])
  128. fi
  129. if test "$ac_cv_header_winsock2_h" = yes; then
  130. HAVE_WINSOCK2_H=1
  131. UNISTD_H_HAVE_WINSOCK2_H=1
  132. SYS_IOCTL_H_HAVE_WINSOCK2_H=1
  133. else
  134. HAVE_WINSOCK2_H=0
  135. fi
  136. AC_SUBST([HAVE_WINSOCK2_H])
  137. ])
  138. AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR],
  139. [
  140. dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
  141. AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
  142. gl_MODULE_INDICATOR_SET_VARIABLE([$1])
  143. dnl Define it also as a C macro, for the benefit of the unit tests.
  144. gl_MODULE_INDICATOR_FOR_TESTS([$1])
  145. ])
  146. AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
  147. [
  148. GNULIB_SOCKET=0; AC_SUBST([GNULIB_SOCKET])
  149. GNULIB_CONNECT=0; AC_SUBST([GNULIB_CONNECT])
  150. GNULIB_ACCEPT=0; AC_SUBST([GNULIB_ACCEPT])
  151. GNULIB_BIND=0; AC_SUBST([GNULIB_BIND])
  152. GNULIB_GETPEERNAME=0; AC_SUBST([GNULIB_GETPEERNAME])
  153. GNULIB_GETSOCKNAME=0; AC_SUBST([GNULIB_GETSOCKNAME])
  154. GNULIB_GETSOCKOPT=0; AC_SUBST([GNULIB_GETSOCKOPT])
  155. GNULIB_LISTEN=0; AC_SUBST([GNULIB_LISTEN])
  156. GNULIB_RECV=0; AC_SUBST([GNULIB_RECV])
  157. GNULIB_SEND=0; AC_SUBST([GNULIB_SEND])
  158. GNULIB_RECVFROM=0; AC_SUBST([GNULIB_RECVFROM])
  159. GNULIB_SENDTO=0; AC_SUBST([GNULIB_SENDTO])
  160. GNULIB_SETSOCKOPT=0; AC_SUBST([GNULIB_SETSOCKOPT])
  161. GNULIB_SHUTDOWN=0; AC_SUBST([GNULIB_SHUTDOWN])
  162. GNULIB_ACCEPT4=0; AC_SUBST([GNULIB_ACCEPT4])
  163. HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE])
  164. HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=1;
  165. AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY])
  166. HAVE_SA_FAMILY_T=1; AC_SUBST([HAVE_SA_FAMILY_T])
  167. HAVE_ACCEPT4=1; AC_SUBST([HAVE_ACCEPT4])
  168. ])