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