Home | History | Annotate | Line # | Download | only in m4
      1      1.1  christos # socklen.m4 serial 11
      2  1.1.1.2  christos dnl Copyright (C) 2005-2007, 2009-2022 Free Software Foundation, Inc.
      3      1.1  christos dnl This file is free software; the Free Software Foundation
      4      1.1  christos dnl gives unlimited permission to copy and/or distribute it,
      5      1.1  christos dnl with or without modifications, as long as this notice is preserved.
      6      1.1  christos 
      7      1.1  christos dnl From Albert Chin, Windows fixes from Simon Josefsson.
      8      1.1  christos 
      9      1.1  christos dnl Check for socklen_t: historically on BSD it is an int, and in
     10      1.1  christos dnl POSIX 1g it is a type of its own, but some platforms use different
     11      1.1  christos dnl types for the argument to getsockopt, getpeername, etc.:
     12      1.1  christos dnl HP-UX 10.20, IRIX 6.5, OSF/1 4.0, Interix 3.5, BeOS.
     13      1.1  christos dnl So we have to test to find something that will work.
     14      1.1  christos 
     15      1.1  christos AC_DEFUN([gl_TYPE_SOCKLEN_T],
     16      1.1  christos   [AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])dnl
     17      1.1  christos    AC_CHECK_TYPE([socklen_t], ,
     18      1.1  christos      [AC_CACHE_CHECK([for socklen_t equivalent],
     19      1.1  christos         [gl_cv_socklen_t_equiv],
     20      1.1  christos         [# Systems have either "struct sockaddr *" or
     21      1.1  christos          # "void *" as the second argument to getpeername
     22      1.1  christos          gl_cv_socklen_t_equiv=
     23      1.1  christos          for arg2 in "struct sockaddr" void; do
     24      1.1  christos            for t in int size_t "unsigned int" "long int" "unsigned long int"; do
     25      1.1  christos              AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
     26      1.1  christos                  [[#include <sys/types.h>
     27      1.1  christos                    #include <sys/socket.h>
     28      1.1  christos 
     29      1.1  christos                    int getpeername (int, $arg2 *, $t *);]],
     30      1.1  christos                  [[$t len;
     31      1.1  christos                   getpeername (0, 0, &len);]])],
     32      1.1  christos                [gl_cv_socklen_t_equiv="$t"])
     33      1.1  christos              test "$gl_cv_socklen_t_equiv" != "" && break
     34      1.1  christos            done
     35      1.1  christos            test "$gl_cv_socklen_t_equiv" != "" && break
     36      1.1  christos          done
     37      1.1  christos          if test "$gl_cv_socklen_t_equiv" = ""; then
     38      1.1  christos            AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
     39      1.1  christos          fi
     40      1.1  christos         ])
     41      1.1  christos       AC_DEFINE_UNQUOTED([socklen_t], [$gl_cv_socklen_t_equiv],
     42      1.1  christos         [type to use in place of socklen_t if not defined])],
     43      1.1  christos      [gl_SOCKET_HEADERS])])
     44      1.1  christos 
     45      1.1  christos dnl On mingw32, socklen_t is in ws2tcpip.h ('int'), so we try to find
     46      1.1  christos dnl it there too.  But on Cygwin, wc2tcpip.h must not be included.  Users
     47      1.1  christos dnl of this module should use the same include pattern as gl_SOCKET_HEADERS.
     48      1.1  christos dnl When you change this macro, keep also in sync:
     49      1.1  christos dnl   - gl_CHECK_SOCKET_HEADERS,
     50      1.1  christos dnl   - the Include section of modules/socklen.
     51      1.1  christos AC_DEFUN([gl_SOCKET_HEADERS],
     52      1.1  christos [
     53      1.1  christos /* <sys/types.h> is not needed according to POSIX, but the
     54      1.1  christos    <sys/socket.h> in i386-unknown-freebsd4.10 and
     55      1.1  christos    powerpc-apple-darwin5.5 required it. */
     56      1.1  christos #include <sys/types.h>
     57      1.1  christos #if HAVE_SYS_SOCKET_H
     58      1.1  christos # include <sys/socket.h>
     59      1.1  christos #elif HAVE_WS2TCPIP_H
     60      1.1  christos # include <ws2tcpip.h>
     61      1.1  christos #endif
     62      1.1  christos ])
     63      1.1  christos 
     64      1.1  christos dnl Tests for the existence of the header for socket facilities.
     65      1.1  christos dnl Defines the C macros HAVE_SYS_SOCKET_H, HAVE_WS2TCPIP_H.
     66      1.1  christos dnl This macro must match gl_SOCKET_HEADERS.
     67      1.1  christos AC_DEFUN([gl_CHECK_SOCKET_HEADERS],
     68      1.1  christos   [AC_CHECK_HEADERS_ONCE([sys/socket.h])
     69      1.1  christos    if test $ac_cv_header_sys_socket_h = no; then
     70      1.1  christos      dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
     71      1.1  christos      dnl the check for those headers unconditional; yet cygwin reports
     72      1.1  christos      dnl that the headers are present but cannot be compiled (since on
     73      1.1  christos      dnl cygwin, all socket information should come from sys/socket.h).
     74      1.1  christos      AC_CHECK_HEADERS([ws2tcpip.h])
     75      1.1  christos    fi
     76      1.1  christos   ])
     77