getaddrinfo.m4 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # getaddrinfo.m4 serial 15
  2. dnl Copyright (C) 2004, 2005, 2006, 2007 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_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
  9. AC_MSG_NOTICE([checking how to do getaddrinfo, freeaddrinfo and getnameinfo])
  10. AC_CHECK_HEADERS_ONCE(netdb.h)
  11. AC_SEARCH_LIBS(getaddrinfo, [nsl socket])
  12. AC_CACHE_CHECK([for getaddrinfo], [gl_cv_func_getaddrinfo], [
  13. AC_TRY_LINK([
  14. #include <sys/types.h>
  15. #ifdef HAVE_SYS_SOCKET_H
  16. #include <sys/socket.h>
  17. #endif
  18. #ifdef HAVE_NETDB_H
  19. #include <netdb.h>
  20. #endif
  21. #include <stddef.h>
  22. ], [getaddrinfo("", "", NULL, NULL);],
  23. [gl_cv_func_getaddrinfo=yes],
  24. [gl_cv_func_getaddrinfo=no])])
  25. if test $gl_cv_func_getaddrinfo = no; then
  26. AC_CACHE_CHECK(for getaddrinfo in ws2tcpip.h and -lws2_32,
  27. gl_cv_w32_getaddrinfo, [
  28. gl_cv_w32_getaddrinfo=no
  29. am_save_LIBS="$LIBS"
  30. LIBS="$LIBS -lws2_32"
  31. AC_TRY_LINK([
  32. #ifdef HAVE_WS2TCPIP_H
  33. #include <ws2tcpip.h>
  34. #endif
  35. #include <stddef.h>
  36. ], [getaddrinfo(NULL, NULL, NULL, NULL);], gl_cv_w32_getaddrinfo=yes)
  37. LIBS="$am_save_LIBS"])
  38. if test "$gl_cv_w32_getaddrinfo" = "yes"; then
  39. LIBS="$LIBS -lws2_32"
  40. else
  41. AC_LIBOBJ(getaddrinfo)
  42. fi
  43. fi
  44. # We can't use AC_REPLACE_FUNCS here because gai_strerror may be an
  45. # inline function declared in ws2tcpip.h, so we need to get that
  46. # header included somehow.
  47. AC_CACHE_CHECK([for gai_strerror (possibly via ws2tcpip.h)],
  48. gl_cv_func_gai_strerror, [
  49. AC_TRY_LINK([
  50. #include <sys/types.h>
  51. #ifdef HAVE_SYS_SOCKET_H
  52. #include <sys/socket.h>
  53. #endif
  54. #ifdef HAVE_NETDB_H
  55. #include <netdb.h>
  56. #endif
  57. #ifdef HAVE_WS2TCPIP_H
  58. #include <ws2tcpip.h>
  59. #endif
  60. #include <stddef.h>
  61. ], [gai_strerror (NULL);],
  62. [gl_cv_func_gai_strerror=yes],
  63. [gl_cv_func_gai_strerror=no])])
  64. if test $gl_cv_func_gai_strerror = no; then
  65. AC_LIBOBJ(gai_strerror)
  66. fi
  67. gl_PREREQ_GETADDRINFO
  68. ])
  69. # Prerequisites of lib/getaddrinfo.h and lib/getaddrinfo.c.
  70. AC_DEFUN([gl_PREREQ_GETADDRINFO], [
  71. AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
  72. AC_SEARCH_LIBS(gethostbyname, [inet nsl])
  73. AC_SEARCH_LIBS(getservbyname, [inet nsl socket xnet])
  74. AC_CHECK_FUNCS(gethostbyname,, [
  75. AC_CACHE_CHECK(for gethostbyname in winsock2.h and -lws2_32,
  76. gl_cv_w32_gethostbyname, [
  77. gl_cv_w32_gethostbyname=no
  78. am_save_LIBS="$LIBS"
  79. LIBS="$LIBS -lws2_32"
  80. AC_TRY_LINK([
  81. #ifdef HAVE_WINSOCK2_H
  82. #include <winsock2.h>
  83. #endif
  84. #include <stddef.h>
  85. ], [gethostbyname(NULL);], gl_cv_w32_gethostbyname=yes)
  86. LIBS="$am_save_LIBS"])
  87. if test "$gl_cv_w32_gethostbyname" = "yes"; then
  88. LIBS="$LIBS -lws2_32"
  89. fi
  90. ])
  91. AC_REQUIRE([AC_C_RESTRICT])
  92. AC_REQUIRE([gl_SOCKET_FAMILIES])
  93. AC_REQUIRE([gl_HEADER_SYS_SOCKET])
  94. AC_REQUIRE([AC_C_INLINE])
  95. AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
  96. AC_CHECK_HEADERS_ONCE(netinet/in.h netdb.h)
  97. AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[
  98. /* sys/types.h is not needed according to POSIX, but the
  99. sys/socket.h in i386-unknown-freebsd4.10 and
  100. powerpc-apple-darwin5.5 required it. */
  101. #include <sys/types.h>
  102. #ifdef HAVE_SYS_SOCKET_H
  103. #include <sys/socket.h>
  104. #endif
  105. #ifdef HAVE_NETDB_H
  106. #include <netdb.h>
  107. #endif
  108. #ifdef HAVE_WS2TCPIP_H
  109. #include <ws2tcpip.h>
  110. #endif
  111. ])
  112. AC_CHECK_TYPES([struct addrinfo],,,[
  113. #include <sys/types.h>
  114. #ifdef HAVE_SYS_SOCKET_H
  115. #include <sys/socket.h>
  116. #endif
  117. #ifdef HAVE_NETDB_H
  118. #include <netdb.h>
  119. #endif
  120. #ifdef HAVE_WS2TCPIP_H
  121. #include <ws2tcpip.h>
  122. #endif
  123. ])
  124. ])