| 1 |
# socketlib.m4 |
| 2 |
# serial 4 |
| 3 |
dnl Copyright (C) 2008-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 gl_SOCKETLIB |
| 10 |
dnl Determines the library to use for socket functions. |
| 11 |
dnl Sets and AC_SUBSTs LIBSOCKET. |
| 12 |
|
| 13 |
AC_DEFUN([gl_SOCKETLIB], |
| 14 |
[ |
| 15 |
gl_PREREQ_SYS_H_WINSOCK2 dnl for HAVE_WINSOCK2_H |
| 16 |
LIBSOCKET= |
| 17 |
if test $HAVE_WINSOCK2_H = 1; then |
| 18 |
dnl Native Windows API (not Cygwin). |
| 19 |
dnl If the function WSAStartup exists (declared in <winsock2.h> and |
| 20 |
dnl defined through -lws2_32), we need to call it. |
| 21 |
AC_CACHE_CHECK([for WSAStartup], |
| 22 |
[gl_cv_func_wsastartup], [ |
| 23 |
gl_saved_LIBS="$LIBS" |
| 24 |
LIBS="$LIBS -lws2_32" |
| 25 |
AC_LINK_IFELSE( |
| 26 |
[AC_LANG_PROGRAM([[ |
| 27 |
#ifdef HAVE_WINSOCK2_H |
| 28 |
# include <winsock2.h> |
| 29 |
#endif]], [[ |
| 30 |
WORD wVersionRequested = MAKEWORD(1, 1); |
| 31 |
WSADATA wsaData; |
| 32 |
int err = WSAStartup(wVersionRequested, &wsaData); |
| 33 |
WSACleanup (); |
| 34 |
]]) |
| 35 |
], |
| 36 |
[gl_cv_func_wsastartup=yes], |
| 37 |
[gl_cv_func_wsastartup=no]) |
| 38 |
LIBS="$gl_saved_LIBS" |
| 39 |
]) |
| 40 |
if test "$gl_cv_func_wsastartup" = "yes"; then |
| 41 |
AC_DEFINE([WINDOWS_SOCKETS], [1], [Define if WSAStartup is needed.]) |
| 42 |
LIBSOCKET='-lws2_32' |
| 43 |
fi |
| 44 |
else |
| 45 |
dnl Unix API. |
| 46 |
dnl Solaris has most socket functions in libsocket. |
| 47 |
dnl Haiku has most socket functions in libnetwork. |
| 48 |
dnl BeOS has most socket functions in libnet. |
| 49 |
dnl On HP-UX, do NOT link with libxnet, because in 64-bit mode this would |
| 50 |
dnl break code (e.g. in libraries) that invokes accept(), getpeername(), |
| 51 |
dnl getsockname(), getsockopt(), or recvfrom() with a 32-bit addrlen. See |
| 52 |
dnl "man xopen_networking" for details. |
| 53 |
AC_CACHE_CHECK([for library containing setsockopt], [gl_cv_lib_socket], [ |
| 54 |
gl_cv_lib_socket= |
| 55 |
AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern |
| 56 |
#ifdef __cplusplus |
| 57 |
"C" |
| 58 |
#endif |
| 59 |
char setsockopt();]], [[setsockopt();]])], |
| 60 |
[], |
| 61 |
[gl_saved_LIBS="$LIBS" |
| 62 |
LIBS="$gl_saved_LIBS -lsocket" |
| 63 |
AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern |
| 64 |
#ifdef __cplusplus |
| 65 |
"C" |
| 66 |
#endif |
| 67 |
char setsockopt();]], [[setsockopt();]])], |
| 68 |
[gl_cv_lib_socket="-lsocket"]) |
| 69 |
if test -z "$gl_cv_lib_socket"; then |
| 70 |
LIBS="$gl_saved_LIBS -lnetwork" |
| 71 |
AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern |
| 72 |
#ifdef __cplusplus |
| 73 |
"C" |
| 74 |
#endif |
| 75 |
char setsockopt();]], [[setsockopt();]])], |
| 76 |
[gl_cv_lib_socket="-lnetwork"]) |
| 77 |
if test -z "$gl_cv_lib_socket"; then |
| 78 |
LIBS="$gl_saved_LIBS -lnet" |
| 79 |
AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern |
| 80 |
#ifdef __cplusplus |
| 81 |
"C" |
| 82 |
#endif |
| 83 |
char setsockopt();]], [[setsockopt();]])], |
| 84 |
[gl_cv_lib_socket="-lnet"]) |
| 85 |
fi |
| 86 |
fi |
| 87 |
LIBS="$gl_saved_LIBS" |
| 88 |
]) |
| 89 |
if test -z "$gl_cv_lib_socket"; then |
| 90 |
gl_cv_lib_socket="none needed" |
| 91 |
fi |
| 92 |
]) |
| 93 |
if test "$gl_cv_lib_socket" != "none needed"; then |
| 94 |
LIBSOCKET="$gl_cv_lib_socket" |
| 95 |
fi |
| 96 |
fi |
| 97 |
AC_SUBST([LIBSOCKET]) |
| 98 |
]) |