Commit | Line | Data |
---|---|---|
401bf9b4 PE |
1 | # socklen.m4 serial 9 |
2 | dnl Copyright (C) 2005-2007, 2009-2011 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 if they want to be portable to | |
18 | dnl mingw32. Cygwin must not include ws2tcpip.h. | |
19 | AC_DEFUN([gl_TYPE_SOCKLEN_T], | |
20 | [AC_REQUIRE([gl_PREREQ_TYPE_SOCKLEN_T])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 | ]m4_ifdef([gl_SYS_SOCKET_H_DEFAULTS], | |
52 | [#elif HAVE_WS2TCPIP_H | |
53 | # include <ws2tcpip.h>] | |
54 | )[#endif])]) | |
55 | ||
56 | AC_DEFUN([gl_PREREQ_TYPE_SOCKLEN_T], | |
57 | [AC_CHECK_HEADERS_ONCE([sys/socket.h]) | |
58 | m4_ifdef([gl_SYS_SOCKET_H_DEFAULTS], | |
59 | [if test $ac_cv_header_sys_socket_h = no; then | |
60 | dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make | |
61 | dnl the check for those headers unconditional; yet cygwin reports | |
62 | dnl that the headers are present but cannot be compiled (since on | |
63 | dnl cygwin, all socket information should come from sys/socket.h). | |
64 | AC_CHECK_HEADERS([ws2tcpip.h]) | |
65 | fi])]) |