1# hostent.m4 serial 2
2dnl Copyright (C) 2008, 2010-2014 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_HOSTENT],
8[
9  dnl Where are gethostent(), sethostent(), endhostent(), gethostbyname(),
10  dnl gethostbyaddr() defined?
11  dnl - On Solaris, they are in libnsl. Ignore libxnet.
12  dnl - On Haiku, they are in libnetwork.
13  dnl - On BeOS, they are in libnet.
14  dnl - On native Windows, they are in ws2_32.dll.
15  dnl - Otherwise they are in libc.
16  AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
17  HOSTENT_LIB=
18  gl_saved_libs="$LIBS"
19  AC_SEARCH_LIBS([gethostbyname], [nsl network net],
20    [if test "$ac_cv_search_gethostbyname" != "none required"; then
21       HOSTENT_LIB="$ac_cv_search_gethostbyname"
22     fi])
23  LIBS="$gl_saved_libs"
24  if test -z "$HOSTENT_LIB"; then
25    AC_CHECK_FUNCS([gethostbyname], , [
26      AC_CACHE_CHECK([for gethostbyname in winsock2.h and -lws2_32],
27        [gl_cv_w32_gethostbyname],
28        [gl_cv_w32_gethostbyname=no
29         gl_save_LIBS="$LIBS"
30         LIBS="$LIBS -lws2_32"
31         AC_LINK_IFELSE(
32           [AC_LANG_PROGRAM(
33              [[
34#ifdef HAVE_WINSOCK2_H
35#include <winsock2.h>
36#endif
37#include <stddef.h>
38              ]],
39              [[gethostbyname(NULL);]])],
40           [gl_cv_w32_gethostbyname=yes])
41         LIBS="$gl_save_LIBS"
42        ])
43      if test "$gl_cv_w32_gethostbyname" = "yes"; then
44        HOSTENT_LIB="-lws2_32"
45      fi
46    ])
47  fi
48  AC_SUBST([HOSTENT_LIB])
49])
50