getaddrinfo.m4 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. # getaddrinfo.m4 serial 31
  2. dnl Copyright (C) 2004-2017 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_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. HAVE_GETADDRINFO=1
  25. AC_CACHE_CHECK([for getaddrinfo], [gl_cv_func_getaddrinfo], [
  26. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  27. #include <sys/types.h>
  28. #ifdef HAVE_SYS_SOCKET_H
  29. #include <sys/socket.h>
  30. #endif
  31. #ifdef HAVE_NETDB_H
  32. #include <netdb.h>
  33. #endif
  34. #include <stddef.h>
  35. ]], [[getaddrinfo("", "", NULL, NULL);]])],
  36. [gl_cv_func_getaddrinfo=yes],
  37. [gl_cv_func_getaddrinfo=no])])
  38. if test $gl_cv_func_getaddrinfo = no; then
  39. AC_CACHE_CHECK([for getaddrinfo in ws2tcpip.h and -lws2_32],
  40. gl_cv_w32_getaddrinfo, [
  41. gl_cv_w32_getaddrinfo=no
  42. am_save_LIBS="$LIBS"
  43. LIBS="$LIBS -lws2_32"
  44. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  45. #ifdef HAVE_WS2TCPIP_H
  46. #include <ws2tcpip.h>
  47. #endif
  48. #include <stddef.h>
  49. ]], [[getaddrinfo(NULL, NULL, NULL, NULL);]])], [gl_cv_w32_getaddrinfo=yes])
  50. LIBS="$am_save_LIBS"
  51. ])
  52. if test "$gl_cv_w32_getaddrinfo" = "yes"; then
  53. GETADDRINFO_LIB="-lws2_32"
  54. LIBS="$gai_saved_LIBS $GETADDRINFO_LIB"
  55. else
  56. HAVE_GETADDRINFO=0
  57. fi
  58. fi
  59. # We can't use AC_REPLACE_FUNCS here because gai_strerror may be an
  60. # inline function declared in ws2tcpip.h, so we need to get that
  61. # header included somehow.
  62. AC_CHECK_DECLS([gai_strerror], [], [], [[
  63. #include <sys/types.h>
  64. #ifdef HAVE_SYS_SOCKET_H
  65. #include <sys/socket.h>
  66. #endif
  67. #ifdef HAVE_NETDB_H
  68. #include <netdb.h>
  69. #endif
  70. #ifdef HAVE_WS2TCPIP_H
  71. #include <ws2tcpip.h>
  72. #endif
  73. #include <stddef.h>
  74. ]])
  75. if test $ac_cv_have_decl_gai_strerror = yes; then
  76. AC_CHECK_DECLS([gai_strerrorA], [], [], [[
  77. #include <sys/types.h>
  78. #ifdef HAVE_SYS_SOCKET_H
  79. #include <sys/socket.h>
  80. #endif
  81. #ifdef HAVE_NETDB_H
  82. #include <netdb.h>
  83. #endif
  84. #ifdef HAVE_WS2TCPIP_H
  85. #include <ws2tcpip.h>
  86. #endif
  87. #include <stddef.h>
  88. ]])
  89. dnl check for correct signature
  90. AC_CACHE_CHECK([for gai_strerror with POSIX signature],
  91. [gl_cv_func_gai_strerror_posix_signature], [
  92. AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
  93. #include <sys/types.h>
  94. #ifdef HAVE_SYS_SOCKET_H
  95. #include <sys/socket.h>
  96. #endif
  97. #ifdef HAVE_NETDB_H
  98. #include <netdb.h>
  99. #endif
  100. #ifdef HAVE_WS2TCPIP_H
  101. #include <ws2tcpip.h>
  102. #endif
  103. #include <stddef.h>
  104. extern
  105. #ifdef __cplusplus
  106. "C"
  107. #endif
  108. const char *gai_strerror(int);]])],
  109. [gl_cv_func_gai_strerror_posix_signature=yes],
  110. [gl_cv_func_gai_strerror_posix_signature=no])])
  111. if test $gl_cv_func_gai_strerror_posix_signature = no; then
  112. REPLACE_GAI_STRERROR=1
  113. fi
  114. fi
  115. LIBS="$gai_saved_LIBS"
  116. gl_PREREQ_GETADDRINFO
  117. AC_SUBST([GETADDRINFO_LIB])
  118. ])
  119. # Prerequisites of lib/netdb.in.h and lib/getaddrinfo.c.
  120. AC_DEFUN([gl_PREREQ_GETADDRINFO], [
  121. AC_REQUIRE([gl_NETDB_H_DEFAULTS])
  122. AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
  123. AC_REQUIRE([gl_HOSTENT]) dnl for HOSTENT_LIB
  124. AC_REQUIRE([gl_SERVENT]) dnl for SERVENT_LIB
  125. AC_REQUIRE([gl_FUNC_INET_NTOP]) dnl for INET_NTOP_LIB
  126. AC_REQUIRE([AC_C_RESTRICT])
  127. AC_REQUIRE([gl_SOCKET_FAMILIES])
  128. AC_REQUIRE([gl_HEADER_SYS_SOCKET])
  129. AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
  130. dnl Including sys/socket.h is wrong for Windows, but Windows does not
  131. dnl have sa_len so the result is correct anyway.
  132. AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , [
  133. #include <sys/types.h>
  134. #include <sys/socket.h>
  135. ])
  136. AC_CHECK_HEADERS_ONCE([netinet/in.h])
  137. AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, getnameinfo],,,[[
  138. /* sys/types.h is not needed according to POSIX, but the
  139. sys/socket.h in i386-unknown-freebsd4.10 and
  140. powerpc-apple-darwin5.5 required it. */
  141. #include <sys/types.h>
  142. #ifdef HAVE_SYS_SOCKET_H
  143. #include <sys/socket.h>
  144. #endif
  145. #ifdef HAVE_NETDB_H
  146. #include <netdb.h>
  147. #endif
  148. #ifdef HAVE_WS2TCPIP_H
  149. #include <ws2tcpip.h>
  150. #endif
  151. ]])
  152. if test $ac_cv_have_decl_getaddrinfo = no; then
  153. HAVE_DECL_GETADDRINFO=0
  154. fi
  155. if test $ac_cv_have_decl_freeaddrinfo = no; then
  156. HAVE_DECL_FREEADDRINFO=0
  157. fi
  158. if test $ac_cv_have_decl_gai_strerror = no; then
  159. HAVE_DECL_GAI_STRERROR=0
  160. fi
  161. if test $ac_cv_have_decl_getnameinfo = no; then
  162. HAVE_DECL_GETNAMEINFO=0
  163. fi
  164. AC_CHECK_TYPES([struct addrinfo],,,[
  165. #include <sys/types.h>
  166. #ifdef HAVE_SYS_SOCKET_H
  167. #include <sys/socket.h>
  168. #endif
  169. #ifdef HAVE_NETDB_H
  170. #include <netdb.h>
  171. #endif
  172. #ifdef HAVE_WS2TCPIP_H
  173. #include <ws2tcpip.h>
  174. #endif
  175. ])
  176. if test $ac_cv_type_struct_addrinfo = no; then
  177. HAVE_STRUCT_ADDRINFO=0
  178. fi
  179. dnl Append $HOSTENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
  180. case " $GETADDRINFO_LIB " in
  181. *" $HOSTENT_LIB "*) ;;
  182. *) GETADDRINFO_LIB="$GETADDRINFO_LIB $HOSTENT_LIB" ;;
  183. esac
  184. dnl Append $SERVENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
  185. case " $GETADDRINFO_LIB " in
  186. *" $SERVENT_LIB "*) ;;
  187. *) GETADDRINFO_LIB="$GETADDRINFO_LIB $SERVENT_LIB" ;;
  188. esac
  189. dnl Append $INET_NTOP_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
  190. case " $GETADDRINFO_LIB " in
  191. *" $INET_NTOP_LIB "*) ;;
  192. *) GETADDRINFO_LIB="$GETADDRINFO_LIB $INET_NTOP_LIB" ;;
  193. esac
  194. ])