1dnl -- The following is base of curl's acinclude.m4 --
2dnl Check for socklen_t: historically on BSD it is an int, and in
3dnl POSIX 1g it is a type of its own, but some platforms use different
4dnl types for the argument to getsockopt, getpeername, etc.  So we
5dnl have to test to find something that will work.
6AC_DEFUN([AX_TYPE_SOCKLEN_T], [
7	AC_CHECK_TYPE(
8		[socklen_t],
9		,
10		[
11			AS_VAR_PUSHDEF([VAR],[ax_cv_socklen_t_equiv])dnl
12			AC_CACHE_CHECK(
13				[for socklen_t equivalent],
14				[VAR],
15				[
16					#AS_CASE is not supported on <autoconf-2.60
17					case "${host}" in
18					*-mingw*) VAR=int ;;
19					*)
20						# Systems have either "struct sockaddr *" or
21						# "void *" as the second argument to getpeername
22						for arg2 in "struct sockaddr" void; do
23							for t in int size_t unsigned long "unsigned long"; do
24								AC_COMPILE_IFELSE(
25									[AC_LANG_PROGRAM(
26										[[
27#include <sys/types.h>
28#include <sys/socket.h>
29int getpeername (int, $arg2 *, $t *);
30										]],
31										[[
32$t len;
33getpeername(0,0,&len);
34										]]
35									)],
36									[VAR="$t"; break]
37								)
38							done
39							test -n "$VAR" && break
40						done
41						;;
42					esac
43				]
44				AS_VAR_IF(
45					[VAR],
46					[],
47					[AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])],
48					[AC_DEFINE_UNQUOTED(
49						[socklen_t],
50						[$VAR],
51						[type to use in place of socklen_t if not defined]
52					)]
53				)
54			)
55		],
56		[[
57#include <sys/types.h>
58#ifdef WIN32
59#include <ws2tcpip.h>
60#else
61#include <sys/socket.h>
62#endif
63		]]
64	)
65])
66