diff options
Diffstat (limited to 'gl/m4/socklen.m4')
-rw-r--r-- | gl/m4/socklen.m4 | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/gl/m4/socklen.m4 b/gl/m4/socklen.m4 new file mode 100644 index 00000000..5e3765a6 --- /dev/null +++ b/gl/m4/socklen.m4 | |||
@@ -0,0 +1,52 @@ | |||
1 | # socklen.m4 serial 4 | ||
2 | dnl Copyright (C) 2005, 2006 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. So we | ||
12 | dnl have to test to find something that will work. | ||
13 | |||
14 | dnl On mingw32, socklen_t is in ws2tcpip.h ('int'), so we try to find | ||
15 | dnl it there first. That file is included by gnulib's socket_.h, which | ||
16 | dnl all users of this module should include. Cygwin must not include | ||
17 | dnl ws2tcpip.h. | ||
18 | AC_DEFUN([gl_TYPE_SOCKLEN_T], | ||
19 | [AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl | ||
20 | AC_CHECK_TYPE([socklen_t], , | ||
21 | [AC_MSG_CHECKING([for socklen_t equivalent]) | ||
22 | AC_CACHE_VAL([gl_cv_gl_cv_socklen_t_equiv], | ||
23 | [# Systems have either "struct sockaddr *" or | ||
24 | # "void *" as the second argument to getpeername | ||
25 | gl_cv_socklen_t_equiv= | ||
26 | for arg2 in "struct sockaddr" void; do | ||
27 | for t in int size_t "unsigned int" "long int" "unsigned long int"; do | ||
28 | AC_TRY_COMPILE( | ||
29 | [#include <sys/types.h> | ||
30 | #include <sys/socket.h> | ||
31 | |||
32 | int getpeername (int, $arg2 *, $t *);], | ||
33 | [$t len; | ||
34 | getpeername (0, 0, &len);], | ||
35 | [gl_cv_socklen_t_equiv="$t"]) | ||
36 | test "$gl_cv_socklen_t_equiv" != "" && break | ||
37 | done | ||
38 | test "$gl_cv_socklen_t_equiv" != "" && break | ||
39 | done | ||
40 | ]) | ||
41 | if test "$gl_cv_socklen_t_equiv" = ""; then | ||
42 | AC_MSG_ERROR([Cannot find a type to use in place of socklen_t]) | ||
43 | fi | ||
44 | AC_MSG_RESULT([$gl_cv_socklen_t_equiv]) | ||
45 | AC_DEFINE_UNQUOTED([socklen_t], [$gl_cv_socklen_t_equiv], | ||
46 | [type to use in place of socklen_t if not defined])], | ||
47 | [#include <sys/types.h> | ||
48 | #if HAVE_SYS_SOCKET_H | ||
49 | # include <sys/socket.h> | ||
50 | #elif HAVE_WS2TCPIP_H | ||
51 | # include <ws2tcpip.h> | ||
52 | #endif])]) | ||