| 1 |
# socklen.m4 |
| 2 |
# serial 11 |
| 3 |
dnl Copyright (C) 2005-2007, 2009-2024 Free Software Foundation, Inc. |
| 4 |
dnl This file is free software; the Free Software Foundation |
| 5 |
dnl gives unlimited permission to copy and/or distribute it, |
| 6 |
dnl with or without modifications, as long as this notice is preserved. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
dnl From Albert Chin, Windows fixes from Simon Josefsson. |
| 10 |
|
| 11 |
dnl Check for socklen_t: historically on BSD it is an int, and in |
| 12 |
dnl POSIX 1g it is a type of its own, but some platforms use different |
| 13 |
dnl types for the argument to getsockopt, getpeername, etc.: |
| 14 |
dnl HP-UX 10.20, IRIX 6.5, OSF/1 4.0, Interix 3.5, BeOS. |
| 15 |
dnl So we have to test to find something that will work. |
| 16 |
|
| 17 |
AC_DEFUN([gl_TYPE_SOCKLEN_T], |
| 18 |
[AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])dnl |
| 19 |
AC_CHECK_TYPE([socklen_t], , |
| 20 |
[AC_CACHE_CHECK([for socklen_t equivalent], |
| 21 |
[gl_cv_socklen_t_equiv], |
| 22 |
[# Systems have either "struct sockaddr *" or |
| 23 |
# "void *" as the second argument to getpeername |
| 24 |
gl_cv_socklen_t_equiv= |
| 25 |
for arg2 in "struct sockaddr" void; do |
| 26 |
for t in int size_t "unsigned int" "long int" "unsigned long int"; do |
| 27 |
AC_COMPILE_IFELSE([AC_LANG_PROGRAM( |
| 28 |
[[#include <sys/types.h> |
| 29 |
#include <sys/socket.h> |
| 30 |
|
| 31 |
int getpeername (int, $arg2 *, $t *);]], |
| 32 |
[[$t len; |
| 33 |
getpeername (0, 0, &len);]])], |
| 34 |
[gl_cv_socklen_t_equiv="$t"]) |
| 35 |
test "$gl_cv_socklen_t_equiv" != "" && break |
| 36 |
done |
| 37 |
test "$gl_cv_socklen_t_equiv" != "" && break |
| 38 |
done |
| 39 |
if test "$gl_cv_socklen_t_equiv" = ""; then |
| 40 |
AC_MSG_ERROR([Cannot find a type to use in place of socklen_t]) |
| 41 |
fi |
| 42 |
]) |
| 43 |
AC_DEFINE_UNQUOTED([socklen_t], [$gl_cv_socklen_t_equiv], |
| 44 |
[type to use in place of socklen_t if not defined])], |
| 45 |
[gl_SOCKET_HEADERS])]) |
| 46 |
|
| 47 |
dnl On mingw32, socklen_t is in ws2tcpip.h ('int'), so we try to find |
| 48 |
dnl it there too. But on Cygwin, wc2tcpip.h must not be included. Users |
| 49 |
dnl of this module should use the same include pattern as gl_SOCKET_HEADERS. |
| 50 |
dnl When you change this macro, keep also in sync: |
| 51 |
dnl - gl_CHECK_SOCKET_HEADERS, |
| 52 |
dnl - the Include section of modules/socklen. |
| 53 |
AC_DEFUN([gl_SOCKET_HEADERS], |
| 54 |
[ |
| 55 |
/* <sys/types.h> is not needed according to POSIX, but the |
| 56 |
<sys/socket.h> in i386-unknown-freebsd4.10 and |
| 57 |
powerpc-apple-darwin5.5 required it. */ |
| 58 |
#include <sys/types.h> |
| 59 |
#if HAVE_SYS_SOCKET_H |
| 60 |
# include <sys/socket.h> |
| 61 |
#elif HAVE_WS2TCPIP_H |
| 62 |
# include <ws2tcpip.h> |
| 63 |
#endif |
| 64 |
]) |
| 65 |
|
| 66 |
dnl Tests for the existence of the header for socket facilities. |
| 67 |
dnl Defines the C macros HAVE_SYS_SOCKET_H, HAVE_WS2TCPIP_H. |
| 68 |
dnl This macro must match gl_SOCKET_HEADERS. |
| 69 |
AC_DEFUN([gl_CHECK_SOCKET_HEADERS], |
| 70 |
[AC_CHECK_HEADERS_ONCE([sys/socket.h]) |
| 71 |
if test $ac_cv_header_sys_socket_h = no; then |
| 72 |
dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make |
| 73 |
dnl the check for those headers unconditional; yet cygwin reports |
| 74 |
dnl that the headers are present but cannot be compiled (since on |
| 75 |
dnl cygwin, all socket information should come from sys/socket.h). |
| 76 |
AC_CHECK_HEADERS([ws2tcpip.h]) |
| 77 |
fi |
| 78 |
]) |