Blame gnulib/m4/sys_socket_h.m4

Packit eba2e2
# sys_socket_h.m4 serial 23
Packit eba2e2
dnl Copyright (C) 2005-2014 Free Software Foundation, Inc.
Packit eba2e2
dnl This file is free software; the Free Software Foundation
Packit eba2e2
dnl gives unlimited permission to copy and/or distribute it,
Packit eba2e2
dnl with or without modifications, as long as this notice is preserved.
Packit eba2e2
Packit eba2e2
dnl From Simon Josefsson.
Packit eba2e2
Packit eba2e2
AC_DEFUN([gl_HEADER_SYS_SOCKET],
Packit eba2e2
[
Packit eba2e2
  AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
Packit eba2e2
  AC_REQUIRE([AC_CANONICAL_HOST])
Packit eba2e2
Packit eba2e2
  dnl On OSF/1, the functions recv(), send(), recvfrom(), sendto() have
Packit eba2e2
  dnl old-style declarations (with return type 'int' instead of 'ssize_t')
Packit eba2e2
  dnl unless _POSIX_PII_SOCKET is defined.
Packit eba2e2
  case "$host_os" in
Packit eba2e2
    osf*)
Packit eba2e2
      AC_DEFINE([_POSIX_PII_SOCKET], [1],
Packit eba2e2
        [Define to 1 in order to get the POSIX compatible declarations
Packit eba2e2
         of socket functions.])
Packit eba2e2
      ;;
Packit eba2e2
  esac
Packit eba2e2
Packit eba2e2
  AC_CACHE_CHECK([whether <sys/socket.h> is self-contained],
Packit eba2e2
    [gl_cv_header_sys_socket_h_selfcontained],
Packit eba2e2
    [
Packit eba2e2
      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>]], [[]])],
Packit eba2e2
        [gl_cv_header_sys_socket_h_selfcontained=yes],
Packit eba2e2
        [gl_cv_header_sys_socket_h_selfcontained=no])
Packit eba2e2
    ])
Packit eba2e2
  if test $gl_cv_header_sys_socket_h_selfcontained = yes; then
Packit eba2e2
    dnl If the shutdown function exists, <sys/socket.h> should define
Packit eba2e2
    dnl SHUT_RD, SHUT_WR, SHUT_RDWR.
Packit eba2e2
    AC_CHECK_FUNCS([shutdown])
Packit eba2e2
    if test $ac_cv_func_shutdown = yes; then
Packit eba2e2
      AC_CACHE_CHECK([whether <sys/socket.h> defines the SHUT_* macros],
Packit eba2e2
        [gl_cv_header_sys_socket_h_shut],
Packit eba2e2
        [
Packit eba2e2
          AC_COMPILE_IFELSE(
Packit eba2e2
            [AC_LANG_PROGRAM([[#include <sys/socket.h>]],
Packit eba2e2
               [[int a[] = { SHUT_RD, SHUT_WR, SHUT_RDWR };]])],
Packit eba2e2
            [gl_cv_header_sys_socket_h_shut=yes],
Packit eba2e2
            [gl_cv_header_sys_socket_h_shut=no])
Packit eba2e2
        ])
Packit eba2e2
      if test $gl_cv_header_sys_socket_h_shut = no; then
Packit eba2e2
        SYS_SOCKET_H='sys/socket.h'
Packit eba2e2
      fi
Packit eba2e2
    fi
Packit eba2e2
  fi
Packit eba2e2
  # We need to check for ws2tcpip.h now.
Packit eba2e2
  gl_PREREQ_SYS_H_SOCKET
Packit eba2e2
  AC_CHECK_TYPES([struct sockaddr_storage, sa_family_t],,,[
Packit eba2e2
  /* sys/types.h is not needed according to POSIX, but the
Packit eba2e2
     sys/socket.h in i386-unknown-freebsd4.10 and
Packit eba2e2
     powerpc-apple-darwin5.5 required it. */
Packit eba2e2
#include <sys/types.h>
Packit eba2e2
#ifdef HAVE_SYS_SOCKET_H
Packit eba2e2
#include <sys/socket.h>
Packit eba2e2
#endif
Packit eba2e2
#ifdef HAVE_WS2TCPIP_H
Packit eba2e2
#include <ws2tcpip.h>
Packit eba2e2
#endif
Packit eba2e2
])
Packit eba2e2
  if test $ac_cv_type_struct_sockaddr_storage = no; then
Packit eba2e2
    HAVE_STRUCT_SOCKADDR_STORAGE=0
Packit eba2e2
  fi
Packit eba2e2
  if test $ac_cv_type_sa_family_t = no; then
Packit eba2e2
    HAVE_SA_FAMILY_T=0
Packit eba2e2
  fi
Packit eba2e2
  if test $ac_cv_type_struct_sockaddr_storage != no; then
Packit eba2e2
    AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family],
Packit eba2e2
      [],
Packit eba2e2
      [HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=0],
Packit eba2e2
      [#include <sys/types.h>
Packit eba2e2
       #ifdef HAVE_SYS_SOCKET_H
Packit eba2e2
       #include <sys/socket.h>
Packit eba2e2
       #endif
Packit eba2e2
       #ifdef HAVE_WS2TCPIP_H
Packit eba2e2
       #include <ws2tcpip.h>
Packit eba2e2
       #endif
Packit eba2e2
      ])
Packit eba2e2
  fi
Packit eba2e2
  if test $HAVE_STRUCT_SOCKADDR_STORAGE = 0 || test $HAVE_SA_FAMILY_T = 0 \
Packit eba2e2
     || test $HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY = 0; then
Packit eba2e2
    SYS_SOCKET_H='sys/socket.h'
Packit eba2e2
  fi
Packit eba2e2
  gl_PREREQ_SYS_H_WINSOCK2
Packit eba2e2
Packit eba2e2
  dnl Check for declarations of anything we want to poison if the
Packit eba2e2
  dnl corresponding gnulib module is not in use.
Packit eba2e2
  gl_WARN_ON_USE_PREPARE([[
Packit eba2e2
/* Some systems require prerequisite headers.  */
Packit eba2e2
#include <sys/types.h>
Packit eba2e2
#include <sys/socket.h>
Packit eba2e2
    ]], [socket connect accept bind getpeername getsockname getsockopt
Packit eba2e2
    listen recv send recvfrom sendto setsockopt shutdown accept4])
Packit eba2e2
])
Packit eba2e2
Packit eba2e2
AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
Packit eba2e2
[
Packit eba2e2
  dnl Check prerequisites of the <sys/socket.h> replacement.
Packit eba2e2
  AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])
Packit eba2e2
  gl_CHECK_NEXT_HEADERS([sys/socket.h])
Packit eba2e2
  if test $ac_cv_header_sys_socket_h = yes; then
Packit eba2e2
    HAVE_SYS_SOCKET_H=1
Packit eba2e2
    HAVE_WS2TCPIP_H=0
Packit eba2e2
  else
Packit eba2e2
    HAVE_SYS_SOCKET_H=0
Packit eba2e2
    if test $ac_cv_header_ws2tcpip_h = yes; then
Packit eba2e2
      HAVE_WS2TCPIP_H=1
Packit eba2e2
    else
Packit eba2e2
      HAVE_WS2TCPIP_H=0
Packit eba2e2
    fi
Packit eba2e2
  fi
Packit eba2e2
  AC_SUBST([HAVE_SYS_SOCKET_H])
Packit eba2e2
  AC_SUBST([HAVE_WS2TCPIP_H])
Packit eba2e2
])
Packit eba2e2
Packit eba2e2
# Common prerequisites of the <sys/socket.h> replacement and of the
Packit eba2e2
# <sys/select.h> replacement.
Packit eba2e2
# Sets and substitutes HAVE_WINSOCK2_H.
Packit eba2e2
AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2],
Packit eba2e2
[
Packit eba2e2
  m4_ifdef([gl_UNISTD_H_DEFAULTS], [AC_REQUIRE([gl_UNISTD_H_DEFAULTS])])
Packit eba2e2
  m4_ifdef([gl_SYS_IOCTL_H_DEFAULTS], [AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])])
Packit eba2e2
  AC_CHECK_HEADERS_ONCE([sys/socket.h])
Packit eba2e2
  if test $ac_cv_header_sys_socket_h != yes; then
Packit eba2e2
    dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
Packit eba2e2
    dnl the check for those headers unconditional; yet cygwin reports
Packit eba2e2
    dnl that the headers are present but cannot be compiled (since on
Packit eba2e2
    dnl cygwin, all socket information should come from sys/socket.h).
Packit eba2e2
    AC_CHECK_HEADERS([winsock2.h])
Packit eba2e2
  fi
Packit eba2e2
  if test "$ac_cv_header_winsock2_h" = yes; then
Packit eba2e2
    HAVE_WINSOCK2_H=1
Packit eba2e2
    UNISTD_H_HAVE_WINSOCK2_H=1
Packit eba2e2
    SYS_IOCTL_H_HAVE_WINSOCK2_H=1
Packit eba2e2
  else
Packit eba2e2
    HAVE_WINSOCK2_H=0
Packit eba2e2
  fi
Packit eba2e2
  AC_SUBST([HAVE_WINSOCK2_H])
Packit eba2e2
])
Packit eba2e2
Packit eba2e2
AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR],
Packit eba2e2
[
Packit eba2e2
  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
Packit eba2e2
  AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
Packit eba2e2
  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
Packit eba2e2
  dnl Define it also as a C macro, for the benefit of the unit tests.
Packit eba2e2
  gl_MODULE_INDICATOR_FOR_TESTS([$1])
Packit eba2e2
])
Packit eba2e2
Packit eba2e2
AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
Packit eba2e2
[
Packit eba2e2
  GNULIB_SOCKET=0;      AC_SUBST([GNULIB_SOCKET])
Packit eba2e2
  GNULIB_CONNECT=0;     AC_SUBST([GNULIB_CONNECT])
Packit eba2e2
  GNULIB_ACCEPT=0;      AC_SUBST([GNULIB_ACCEPT])
Packit eba2e2
  GNULIB_BIND=0;        AC_SUBST([GNULIB_BIND])
Packit eba2e2
  GNULIB_GETPEERNAME=0; AC_SUBST([GNULIB_GETPEERNAME])
Packit eba2e2
  GNULIB_GETSOCKNAME=0; AC_SUBST([GNULIB_GETSOCKNAME])
Packit eba2e2
  GNULIB_GETSOCKOPT=0;  AC_SUBST([GNULIB_GETSOCKOPT])
Packit eba2e2
  GNULIB_LISTEN=0;      AC_SUBST([GNULIB_LISTEN])
Packit eba2e2
  GNULIB_RECV=0;        AC_SUBST([GNULIB_RECV])
Packit eba2e2
  GNULIB_SEND=0;        AC_SUBST([GNULIB_SEND])
Packit eba2e2
  GNULIB_RECVFROM=0;    AC_SUBST([GNULIB_RECVFROM])
Packit eba2e2
  GNULIB_SENDTO=0;      AC_SUBST([GNULIB_SENDTO])
Packit eba2e2
  GNULIB_SETSOCKOPT=0;  AC_SUBST([GNULIB_SETSOCKOPT])
Packit eba2e2
  GNULIB_SHUTDOWN=0;    AC_SUBST([GNULIB_SHUTDOWN])
Packit eba2e2
  GNULIB_ACCEPT4=0;     AC_SUBST([GNULIB_ACCEPT4])
Packit eba2e2
  HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE])
Packit eba2e2
  HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=1;
Packit eba2e2
                        AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY])
Packit eba2e2
  HAVE_SA_FAMILY_T=1;   AC_SUBST([HAVE_SA_FAMILY_T])
Packit eba2e2
  HAVE_ACCEPT4=1;       AC_SUBST([HAVE_ACCEPT4])
Packit eba2e2
])