1dnl ****************************************
2dnl **** based on the KDE socklen_t test ***
3dnl ****************************************
4
5dnl Check for the type of the third argument of getsockname
6AC_DEFUN([ONMS_CHECK_SOCKLEN_T],
7[
8	AC_CHECK_HEADERS([sys/types.h sys/socket.h winsock2.h ws2tcpip.h])
9	AC_MSG_CHECKING(for socklen_t)
10	AC_CACHE_VAL(onms_cv_socklen_t,
11	[
12		onms_cv_socklen_t=no
13		AC_TRY_COMPILE([
14			#ifdef HAVE_SYS_TYPES_H
15			#include <sys/types.h>
16			#endif
17
18			#ifdef HAVE_SYS_SOCKET_H
19			#include <sys/socket.h>
20			#endif
21
22			#ifdef HAVE_WINSOCK2_H
23			#include <winsock2.h>
24			#endif
25
26			#ifdef HAVE_WS2TCPIP_H
27			#include <ws2tcpip.h>
28			#endif
29		],
30		[
31			socklen_t len;
32			getpeername(0,0,&len);
33		],
34		[
35			onms_cv_socklen_t=yes
36			onms_cv_socklen_t_equiv=socklen_t
37		])
38	])
39	AC_MSG_RESULT($onms_cv_socklen_t)
40	if test $onms_cv_socklen_t = no; then
41		AC_MSG_CHECKING([for socklen_t equivalent for socket functions])
42		AC_CACHE_VAL(onms_cv_socklen_t_equiv,
43		[
44			onms_cv_socklen_t_equiv=int
45			for t in int size_t unsigned long "unsigned long"; do
46				AC_TRY_COMPILE([
47					#ifdef HAVE_SYS_TYPES_H
48					#include <sys/types.h>
49					#endif
50
51					#ifdef HAVE_SYS_SOCKET_H
52					#include <sys/socket.h>
53					#endif
54
55					#ifdef HAVE_WINSOCK2_H
56					#include <winsock2.h>
57					#endif
58
59					#ifdef HAVE_WS2TCPIP_H
60					#include <ws2tcpip.h>
61					#endif
62				],
63				[
64					$t len;
65					getpeername(0,0,&len);
66				],
67				[
68					onms_cv_socklen_t_equiv="$t"
69					break
70				])
71			done
72		])
73		AC_MSG_RESULT($onms_cv_socklen_t_equiv)
74	fi
75	AC_DEFINE_UNQUOTED(onms_socklen_t, $onms_cv_socklen_t_equiv, [type to use in place of socklen_t if not defined])
76])
77