Blame m4/socklen.m4

Packit 8f70b4
# socklen.m4 serial 10
Packit 8f70b4
dnl Copyright (C) 2005-2007, 2009-2018 Free Software Foundation, Inc.
Packit 8f70b4
dnl This file is free software; the Free Software Foundation
Packit 8f70b4
dnl gives unlimited permission to copy and/or distribute it,
Packit 8f70b4
dnl with or without modifications, as long as this notice is preserved.
Packit 8f70b4
Packit 8f70b4
dnl From Albert Chin, Windows fixes from Simon Josefsson.
Packit 8f70b4
Packit 8f70b4
dnl Check for socklen_t: historically on BSD it is an int, and in
Packit 8f70b4
dnl POSIX 1g it is a type of its own, but some platforms use different
Packit 8f70b4
dnl types for the argument to getsockopt, getpeername, etc.:
Packit 8f70b4
dnl HP-UX 10.20, IRIX 6.5, OSF/1 4.0, Interix 3.5, BeOS.
Packit 8f70b4
dnl So we have to test to find something that will work.
Packit 8f70b4
Packit 8f70b4
AC_DEFUN([gl_TYPE_SOCKLEN_T],
Packit 8f70b4
  [AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])dnl
Packit 8f70b4
   AC_CHECK_TYPE([socklen_t], ,
Packit 8f70b4
     [AC_MSG_CHECKING([for socklen_t equivalent])
Packit 8f70b4
      AC_CACHE_VAL([gl_cv_socklen_t_equiv],
Packit 8f70b4
        [# Systems have either "struct sockaddr *" or
Packit 8f70b4
         # "void *" as the second argument to getpeername
Packit 8f70b4
         gl_cv_socklen_t_equiv=
Packit 8f70b4
         for arg2 in "struct sockaddr" void; do
Packit 8f70b4
           for t in int size_t "unsigned int" "long int" "unsigned long int"; do
Packit 8f70b4
             AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Packit 8f70b4
                 [[#include <sys/types.h>
Packit 8f70b4
                   #include <sys/socket.h>
Packit 8f70b4
Packit 8f70b4
                   int getpeername (int, $arg2 *, $t *);]],
Packit 8f70b4
                 [[$t len;
Packit 8f70b4
                  getpeername (0, 0, &len;;]])],
Packit 8f70b4
               [gl_cv_socklen_t_equiv="$t"])
Packit 8f70b4
             test "$gl_cv_socklen_t_equiv" != "" && break
Packit 8f70b4
           done
Packit 8f70b4
           test "$gl_cv_socklen_t_equiv" != "" && break
Packit 8f70b4
         done
Packit 8f70b4
      ])
Packit 8f70b4
      if test "$gl_cv_socklen_t_equiv" = ""; then
Packit 8f70b4
        AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
Packit 8f70b4
      fi
Packit 8f70b4
      AC_MSG_RESULT([$gl_cv_socklen_t_equiv])
Packit 8f70b4
      AC_DEFINE_UNQUOTED([socklen_t], [$gl_cv_socklen_t_equiv],
Packit 8f70b4
        [type to use in place of socklen_t if not defined])],
Packit 8f70b4
     [gl_SOCKET_HEADERS])])
Packit 8f70b4
Packit 8f70b4
dnl On mingw32, socklen_t is in ws2tcpip.h ('int'), so we try to find
Packit 8f70b4
dnl it there too.  But on Cygwin, wc2tcpip.h must not be included.  Users
Packit 8f70b4
dnl of this module should use the same include pattern as gl_SOCKET_HEADERS.
Packit 8f70b4
dnl When you change this macro, keep also in sync:
Packit 8f70b4
dnl   - gl_CHECK_SOCKET_HEADERS,
Packit 8f70b4
dnl   - the Include section of modules/socklen.
Packit 8f70b4
AC_DEFUN([gl_SOCKET_HEADERS],
Packit 8f70b4
[
Packit 8f70b4
/* <sys/types.h> is not needed according to POSIX, but the
Packit 8f70b4
   <sys/socket.h> in i386-unknown-freebsd4.10 and
Packit 8f70b4
   powerpc-apple-darwin5.5 required it. */
Packit 8f70b4
#include <sys/types.h>
Packit 8f70b4
#if HAVE_SYS_SOCKET_H
Packit 8f70b4
# include <sys/socket.h>
Packit 8f70b4
#elif HAVE_WS2TCPIP_H
Packit 8f70b4
# include <ws2tcpip.h>
Packit 8f70b4
#endif
Packit 8f70b4
])
Packit 8f70b4
Packit 8f70b4
dnl Tests for the existence of the header for socket facilities.
Packit 8f70b4
dnl Defines the C macros HAVE_SYS_SOCKET_H, HAVE_WS2TCPIP_H.
Packit 8f70b4
dnl This macro must match gl_SOCKET_HEADERS.
Packit 8f70b4
AC_DEFUN([gl_CHECK_SOCKET_HEADERS],
Packit 8f70b4
  [AC_CHECK_HEADERS_ONCE([sys/socket.h])
Packit 8f70b4
   if test $ac_cv_header_sys_socket_h = no; then
Packit 8f70b4
     dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
Packit 8f70b4
     dnl the check for those headers unconditional; yet cygwin reports
Packit 8f70b4
     dnl that the headers are present but cannot be compiled (since on
Packit 8f70b4
     dnl cygwin, all socket information should come from sys/socket.h).
Packit 8f70b4
     AC_CHECK_HEADERS([ws2tcpip.h])
Packit 8f70b4
   fi
Packit 8f70b4
  ])