getaddrinfo.m4 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. # getaddrinfo.m4 serial 34
  2. dnl Copyright (C) 2004-2023 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_SYS_SOCKET_H])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
  9. AC_REQUIRE([gl_NETDB_H])dnl for HAVE_NETDB_H
  10. GETADDRINFO_LIB=
  11. gai_saved_LIBS="$LIBS"
  12. dnl Where is getaddrinfo()?
  13. dnl - On Solaris, it is in libsocket.
  14. dnl - On Haiku, it is in libnetwork.
  15. dnl - On BeOS, it is in libnet.
  16. dnl - On native Windows, it is in ws2_32.dll.
  17. dnl - Otherwise it is in libc.
  18. AC_SEARCH_LIBS([getaddrinfo], [socket network net],
  19. [if test "$ac_cv_search_getaddrinfo" != "none required"; then
  20. GETADDRINFO_LIB="$ac_cv_search_getaddrinfo"
  21. fi])
  22. LIBS="$gai_saved_LIBS $GETADDRINFO_LIB"
  23. HAVE_GETADDRINFO=1
  24. AC_CACHE_CHECK([for getaddrinfo], [gl_cv_func_getaddrinfo], [
  25. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  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_LINK_IFELSE([AC_LANG_PROGRAM([[
  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. dnl Check for correct signature, in particular for a cdecl-compatible
  55. dnl calling convention.
  56. AC_CACHE_CHECK([for getaddrinfo with POSIX signature],
  57. [gl_cv_func_getaddrinfo_posix_signature],
  58. [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
  59. #include <sys/types.h>
  60. #ifdef HAVE_SYS_SOCKET_H
  61. #include <sys/socket.h>
  62. #endif
  63. #ifdef HAVE_NETDB_H
  64. #include <netdb.h>
  65. #endif
  66. #ifdef HAVE_WS2TCPIP_H
  67. #include <ws2tcpip.h>
  68. #endif
  69. #include <stddef.h>
  70. extern
  71. #ifdef __cplusplus
  72. "C"
  73. #endif
  74. int getaddrinfo (const char *, const char *, const struct addrinfo *, struct addrinfo **);
  75. ]])],
  76. [gl_cv_func_getaddrinfo_posix_signature=yes],
  77. [gl_cv_func_getaddrinfo_posix_signature=no])
  78. ])
  79. if test $gl_cv_func_getaddrinfo_posix_signature = no; then
  80. REPLACE_GETADDRINFO=1
  81. fi
  82. else
  83. HAVE_GETADDRINFO=0
  84. fi
  85. fi
  86. AC_DEFINE_UNQUOTED([HAVE_GETADDRINFO], [$HAVE_GETADDRINFO],
  87. [Define to 1 if getaddrinfo exists, or to 0 otherwise.])
  88. # We can't use AC_REPLACE_FUNCS here because gai_strerror may be an
  89. # inline function declared in ws2tcpip.h, so we need to get that
  90. # header included somehow.
  91. AC_CHECK_DECLS([gai_strerror], [], [], [[
  92. #include <sys/types.h>
  93. #ifdef HAVE_SYS_SOCKET_H
  94. #include <sys/socket.h>
  95. #endif
  96. #ifdef HAVE_NETDB_H
  97. #include <netdb.h>
  98. #endif
  99. #ifdef HAVE_WS2TCPIP_H
  100. #include <ws2tcpip.h>
  101. #endif
  102. #include <stddef.h>
  103. ]])
  104. if test $ac_cv_have_decl_gai_strerror = yes; then
  105. AC_CHECK_DECLS([gai_strerrorA], [], [], [[
  106. #include <sys/types.h>
  107. #ifdef HAVE_SYS_SOCKET_H
  108. #include <sys/socket.h>
  109. #endif
  110. #ifdef HAVE_NETDB_H
  111. #include <netdb.h>
  112. #endif
  113. #ifdef HAVE_WS2TCPIP_H
  114. #include <ws2tcpip.h>
  115. #endif
  116. #include <stddef.h>
  117. ]])
  118. dnl check for correct signature
  119. AC_CACHE_CHECK([for gai_strerror with POSIX signature],
  120. [gl_cv_func_gai_strerror_posix_signature], [
  121. AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
  122. #include <sys/types.h>
  123. #ifdef HAVE_SYS_SOCKET_H
  124. #include <sys/socket.h>
  125. #endif
  126. #ifdef HAVE_NETDB_H
  127. #include <netdb.h>
  128. #endif
  129. #ifdef HAVE_WS2TCPIP_H
  130. #include <ws2tcpip.h>
  131. #endif
  132. #include <stddef.h>
  133. extern
  134. #ifdef __cplusplus
  135. "C"
  136. #endif
  137. const char *gai_strerror(int);]])],
  138. [gl_cv_func_gai_strerror_posix_signature=yes],
  139. [gl_cv_func_gai_strerror_posix_signature=no])])
  140. if test $gl_cv_func_gai_strerror_posix_signature = no; then
  141. REPLACE_GAI_STRERROR=1
  142. fi
  143. fi
  144. LIBS="$gai_saved_LIBS"
  145. gl_PREREQ_GETADDRINFO
  146. AC_SUBST([GETADDRINFO_LIB])
  147. ])
  148. # Prerequisites of lib/netdb.in.h and lib/getaddrinfo.c.
  149. AC_DEFUN([gl_PREREQ_GETADDRINFO], [
  150. AC_REQUIRE([gl_NETDB_H_DEFAULTS])
  151. AC_REQUIRE([gl_SYS_SOCKET_H])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
  152. AC_REQUIRE([gl_HOSTENT]) dnl for HOSTENT_LIB
  153. AC_REQUIRE([gl_SERVENT]) dnl for SERVENT_LIB
  154. AC_REQUIRE([gl_FUNC_INET_NTOP]) dnl for INET_NTOP_LIB
  155. AC_REQUIRE([AC_C_RESTRICT])
  156. AC_REQUIRE([gl_SOCKET_FAMILIES])
  157. AC_REQUIRE([gl_SYS_SOCKET_H])
  158. AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
  159. dnl Including sys/socket.h is wrong for Windows, but Windows does not
  160. dnl have sa_len so the result is correct anyway.
  161. AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , [
  162. #include <sys/types.h>
  163. #include <sys/socket.h>
  164. ])
  165. AC_CHECK_HEADERS_ONCE([netinet/in.h])
  166. AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, getnameinfo],,,[[
  167. /* sys/types.h is not needed according to POSIX, but the
  168. sys/socket.h in i386-unknown-freebsd4.10 and
  169. powerpc-apple-darwin5.5 required it. */
  170. #include <sys/types.h>
  171. #ifdef HAVE_SYS_SOCKET_H
  172. #include <sys/socket.h>
  173. #endif
  174. #ifdef HAVE_NETDB_H
  175. #include <netdb.h>
  176. #endif
  177. #ifdef HAVE_WS2TCPIP_H
  178. #include <ws2tcpip.h>
  179. #endif
  180. ]])
  181. if test $ac_cv_have_decl_getaddrinfo = no; then
  182. HAVE_DECL_GETADDRINFO=0
  183. fi
  184. if test $ac_cv_have_decl_freeaddrinfo = no; then
  185. HAVE_DECL_FREEADDRINFO=0
  186. fi
  187. if test $ac_cv_have_decl_gai_strerror = no; then
  188. HAVE_DECL_GAI_STRERROR=0
  189. fi
  190. if test $ac_cv_have_decl_getnameinfo = no; then
  191. HAVE_DECL_GETNAMEINFO=0
  192. fi
  193. AC_CHECK_TYPES([struct addrinfo],,,[
  194. #include <sys/types.h>
  195. #ifdef HAVE_SYS_SOCKET_H
  196. #include <sys/socket.h>
  197. #endif
  198. #ifdef HAVE_NETDB_H
  199. #include <netdb.h>
  200. #endif
  201. #ifdef HAVE_WS2TCPIP_H
  202. #include <ws2tcpip.h>
  203. #endif
  204. ])
  205. if test $ac_cv_type_struct_addrinfo = no; then
  206. HAVE_STRUCT_ADDRINFO=0
  207. fi
  208. dnl Append $HOSTENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
  209. case " $GETADDRINFO_LIB " in
  210. *" $HOSTENT_LIB "*) ;;
  211. *) GETADDRINFO_LIB="$GETADDRINFO_LIB $HOSTENT_LIB" ;;
  212. esac
  213. dnl Append $SERVENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
  214. case " $GETADDRINFO_LIB " in
  215. *" $SERVENT_LIB "*) ;;
  216. *) GETADDRINFO_LIB="$GETADDRINFO_LIB $SERVENT_LIB" ;;
  217. esac
  218. dnl Append $INET_NTOP_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
  219. case " $GETADDRINFO_LIB " in
  220. *" $INET_NTOP_LIB "*) ;;
  221. *) GETADDRINFO_LIB="$GETADDRINFO_LIB $INET_NTOP_LIB" ;;
  222. esac
  223. ])