and added files
[bcm963xx.git] / userapps / opensource / ipsec-tools / acracoon.m4
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.
4
5 AC_DEFUN([RACOON_PATH_LIBS],
6 [AC_PREREQ([2.13])
7 AC_CACHE_CHECK([for $2 containing $1], [ac_cv_search_$1],
8 [ac_func_search_save_LIBS="$LIBS"
9 ac_cv_search_$1="no"
10 AC_TRY_LINK_FUNC([$1], [ac_cv_search_$1="none required"],
11         [LIBS="-l$2 $LIBS"
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"
18   break])
19   done 
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"
23   $4
24 else :
25   $5
26 fi])
27
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], [
31         saved_CFLAGS=$CFLAGS
32         CFLAGS="-Wall -O2"
33         AC_CACHE_CHECK([for an implementation of va_copy()],
34                 ac_cv_va_copy,[
35                 AC_TRY_RUN([#include <stdarg.h>
36                 void func (int i, ...) {
37                         va_list args1, args2;
38                         va_start (args1, i);
39                         va_copy (args2, args1);
40                         if (va_arg (args1, int) != 1 || va_arg (args2, int) != 1)
41                                 exit (1);
42                         va_end (args1);
43                         va_end (args2);
44                 }
45                 int main() {
46                         func (0, 1);
47                         return 0;
48                 }],
49                 [ac_cv_va_copy=yes],
50                 [ac_cv_va_copy=no],
51                 [])
52         ])
53         if test x$ac_cv_va_copy != xyes; then
54                 AC_CACHE_CHECK([for an implementation of __va_copy()],
55                         ac_cv___va_copy,[
56                         AC_TRY_RUN([#include <stdarg.h>
57                         void func (int i, ...) {
58                                 va_list args1, args2;
59                                 va_start (args1, i);
60                                 __va_copy (args2, args1);
61                                 if (va_arg (args1, int) != 1 || va_arg (args2, int) != 1)
62                                         exit (1);
63                                 va_end (args1);
64                                 va_end (args2);
65                         }
66                         int main() {
67                                 func (0, 1);
68                                 return 0;
69                         }],
70                         [ac_cv___va_copy=yes],
71                         [ac_cv___va_copy=no],
72                         [])
73                 ])
74         fi
75
76         if test "x$ac_cv_va_copy" = "xyes"; then
77                 va_copy_func=va_copy
78         elif test "x$ac_cv___va_copy" = "xyes"; then
79                 va_copy_func=__va_copy
80         fi
81
82         if test -n "$va_copy_func"; then
83                 AC_DEFINE_UNQUOTED(VA_COPY,$va_copy_func,
84                         [A 'va_copy' style function])
85         else
86                 AC_MSG_WARN([Hmm, neither va_copy() nor __va_copy() found.])
87                 AC_MSG_WARN([Using a generic fallback.])
88         fi
89         CFLAGS=$saved_CFLAGS
90         unset saved_CFLAGS
91 ])
92
93 AC_DEFUN([RACOON_CHECK_BUGGY_GETADDRINFO], [
94         AC_MSG_CHECKING(getaddrinfo bug)
95         saved_CFLAGS=$CFLAGS
96         CFLAGS="-Wall -O2"
97         AC_TRY_RUN([
98         #include <sys/types.h>
99         #include <sys/socket.h>
100         #include <netdb.h>
101         #include <stdlib.h>
102         #include <string.h>
103         #include <netinet/in.h>
104         
105         int main()
106         {
107           int passive, gaierr, inet4 = 0, inet6 = 0;
108           struct addrinfo hints, *ai, *aitop;
109           char straddr[INET6_ADDRSTRLEN], strport[16];
110         
111           for (passive = 0; passive <= 1; passive++) {
112             memset(&hints, 0, sizeof(hints));
113             hints.ai_family = AF_UNSPEC;
114             hints.ai_flags = passive ? AI_PASSIVE : 0;
115             hints.ai_protocol = IPPROTO_TCP;
116             hints.ai_socktype = SOCK_STREAM;
117             if ((gaierr = getaddrinfo(NULL, "54321", &hints, &aitop)) != 0) {
118               (void)gai_strerror(gaierr);
119               goto bad;
120             }
121             for (ai = aitop; ai; ai = ai->ai_next) {
122               if (ai->ai_addr == NULL ||
123                   ai->ai_addrlen == 0 ||
124                   getnameinfo(ai->ai_addr, ai->ai_addrlen,
125                               straddr, sizeof(straddr), strport, sizeof(strport),
126                               NI_NUMERICHOST|NI_NUMERICSERV) != 0) {
127                 goto bad;
128               }
129               switch (ai->ai_family) {
130               case AF_INET:
131                 if (strcmp(strport, "54321") != 0) {
132                   goto bad;
133                 }
134                 if (passive) {
135                   if (strcmp(straddr, "0.0.0.0") != 0) {
136                     goto bad;
137                   }
138                 } else {
139                   if (strcmp(straddr, "127.0.0.1") != 0) {
140                     goto bad;
141                   }
142                 }
143                 inet4++;
144                 break;
145               case AF_INET6:
146                 if (strcmp(strport, "54321") != 0) {
147                   goto bad;
148                 }
149                 if (passive) {
150                   if (strcmp(straddr, "::") != 0) {
151                     goto bad;
152                   }
153                 } else {
154                   if (strcmp(straddr, "::1") != 0) {
155                     goto bad;
156                   }
157                 }
158                 inet6++;
159                 break;
160               case AF_UNSPEC:
161                 goto bad;
162                 break;
163               default:
164                 /* another family support? */
165                 break;
166               }
167             }
168           }
169         
170           if (!(inet4 == 0 || inet4 == 2))
171             goto bad;
172           if (!(inet6 == 0 || inet6 == 2))
173             goto bad;
174         
175           if (aitop)
176             freeaddrinfo(aitop);
177           exit(0);
178         
179          bad:
180           if (aitop)
181             freeaddrinfo(aitop);
182           exit(1);
183         }
184         ],
185         AC_MSG_RESULT(good)
186         buggygetaddrinfo=no,
187         AC_MSG_RESULT(buggy)
188         buggygetaddrinfo=yes,
189         AC_MSG_RESULT(buggy)
190         buggygetaddrinfo=yes)
191         CFLAGS=$saved_CFLAGS
192         unset saved_CFLAGS
193 ])