Blame m4/socklen.m4

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