Blame m4/socklen.m4

Packit Service 4684c1
# socklen.m4 serial 11
Packit Service 4684c1
dnl Copyright (C) 2005-2007, 2009-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 Albert Chin, Windows fixes from Simon Josefsson.
Packit Service 4684c1
Packit Service 4684c1
dnl Check for socklen_t: historically on BSD it is an int, and in
Packit Service 4684c1
dnl POSIX 1g it is a type of its own, but some platforms use different
Packit Service 4684c1
dnl types for the argument to getsockopt, getpeername, etc.:
Packit Service 4684c1
dnl HP-UX 10.20, IRIX 6.5, OSF/1 4.0, Interix 3.5, BeOS.
Packit Service 4684c1
dnl So we have to test to find something that will work.
Packit Service 4684c1
Packit Service 4684c1
AC_DEFUN([gl_TYPE_SOCKLEN_T],
Packit Service 4684c1
  [AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])dnl
Packit Service 4684c1
   AC_CHECK_TYPE([socklen_t], ,
Packit Service 4684c1
     [AC_CACHE_CHECK([for socklen_t equivalent],
Packit Service 4684c1
        [gl_cv_socklen_t_equiv],
Packit Service 4684c1
        [# Systems have either "struct sockaddr *" or
Packit Service 4684c1
         # "void *" as the second argument to getpeername
Packit Service 4684c1
         gl_cv_socklen_t_equiv=
Packit Service 4684c1
         for arg2 in "struct sockaddr" void; do
Packit Service 4684c1
           for t in int size_t "unsigned int" "long int" "unsigned long int"; do
Packit Service 4684c1
             AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Packit Service 4684c1
                 [[#include <sys/types.h>
Packit Service 4684c1
                   #include <sys/socket.h>
Packit Service 4684c1
Packit Service 4684c1
                   int getpeername (int, $arg2 *, $t *);]],
Packit Service 4684c1
                 [[$t len;
Packit Service 4684c1
                  getpeername (0, 0, &len;;]])],
Packit Service 4684c1
               [gl_cv_socklen_t_equiv="$t"])
Packit Service 4684c1
             test "$gl_cv_socklen_t_equiv" != "" && break
Packit Service 4684c1
           done
Packit Service 4684c1
           test "$gl_cv_socklen_t_equiv" != "" && break
Packit Service 4684c1
         done
Packit Service 4684c1
         if test "$gl_cv_socklen_t_equiv" = ""; then
Packit Service 4684c1
           AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
Packit Service 4684c1
         fi
Packit Service 4684c1
        ])
Packit Service 4684c1
      AC_DEFINE_UNQUOTED([socklen_t], [$gl_cv_socklen_t_equiv],
Packit Service 4684c1
        [type to use in place of socklen_t if not defined])],
Packit Service 4684c1
     [gl_SOCKET_HEADERS])])
Packit Service 4684c1
Packit Service 4684c1
dnl On mingw32, socklen_t is in ws2tcpip.h ('int'), so we try to find
Packit Service 4684c1
dnl it there too.  But on Cygwin, wc2tcpip.h must not be included.  Users
Packit Service 4684c1
dnl of this module should use the same include pattern as gl_SOCKET_HEADERS.
Packit Service 4684c1
dnl When you change this macro, keep also in sync:
Packit Service 4684c1
dnl   - gl_CHECK_SOCKET_HEADERS,
Packit Service 4684c1
dnl   - the Include section of modules/socklen.
Packit Service 4684c1
AC_DEFUN([gl_SOCKET_HEADERS],
Packit Service 4684c1
[
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
#if HAVE_SYS_SOCKET_H
Packit Service 4684c1
# include <sys/socket.h>
Packit Service 4684c1
#elif HAVE_WS2TCPIP_H
Packit Service 4684c1
# include <ws2tcpip.h>
Packit Service 4684c1
#endif
Packit Service 4684c1
])
Packit Service 4684c1
Packit Service 4684c1
dnl Tests for the existence of the header for socket facilities.
Packit Service 4684c1
dnl Defines the C macros HAVE_SYS_SOCKET_H, HAVE_WS2TCPIP_H.
Packit Service 4684c1
dnl This macro must match gl_SOCKET_HEADERS.
Packit Service 4684c1
AC_DEFUN([gl_CHECK_SOCKET_HEADERS],
Packit Service 4684c1
  [AC_CHECK_HEADERS_ONCE([sys/socket.h])
Packit Service 4684c1
   if test $ac_cv_header_sys_socket_h = no; 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([ws2tcpip.h])
Packit Service 4684c1
   fi
Packit Service 4684c1
  ])