getaddrinfo.m4 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. # getaddrinfo.m4 serial 20
  2. dnl Copyright (C) 2004-2009 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_REQUIRE([gl_HEADER_NETDB])dnl for HAVE_NETDB_H
  10. AC_MSG_NOTICE([checking how to do getaddrinfo, freeaddrinfo and getnameinfo])
  11. GETADDRINFO_LIB=
  12. gai_saved_LIBS="$LIBS"
  13. dnl Where is getaddrinfo()?
  14. dnl - On Solaris, it is in libsocket.
  15. dnl - On Haiku, it is in libnetwork.
  16. dnl - On BeOS, it is in libnet.
  17. dnl - On native Windows, it is in ws2_32.dll.
  18. dnl - Otherwise it is in libc.
  19. AC_SEARCH_LIBS([getaddrinfo], [socket network net],
  20. [if test "$ac_cv_search_getaddrinfo" != "none required"; then
  21. GETADDRINFO_LIB="$ac_cv_search_getaddrinfo"
  22. fi])
  23. LIBS="$gai_saved_LIBS $GETADDRINFO_LIB"
  24. AC_CACHE_CHECK([for getaddrinfo], [gl_cv_func_getaddrinfo], [
  25. AC_TRY_LINK([
  26. #include <sys/types.h>
  27. #ifdef HAVE_SYS_SOCKET_H
  28. #include <sys/socket.h>
  29. #endif
  30. #ifdef HAVE_NETDB_H
  31. #include <netdb.h>
  32. #endif
  33. #include <stddef.h>
  34. ], [getaddrinfo("", "", NULL, NULL);],
  35. [gl_cv_func_getaddrinfo=yes],
  36. [gl_cv_func_getaddrinfo=no])])
  37. if test $gl_cv_func_getaddrinfo = no; then
  38. AC_CACHE_CHECK([for getaddrinfo in ws2tcpip.h and -lws2_32],
  39. gl_cv_w32_getaddrinfo, [
  40. gl_cv_w32_getaddrinfo=no
  41. am_save_LIBS="$LIBS"
  42. LIBS="$LIBS -lws2_32"
  43. AC_TRY_LINK([
  44. #ifdef HAVE_WS2TCPIP_H
  45. #include <ws2tcpip.h>
  46. #endif
  47. #include <stddef.h>
  48. ], [getaddrinfo(NULL, NULL, NULL, NULL);], gl_cv_w32_getaddrinfo=yes)
  49. LIBS="$am_save_LIBS"
  50. ])
  51. if test "$gl_cv_w32_getaddrinfo" = "yes"; then
  52. GETADDRINFO_LIB="-lws2_32"
  53. LIBS="$gai_saved_LIBS $GETADDRINFO_LIB"
  54. else
  55. AC_LIBOBJ([getaddrinfo])
  56. fi
  57. fi
  58. # We can't use AC_REPLACE_FUNCS here because gai_strerror may be an
  59. # inline function declared in ws2tcpip.h, so we need to get that
  60. # header included somehow.
  61. AC_CACHE_CHECK([for gai_strerror (possibly via ws2tcpip.h)],
  62. gl_cv_func_gai_strerror, [
  63. AC_TRY_LINK([
  64. #include <sys/types.h>
  65. #ifdef HAVE_SYS_SOCKET_H
  66. #include <sys/socket.h>
  67. #endif
  68. #ifdef HAVE_NETDB_H
  69. #include <netdb.h>
  70. #endif
  71. #ifdef HAVE_WS2TCPIP_H
  72. #include <ws2tcpip.h>
  73. #endif
  74. #include <stddef.h>
  75. ], [gai_strerror (NULL);],
  76. [gl_cv_func_gai_strerror=yes],
  77. [gl_cv_func_gai_strerror=no])])
  78. if test $gl_cv_func_gai_strerror = no; then
  79. AC_LIBOBJ([gai_strerror])
  80. fi
  81. LIBS="$gai_saved_LIBS"
  82. gl_PREREQ_GETADDRINFO
  83. AC_SUBST([GETADDRINFO_LIB])
  84. ])
  85. # Prerequisites of lib/netdb.in.h and lib/getaddrinfo.c.
  86. AC_DEFUN([gl_PREREQ_GETADDRINFO], [
  87. AC_REQUIRE([gl_NETDB_H_DEFAULTS])
  88. AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
  89. AC_REQUIRE([gl_HOSTENT]) dnl for HOSTENT_LIB
  90. AC_REQUIRE([gl_SERVENT]) dnl for SERVENT_LIB
  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. dnl Including sys/socket.h is wrong for Windows, but Windows does not
  97. dnl have sa_len so the result is correct anyway.
  98. AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , [#include <sys/socket.h>])
  99. AC_CHECK_HEADERS_ONCE([netinet/in.h])
  100. AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[
  101. /* sys/types.h is not needed according to POSIX, but the
  102. sys/socket.h in i386-unknown-freebsd4.10 and
  103. powerpc-apple-darwin5.5 required it. */
  104. #include <sys/types.h>
  105. #ifdef HAVE_SYS_SOCKET_H
  106. #include <sys/socket.h>
  107. #endif
  108. #ifdef HAVE_NETDB_H
  109. #include <netdb.h>
  110. #endif
  111. #ifdef HAVE_WS2TCPIP_H
  112. #include <ws2tcpip.h>
  113. #endif
  114. ])
  115. if test $ac_cv_have_decl_getaddrinfo = no; then
  116. HAVE_DECL_GETADDRINFO=0
  117. fi
  118. if test $ac_cv_have_decl_freeaddrinfo = no; then
  119. HAVE_DECL_FREEADDRINFO=0
  120. fi
  121. if test $ac_cv_have_decl_gai_strerror = no; then
  122. HAVE_DECL_GAI_STRERROR=0
  123. fi
  124. if test $ac_cv_have_decl_getnameinfo = no; then
  125. HAVE_DECL_GETNAMEINFO=0
  126. fi
  127. AC_CHECK_TYPES([struct addrinfo],,,[
  128. #include <sys/types.h>
  129. #ifdef HAVE_SYS_SOCKET_H
  130. #include <sys/socket.h>
  131. #endif
  132. #ifdef HAVE_NETDB_H
  133. #include <netdb.h>
  134. #endif
  135. #ifdef HAVE_WS2TCPIP_H
  136. #include <ws2tcpip.h>
  137. #endif
  138. ])
  139. if test $ac_cv_type_struct_addrinfo = no; then
  140. HAVE_STRUCT_ADDRINFO=0
  141. fi
  142. dnl Append $HOSTENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
  143. case " $GETADDRINFO_LIB " in
  144. *" $HOSTENT_LIB "*) ;;
  145. *) GETADDRINFO_LIB="$GETADDRINFO_LIB $HOSTENT_LIB" ;;
  146. esac
  147. dnl Append $SERVENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
  148. case " $GETADDRINFO_LIB " in
  149. *" $SERVENT_LIB "*) ;;
  150. *) GETADDRINFO_LIB="$GETADDRINFO_LIB $SERVENT_LIB" ;;
  151. esac
  152. ])