sys_socket_h.m4 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. # sys_socket_h.m4 serial 12
  2. dnl Copyright (C) 2005-2009 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. SYS_SOCKET_H=''
  20. dnl If the shutdown function exists, <sys/socket.h> should define
  21. dnl SHUT_RD, SHUT_WR, SHUT_RDWR.
  22. AC_CHECK_FUNCS([shutdown])
  23. if test $ac_cv_func_shutdown = yes; then
  24. AC_CACHE_CHECK([whether <sys/socket.h> defines the SHUT_* macros],
  25. [gl_cv_header_sys_socket_h_shut],
  26. [
  27. AC_COMPILE_IFELSE(
  28. [AC_LANG_PROGRAM([[#include <sys/socket.h>]],
  29. [[int a[] = { SHUT_RD, SHUT_WR, SHUT_RDWR };]])],
  30. [gl_cv_header_sys_socket_h_shut=yes],
  31. [gl_cv_header_sys_socket_h_shut=no])
  32. ])
  33. if test $gl_cv_header_sys_socket_h_shut = no; then
  34. SYS_SOCKET_H='sys/socket.h'
  35. fi
  36. fi
  37. else
  38. SYS_SOCKET_H='sys/socket.h'
  39. fi
  40. # We need to check for ws2tcpip.h now.
  41. gl_PREREQ_SYS_H_SOCKET
  42. AC_CHECK_TYPES([struct sockaddr_storage],,,[
  43. /* sys/types.h is not needed according to POSIX, but the
  44. sys/socket.h in i386-unknown-freebsd4.10 and
  45. powerpc-apple-darwin5.5 required it. */
  46. #include <sys/types.h>
  47. #ifdef HAVE_SYS_SOCKET_H
  48. #include <sys/socket.h>
  49. #endif
  50. #ifdef HAVE_WS2TCPIP_H
  51. #include <ws2tcpip.h>
  52. #endif
  53. ])
  54. if test $ac_cv_type_struct_sockaddr_storage = no; then
  55. HAVE_STRUCT_SOCKADDR_STORAGE=0
  56. SYS_SOCKET_H='sys/socket.h'
  57. fi
  58. if test -n "$SYS_SOCKET_H"; then
  59. gl_PREREQ_SYS_H_WINSOCK2
  60. fi
  61. AC_SUBST([SYS_SOCKET_H])
  62. ])
  63. AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
  64. [
  65. dnl Check prerequisites of the <sys/socket.h> replacement.
  66. gl_CHECK_NEXT_HEADERS([sys/socket.h])
  67. if test $ac_cv_header_sys_socket_h = yes; then
  68. HAVE_SYS_SOCKET_H=1
  69. HAVE_WS2TCPIP_H=0
  70. else
  71. HAVE_SYS_SOCKET_H=0
  72. dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
  73. dnl the check for those headers unconditional; yet cygwin reports
  74. dnl that the headers are present but cannot be compiled (since on
  75. dnl cygwin, all socket information should come from sys/socket.h).
  76. AC_CHECK_HEADERS([ws2tcpip.h])
  77. if test $ac_cv_header_ws2tcpip_h = yes; then
  78. HAVE_WS2TCPIP_H=1
  79. else
  80. HAVE_WS2TCPIP_H=0
  81. fi
  82. fi
  83. AC_SUBST([HAVE_SYS_SOCKET_H])
  84. AC_SUBST([HAVE_WS2TCPIP_H])
  85. ])
  86. # Common prerequisites of of the <sys/socket.h> replacement and of the
  87. # <sys/select.h> replacement.
  88. # Sets and substitutes HAVE_WINSOCK2_H.
  89. AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2],
  90. [
  91. m4_ifdef([gl_UNISTD_H_DEFAULTS], [AC_REQUIRE([gl_UNISTD_H_DEFAULTS])])
  92. m4_ifdef([gl_SYS_IOCTL_H_DEFAULTS], [AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])])
  93. AC_CHECK_HEADERS_ONCE([sys/socket.h])
  94. if test $ac_cv_header_sys_socket_h != yes; then
  95. dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
  96. dnl the check for those headers unconditional; yet cygwin reports
  97. dnl that the headers are present but cannot be compiled (since on
  98. dnl cygwin, all socket information should come from sys/socket.h).
  99. AC_CHECK_HEADERS([winsock2.h])
  100. fi
  101. if test "$ac_cv_header_winsock2_h" = yes; then
  102. HAVE_WINSOCK2_H=1
  103. UNISTD_H_HAVE_WINSOCK2_H=1
  104. SYS_IOCTL_H_HAVE_WINSOCK2_H=1
  105. else
  106. HAVE_WINSOCK2_H=0
  107. fi
  108. AC_SUBST([HAVE_WINSOCK2_H])
  109. ])
  110. AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR],
  111. [
  112. dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
  113. AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
  114. GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
  115. ])
  116. AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
  117. [
  118. GNULIB_SOCKET=0; AC_SUBST([GNULIB_SOCKET])
  119. GNULIB_CONNECT=0; AC_SUBST([GNULIB_CONNECT])
  120. GNULIB_ACCEPT=0; AC_SUBST([GNULIB_ACCEPT])
  121. GNULIB_BIND=0; AC_SUBST([GNULIB_BIND])
  122. GNULIB_GETPEERNAME=0; AC_SUBST([GNULIB_GETPEERNAME])
  123. GNULIB_GETSOCKNAME=0; AC_SUBST([GNULIB_GETSOCKNAME])
  124. GNULIB_GETSOCKOPT=0; AC_SUBST([GNULIB_GETSOCKOPT])
  125. GNULIB_LISTEN=0; AC_SUBST([GNULIB_LISTEN])
  126. GNULIB_RECV=0; AC_SUBST([GNULIB_RECV])
  127. GNULIB_SEND=0; AC_SUBST([GNULIB_SEND])
  128. GNULIB_RECVFROM=0; AC_SUBST([GNULIB_RECVFROM])
  129. GNULIB_SENDTO=0; AC_SUBST([GNULIB_SENDTO])
  130. GNULIB_SETSOCKOPT=0; AC_SUBST([GNULIB_SETSOCKOPT])
  131. GNULIB_SHUTDOWN=0; AC_SUBST([GNULIB_SHUTDOWN])
  132. HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE])
  133. ])