1 # socketlib.m4 serial 3
2 dnl Copyright (C) 2008-2020 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.
8 dnl Determines the library to use for socket functions.
9 dnl Sets and AC_SUBSTs LIBSOCKET.
11 AC_DEFUN([gl_SOCKETLIB],
13 gl_PREREQ_SYS_H_WINSOCK2 dnl for HAVE_WINSOCK2_H
15 if test $HAVE_WINSOCK2_H = 1; then
16 dnl Native Windows API (not Cygwin).
17 dnl If the function WSAStartup exists (declared in <winsock2.h> and
18 dnl defined through -lws2_32), we need to call it.
19 AC_CACHE_CHECK([for WSAStartup],
20 [gl_cv_func_wsastartup], [
25 #ifdef HAVE_WINSOCK2_H
26 # include <winsock2.h>
28 WORD wVersionRequested = MAKEWORD(1, 1);
30 int err = WSAStartup(wVersionRequested, &wsaData);
34 [gl_cv_func_wsastartup=yes],
35 [gl_cv_func_wsastartup=no])
38 if test "$gl_cv_func_wsastartup" = "yes"; then
39 AC_DEFINE([WINDOWS_SOCKETS], [1], [Define if WSAStartup is needed.])
44 dnl Solaris has most socket functions in libsocket.
45 dnl Haiku has most socket functions in libnetwork.
46 dnl BeOS has most socket functions in libnet.
47 dnl On HP-UX, do NOT link with libxnet, because in 64-bit mode this would
48 dnl break code (e.g. in libraries) that invokes accept(), getpeername(),
49 dnl getsockname(), getsockopt(), or recvfrom() with a 32-bit addrlen. See
50 dnl "man xopen_networking" for details.
51 AC_CACHE_CHECK([for library containing setsockopt], [gl_cv_lib_socket], [
53 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
57 char setsockopt();]], [[setsockopt();]])],
60 LIBS="$gl_save_LIBS -lsocket"
61 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
65 char setsockopt();]], [[setsockopt();]])],
66 [gl_cv_lib_socket="-lsocket"])
67 if test -z "$gl_cv_lib_socket"; then
68 LIBS="$gl_save_LIBS -lnetwork"
69 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
73 char setsockopt();]], [[setsockopt();]])],
74 [gl_cv_lib_socket="-lnetwork"])
75 if test -z "$gl_cv_lib_socket"; then
76 LIBS="$gl_save_LIBS -lnet"
77 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
81 char setsockopt();]], [[setsockopt();]])],
82 [gl_cv_lib_socket="-lnet"])
87 if test -z "$gl_cv_lib_socket"; then
88 gl_cv_lib_socket="none needed"
91 if test "$gl_cv_lib_socket" != "none needed"; then
92 LIBSOCKET="$gl_cv_lib_socket"