sys_socket_h.m4 5.4 KB

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