Imported Upstream version 3.2.0
[debian/amanda] / config / gnulib / socklen.m4
1 # socklen.m4 serial 8
2 dnl Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Albert Chin, Windows fixes from Simon Josefsson.
8
9 dnl Check for socklen_t: historically on BSD it is an int, and in
10 dnl POSIX 1g it is a type of its own, but some platforms use different
11 dnl types for the argument to getsockopt, getpeername, etc.:
12 dnl HP-UX 10.20, IRIX 6.5, Interix 3.5, BeOS.
13 dnl So we have to test to find something that will work.
14
15 dnl On mingw32, socklen_t is in ws2tcpip.h ('int'), so we try to find
16 dnl it there first.  That file is included by gnulib's sys_socket.in.h, which
17 dnl all users of this module should include.  Cygwin must not include
18 dnl ws2tcpip.h.
19 AC_DEFUN([gl_TYPE_SOCKLEN_T],
20   [AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl
21    AC_CHECK_TYPE([socklen_t], ,
22      [AC_MSG_CHECKING([for socklen_t equivalent])
23       AC_CACHE_VAL([gl_cv_socklen_t_equiv],
24         [# Systems have either "struct sockaddr *" or
25          # "void *" as the second argument to getpeername
26          gl_cv_socklen_t_equiv=
27          for arg2 in "struct sockaddr" void; do
28            for t in int size_t "unsigned int" "long int" "unsigned long int"; do
29              AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
30                  [[#include <sys/types.h>
31                    #include <sys/socket.h>
32
33                    int getpeername (int, $arg2 *, $t *);]],
34                  [[$t len;
35                   getpeername (0, 0, &len);]])],
36                [gl_cv_socklen_t_equiv="$t"])
37              test "$gl_cv_socklen_t_equiv" != "" && break
38            done
39            test "$gl_cv_socklen_t_equiv" != "" && break
40          done
41       ])
42       if test "$gl_cv_socklen_t_equiv" = ""; then
43         AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
44       fi
45       AC_MSG_RESULT([$gl_cv_socklen_t_equiv])
46       AC_DEFINE_UNQUOTED([socklen_t], [$gl_cv_socklen_t_equiv],
47         [type to use in place of socklen_t if not defined])],
48      [#include <sys/types.h>
49       #if HAVE_SYS_SOCKET_H
50       # include <sys/socket.h>
51       #elif HAVE_WS2TCPIP_H
52       # include <ws2tcpip.h>
53       #endif])])