1 dnl RACOON_PATH_LIBS(FUNCTION, LIB, SEARCH-PATHS [, ACTION-IF-FOUND
2 dnl [, ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
3 dnl Search for a library defining FUNC, if it's not already available.
5 AC_DEFUN([RACOON_PATH_LIBS],
7 AC_CACHE_CHECK([for $2 containing $1], [ac_cv_search_$1],
8 [ac_func_search_save_LIBS="$LIBS"
10 AC_TRY_LINK_FUNC([$1], [ac_cv_search_$1="none required"],
12 AC_TRY_LINK_FUNC([$1], [ac_cv_search_$1="-l$2"], [])])
13 LIBS="$ac_func_search_save_LIBS"
14 ifelse("x$3", "x", , [ test "$ac_cv_search_$1" = "no" && for i in $3; do
15 LIBS="-L$i -l$2 $ac_func_search_save_LIBS"
16 AC_TRY_LINK_FUNC([$1],
17 [ac_cv_search_$1="-L$i -l$2"
20 LIBS="$ac_func_search_save_LIBS" ]) ])
21 if test "$ac_cv_search_$1" != "no"; then
22 test "$ac_cv_search_$1" = "none required" || LIBS="$ac_cv_search_$1 $LIBS"
28 dnl Check if either va_copy() or __va_copy() is available. On linux systems
29 dnl at least one of these should be present.
30 AC_DEFUN([RACOON_CHECK_VA_COPY], [
33 AC_CACHE_CHECK([for an implementation of va_copy()],
35 AC_TRY_RUN([#include <stdarg.h>
36 void func (int i, ...) {
39 va_copy (args2, args1);
40 if (va_arg (args1, int) != 1 || va_arg (args2, int) != 1)
51 AC_MSG_WARN(Cross compiling... Unable to test va_copy)
54 if test x$ac_cv_va_copy != xyes; then
55 AC_CACHE_CHECK([for an implementation of __va_copy()],
57 AC_TRY_RUN([#include <stdarg.h>
58 void func (int i, ...) {
61 __va_copy (args2, args1);
62 if (va_arg (args1, int) != 1 || va_arg (args2, int) != 1)
71 [ac_cv___va_copy=yes],
73 AC_MSG_WARN(Cross compiling... Unable to test __va_copy)
78 if test "x$ac_cv_va_copy" = "xyes"; then
80 elif test "x$ac_cv___va_copy" = "xyes"; then
81 va_copy_func=__va_copy
84 if test -n "$va_copy_func"; then
85 AC_DEFINE_UNQUOTED(VA_COPY,$va_copy_func,
86 [A 'va_copy' style function])
88 AC_MSG_WARN([Hmm, neither va_copy() nor __va_copy() found.])
89 AC_MSG_WARN([Using a generic fallback.])
95 AC_DEFUN([RACOON_CHECK_BUGGY_GETADDRINFO], [
96 AC_MSG_CHECKING(getaddrinfo bug)
100 #include <sys/types.h>
101 #include <sys/socket.h>
105 #include <netinet/in.h>
109 int passive, gaierr, inet4 = 0, inet6 = 0;
110 struct addrinfo hints, *ai, *aitop;
111 char straddr[INET6_ADDRSTRLEN], strport[16];
113 for (passive = 0; passive <= 1; passive++) {
114 memset(&hints, 0, sizeof(hints));
115 hints.ai_family = AF_UNSPEC;
116 hints.ai_flags = passive ? AI_PASSIVE : 0;
117 hints.ai_protocol = IPPROTO_TCP;
118 hints.ai_socktype = SOCK_STREAM;
119 if ((gaierr = getaddrinfo(NULL, "54321", &hints, &aitop)) != 0) {
120 (void)gai_strerror(gaierr);
123 for (ai = aitop; ai; ai = ai->ai_next) {
124 if (ai->ai_addr == NULL ||
125 ai->ai_addrlen == 0 ||
126 getnameinfo(ai->ai_addr, ai->ai_addrlen,
127 straddr, sizeof(straddr), strport, sizeof(strport),
128 NI_NUMERICHOST|NI_NUMERICSERV) != 0) {
131 switch (ai->ai_family) {
133 if (strcmp(strport, "54321") != 0) {
137 if (strcmp(straddr, "0.0.0.0") != 0) {
141 if (strcmp(straddr, "127.0.0.1") != 0) {
148 if (strcmp(strport, "54321") != 0) {
152 if (strcmp(straddr, "::") != 0) {
156 if (strcmp(straddr, "::1") != 0) {
166 /* another family support? */
172 if (!(inet4 == 0 || inet4 == 2))
174 if (!(inet6 == 0 || inet6 == 2))
190 buggygetaddrinfo=yes,
191 AC_MSG_RESULT(Cross compiling ... Assuming getaddrinfo is not buggy.)