Blame m4/sys_socket_h.m4

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