| 1 |
# getaddrinfo.m4 |
| 2 |
# serial 35 |
| 3 |
dnl Copyright (C) 2004-2024 Free Software Foundation, Inc. |
| 4 |
dnl This file is free software; the Free Software Foundation |
| 5 |
dnl gives unlimited permission to copy and/or distribute it, |
| 6 |
dnl with or without modifications, as long as this notice is preserved. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
AC_DEFUN([gl_GETADDRINFO], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_SYS_SOCKET_H])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H |
| 12 |
AC_REQUIRE([gl_NETDB_H])dnl for HAVE_NETDB_H |
| 13 |
GETADDRINFO_LIB= |
| 14 |
gai_saved_LIBS="$LIBS" |
| 15 |
|
| 16 |
dnl Where is getaddrinfo()? |
| 17 |
dnl - On Solaris, it is in libsocket. |
| 18 |
dnl - On Haiku, it is in libnetwork. |
| 19 |
dnl - On BeOS, it is in libnet. |
| 20 |
dnl - On native Windows, it is in ws2_32.dll. |
| 21 |
dnl - Otherwise it is in libc. |
| 22 |
AC_SEARCH_LIBS([getaddrinfo], [socket network net], |
| 23 |
[if test "$ac_cv_search_getaddrinfo" != "none required"; then |
| 24 |
GETADDRINFO_LIB="$ac_cv_search_getaddrinfo" |
| 25 |
fi]) |
| 26 |
LIBS="$gai_saved_LIBS $GETADDRINFO_LIB" |
| 27 |
|
| 28 |
HAVE_GETADDRINFO=1 |
| 29 |
AC_CACHE_CHECK([for getaddrinfo], [gl_cv_func_getaddrinfo], [ |
| 30 |
AC_LINK_IFELSE([AC_LANG_PROGRAM([[ |
| 31 |
#include <sys/types.h> |
| 32 |
#ifdef HAVE_SYS_SOCKET_H |
| 33 |
#include <sys/socket.h> |
| 34 |
#endif |
| 35 |
#ifdef HAVE_NETDB_H |
| 36 |
#include <netdb.h> |
| 37 |
#endif |
| 38 |
#include <stddef.h> |
| 39 |
]], [[getaddrinfo("", "", NULL, NULL);]])], |
| 40 |
[gl_cv_func_getaddrinfo=yes], |
| 41 |
[gl_cv_func_getaddrinfo=no])]) |
| 42 |
if test $gl_cv_func_getaddrinfo = no; then |
| 43 |
AC_CACHE_CHECK([for getaddrinfo in ws2tcpip.h and -lws2_32], |
| 44 |
gl_cv_w32_getaddrinfo, [ |
| 45 |
gl_cv_w32_getaddrinfo=no |
| 46 |
gl_saved_LIBS="$LIBS" |
| 47 |
LIBS="$LIBS -lws2_32" |
| 48 |
AC_LINK_IFELSE([AC_LANG_PROGRAM([[ |
| 49 |
#ifdef HAVE_WS2TCPIP_H |
| 50 |
#include <ws2tcpip.h> |
| 51 |
#endif |
| 52 |
#include <stddef.h> |
| 53 |
]], [[getaddrinfo(NULL, NULL, NULL, NULL);]])], [gl_cv_w32_getaddrinfo=yes]) |
| 54 |
LIBS="$gl_saved_LIBS" |
| 55 |
]) |
| 56 |
if test "$gl_cv_w32_getaddrinfo" = "yes"; then |
| 57 |
GETADDRINFO_LIB="-lws2_32" |
| 58 |
LIBS="$gai_saved_LIBS $GETADDRINFO_LIB" |
| 59 |
dnl Check for correct signature, in particular for a cdecl-compatible |
| 60 |
dnl calling convention. |
| 61 |
AC_CACHE_CHECK([for getaddrinfo with POSIX signature], |
| 62 |
[gl_cv_func_getaddrinfo_posix_signature], |
| 63 |
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ |
| 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 |
extern |
| 76 |
#ifdef __cplusplus |
| 77 |
"C" |
| 78 |
#endif |
| 79 |
int getaddrinfo (const char *, const char *, const struct addrinfo *, struct addrinfo **); |
| 80 |
]])], |
| 81 |
[gl_cv_func_getaddrinfo_posix_signature=yes], |
| 82 |
[gl_cv_func_getaddrinfo_posix_signature=no]) |
| 83 |
]) |
| 84 |
if test $gl_cv_func_getaddrinfo_posix_signature = no; then |
| 85 |
REPLACE_GETADDRINFO=1 |
| 86 |
fi |
| 87 |
else |
| 88 |
HAVE_GETADDRINFO=0 |
| 89 |
fi |
| 90 |
fi |
| 91 |
AC_DEFINE_UNQUOTED([HAVE_GETADDRINFO], [$HAVE_GETADDRINFO], |
| 92 |
[Define to 1 if getaddrinfo exists, or to 0 otherwise.]) |
| 93 |
|
| 94 |
# We can't use AC_REPLACE_FUNCS here because gai_strerror may be an |
| 95 |
# inline function declared in ws2tcpip.h, so we need to get that |
| 96 |
# header included somehow. |
| 97 |
AC_CHECK_DECLS([gai_strerror], [], [], [[ |
| 98 |
#include <sys/types.h> |
| 99 |
#ifdef HAVE_SYS_SOCKET_H |
| 100 |
#include <sys/socket.h> |
| 101 |
#endif |
| 102 |
#ifdef HAVE_NETDB_H |
| 103 |
#include <netdb.h> |
| 104 |
#endif |
| 105 |
#ifdef HAVE_WS2TCPIP_H |
| 106 |
#include <ws2tcpip.h> |
| 107 |
#endif |
| 108 |
#include <stddef.h> |
| 109 |
]]) |
| 110 |
if test $ac_cv_have_decl_gai_strerror = yes; then |
| 111 |
AC_CHECK_DECLS([gai_strerrorA], [], [], [[ |
| 112 |
#include <sys/types.h> |
| 113 |
#ifdef HAVE_SYS_SOCKET_H |
| 114 |
#include <sys/socket.h> |
| 115 |
#endif |
| 116 |
#ifdef HAVE_NETDB_H |
| 117 |
#include <netdb.h> |
| 118 |
#endif |
| 119 |
#ifdef HAVE_WS2TCPIP_H |
| 120 |
#include <ws2tcpip.h> |
| 121 |
#endif |
| 122 |
#include <stddef.h> |
| 123 |
]]) |
| 124 |
dnl check for correct signature |
| 125 |
AC_CACHE_CHECK([for gai_strerror with POSIX signature], |
| 126 |
[gl_cv_func_gai_strerror_posix_signature], [ |
| 127 |
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ |
| 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 |
#include <stddef.h> |
| 139 |
extern |
| 140 |
#ifdef __cplusplus |
| 141 |
"C" |
| 142 |
#endif |
| 143 |
const char *gai_strerror(int);]])], |
| 144 |
[gl_cv_func_gai_strerror_posix_signature=yes], |
| 145 |
[gl_cv_func_gai_strerror_posix_signature=no])]) |
| 146 |
if test $gl_cv_func_gai_strerror_posix_signature = no; then |
| 147 |
REPLACE_GAI_STRERROR=1 |
| 148 |
fi |
| 149 |
fi |
| 150 |
|
| 151 |
LIBS="$gai_saved_LIBS" |
| 152 |
|
| 153 |
gl_PREREQ_GETADDRINFO |
| 154 |
|
| 155 |
AC_SUBST([GETADDRINFO_LIB]) |
| 156 |
]) |
| 157 |
|
| 158 |
# Prerequisites of lib/netdb.in.h and lib/getaddrinfo.c. |
| 159 |
AC_DEFUN([gl_PREREQ_GETADDRINFO], [ |
| 160 |
AC_REQUIRE([gl_NETDB_H_DEFAULTS]) |
| 161 |
AC_REQUIRE([gl_SYS_SOCKET_H])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H |
| 162 |
AC_REQUIRE([gl_HOSTENT]) dnl for HOSTENT_LIB |
| 163 |
AC_REQUIRE([gl_SERVENT]) dnl for SERVENT_LIB |
| 164 |
AC_REQUIRE([gl_FUNC_INET_NTOP]) dnl for INET_NTOP_LIB |
| 165 |
AC_REQUIRE([AC_C_RESTRICT]) |
| 166 |
AC_REQUIRE([gl_SOCKET_FAMILIES]) |
| 167 |
AC_REQUIRE([gl_SYS_SOCKET_H]) |
| 168 |
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) |
| 169 |
|
| 170 |
dnl Including sys/socket.h is wrong for Windows, but Windows does not |
| 171 |
dnl have sa_len so the result is correct anyway. |
| 172 |
AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , [ |
| 173 |
#include <sys/types.h> |
| 174 |
#include <sys/socket.h> |
| 175 |
]) |
| 176 |
|
| 177 |
AC_CHECK_HEADERS_ONCE([netinet/in.h]) |
| 178 |
|
| 179 |
AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, getnameinfo],,,[[ |
| 180 |
/* sys/types.h is not needed according to POSIX, but the |
| 181 |
sys/socket.h in i386-unknown-freebsd4.10 and |
| 182 |
powerpc-apple-darwin5.5 required it. */ |
| 183 |
#include <sys/types.h> |
| 184 |
#ifdef HAVE_SYS_SOCKET_H |
| 185 |
#include <sys/socket.h> |
| 186 |
#endif |
| 187 |
#ifdef HAVE_NETDB_H |
| 188 |
#include <netdb.h> |
| 189 |
#endif |
| 190 |
#ifdef HAVE_WS2TCPIP_H |
| 191 |
#include <ws2tcpip.h> |
| 192 |
#endif |
| 193 |
]]) |
| 194 |
if test $ac_cv_have_decl_getaddrinfo = no; then |
| 195 |
HAVE_DECL_GETADDRINFO=0 |
| 196 |
fi |
| 197 |
if test $ac_cv_have_decl_freeaddrinfo = no; then |
| 198 |
HAVE_DECL_FREEADDRINFO=0 |
| 199 |
fi |
| 200 |
if test $ac_cv_have_decl_gai_strerror = no; then |
| 201 |
HAVE_DECL_GAI_STRERROR=0 |
| 202 |
fi |
| 203 |
if test $ac_cv_have_decl_getnameinfo = no; then |
| 204 |
HAVE_DECL_GETNAMEINFO=0 |
| 205 |
fi |
| 206 |
|
| 207 |
AC_CHECK_TYPES([struct addrinfo],,,[ |
| 208 |
#include <sys/types.h> |
| 209 |
#ifdef HAVE_SYS_SOCKET_H |
| 210 |
#include <sys/socket.h> |
| 211 |
#endif |
| 212 |
#ifdef HAVE_NETDB_H |
| 213 |
#include <netdb.h> |
| 214 |
#endif |
| 215 |
#ifdef HAVE_WS2TCPIP_H |
| 216 |
#include <ws2tcpip.h> |
| 217 |
#endif |
| 218 |
]) |
| 219 |
if test $ac_cv_type_struct_addrinfo = no; then |
| 220 |
HAVE_STRUCT_ADDRINFO=0 |
| 221 |
fi |
| 222 |
|
| 223 |
dnl Append $HOSTENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates. |
| 224 |
case " $GETADDRINFO_LIB " in |
| 225 |
*" $HOSTENT_LIB "*) ;; |
| 226 |
*) GETADDRINFO_LIB="$GETADDRINFO_LIB $HOSTENT_LIB" ;; |
| 227 |
esac |
| 228 |
|
| 229 |
dnl Append $SERVENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates. |
| 230 |
case " $GETADDRINFO_LIB " in |
| 231 |
*" $SERVENT_LIB "*) ;; |
| 232 |
*) GETADDRINFO_LIB="$GETADDRINFO_LIB $SERVENT_LIB" ;; |
| 233 |
esac |
| 234 |
|
| 235 |
dnl Append $INET_NTOP_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates. |
| 236 |
case " $GETADDRINFO_LIB " in |
| 237 |
*" $INET_NTOP_LIB "*) ;; |
| 238 |
*) GETADDRINFO_LIB="$GETADDRINFO_LIB $INET_NTOP_LIB" ;; |
| 239 |
esac |
| 240 |
]) |