hostent.m4 1.6 KB

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