getaddrinfo.m4 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # getaddrinfo.m4 serial 11
  2. dnl Copyright (C) 2004, 2005, 2006 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_GETADDRINFO],
  7. [
  8. AC_MSG_NOTICE([checking how to do getaddrinfo, freeaddrinfo and getnameinfo])
  9. AC_SEARCH_LIBS(getaddrinfo, [nsl socket])
  10. AC_CHECK_FUNCS(getaddrinfo,, [
  11. AC_CACHE_CHECK(for getaddrinfo in ws2tcpip.h and -lws2_32,
  12. gl_cv_w32_getaddrinfo, [
  13. gl_cv_w32_getaddrinfo=no
  14. am_save_LIBS="$LIBS"
  15. LIBS="$LIBS -lws2_32"
  16. AC_TRY_LINK([
  17. #ifdef HAVE_WS2TCPIP_H
  18. #include <ws2tcpip.h>
  19. #endif
  20. ], [getaddrinfo(0, 0, 0, 0);], gl_cv_w32_getaddrinfo=yes)
  21. LIBS="$am_save_LIBS"])
  22. if test "$gl_cv_w32_getaddrinfo" = "yes"; then
  23. LIBS="$LIBS -lws2_32"
  24. else
  25. AC_LIBOBJ(getaddrinfo)
  26. fi
  27. ])
  28. AC_REPLACE_FUNCS(gai_strerror)
  29. gl_PREREQ_GETADDRINFO
  30. ])
  31. # Prerequisites of lib/getaddrinfo.h and lib/getaddrinfo.c.
  32. AC_DEFUN([gl_PREREQ_GETADDRINFO], [
  33. AC_SEARCH_LIBS(gethostbyname, [inet nsl])
  34. AC_SEARCH_LIBS(getservbyname, [inet nsl socket xnet])
  35. AC_CHECK_FUNCS(gethostbyname,, [
  36. AC_CACHE_CHECK(for gethostbyname in winsock2.h and -lws2_32,
  37. gl_cv_w32_gethostbyname, [
  38. gl_cv_w32_gethostbyname=no
  39. am_save_LIBS="$LIBS"
  40. LIBS="$LIBS -lws2_32"
  41. AC_TRY_LINK([
  42. #ifdef HAVE_WINSOCK2_H
  43. #include <winsock2.h>
  44. #endif
  45. ], [gethostbyname(0);], gl_cv_w32_gethostbyname=yes)
  46. LIBS="$am_save_LIBS"])
  47. if test "$gl_cv_w32_gethostbyname" = "yes"; then
  48. LIBS="$LIBS -lws2_32"
  49. fi
  50. ])
  51. AC_REQUIRE([AC_C_RESTRICT])
  52. AC_REQUIRE([gl_SOCKET_FAMILIES])
  53. AC_REQUIRE([gl_HEADER_SYS_SOCKET])
  54. AC_REQUIRE([AC_C_INLINE])
  55. AC_REQUIRE([AC_GNU_SOURCE])
  56. AC_CHECK_HEADERS_ONCE(netinet/in.h netdb.h)
  57. AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[
  58. /* sys/types.h is not needed according to POSIX, but the
  59. sys/socket.h in i386-unknown-freebsd4.10 and
  60. powerpc-apple-darwin5.5 required it. */
  61. #include <sys/types.h>
  62. #ifdef HAVE_SYS_SOCKET_H
  63. #include <sys/socket.h>
  64. #endif
  65. #ifdef HAVE_NETDB_H
  66. #include <netdb.h>
  67. #endif
  68. #ifdef HAVE_WS2TCPIP_H
  69. #include <ws2tcpip.h>
  70. #endif
  71. ])
  72. AC_CHECK_TYPES([struct addrinfo],,,[
  73. #include <sys/types.h>
  74. #ifdef HAVE_SYS_SOCKET_H
  75. #include <sys/socket.h>
  76. #endif
  77. #ifdef HAVE_NETDB_H
  78. #include <netdb.h>
  79. #endif
  80. #ifdef HAVE_WS2TCPIP_H
  81. #include <ws2tcpip.h>
  82. #endif
  83. ])
  84. ])