attribute: Improve documentation.
[gnulib.git] / m4 / hostent.m4
blob36dc636ed4cfc40ae4a95ca3c74a403b3ff25a05
1 # hostent.m4
2 # serial 5
3 dnl Copyright (C) 2008, 2010-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.
8 AC_DEFUN([gl_HOSTENT],
10   dnl Where are gethostent(), sethostent(), endhostent(), gethostbyname(),
11   dnl gethostbyaddr() defined?
12   dnl - On Solaris < 11.4, they are in libnsl. Ignore libxnet.
13   dnl - On Haiku, they are in libnetwork.
14   dnl - On BeOS, they are in libnet.
15   dnl - On native Windows, they are in ws2_32.dll.
16   dnl - Otherwise they are in libc.
17   AC_REQUIRE([gl_SYS_SOCKET_H])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
18   HOSTENT_LIB=
19   gl_saved_libs="$LIBS"
20   AC_SEARCH_LIBS([gethostbyname], [nsl network net],
21     [if test "$ac_cv_search_gethostbyname" != "none required"; then
22        HOSTENT_LIB="$ac_cv_search_gethostbyname"
23      fi])
24   LIBS="$gl_saved_libs"
25   if test -z "$HOSTENT_LIB"; then
26     AC_CHECK_FUNCS([gethostbyname], , [
27       AC_CACHE_CHECK([for gethostbyname in winsock2.h and -lws2_32],
28         [gl_cv_w32_gethostbyname],
29         [gl_cv_w32_gethostbyname=no
30          gl_saved_LIBS="$LIBS"
31          LIBS="$LIBS -lws2_32"
32          AC_LINK_IFELSE(
33            [AC_LANG_PROGRAM(
34               [[
35 #ifdef HAVE_WINSOCK2_H
36 #include <winsock2.h>
37 #endif
38 #include <stddef.h>
39               ]],
40               [[gethostbyname(NULL);]])],
41            [gl_cv_w32_gethostbyname=yes])
42          LIBS="$gl_saved_LIBS"
43         ])
44       if test "$gl_cv_w32_gethostbyname" = "yes"; then
45         HOSTENT_LIB="-lws2_32"
46       fi
47     ])
48   fi
49   AC_SUBST([HOSTENT_LIB])