Blame m4/sys_socket_h.m4

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