Blame m4/sys_socket_h.m4

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