summaryrefslogtreecommitdiffstats
path: root/ipsec-tools/acracoon.m4
blob: 1f7e6c15398bb751226e80f8076f7386b6355810 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
dnl RACOON_PATH_LIBS(FUNCTION, LIB, SEARCH-PATHS [, ACTION-IF-FOUND
dnl            [, ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
dnl Search for a library defining FUNC, if it's not already available.

AC_DEFUN([RACOON_PATH_LIBS],
[AC_PREREQ([2.13])
AC_CACHE_CHECK([for $2 containing $1], [ac_cv_search_$1],
[ac_func_search_save_LIBS="$LIBS"
ac_cv_search_$1="no"
AC_TRY_LINK_FUNC([$1], [ac_cv_search_$1="none required"],
	[LIBS="-l$2 $LIBS"
	AC_TRY_LINK_FUNC([$1], [ac_cv_search_$1="-l$2"], [])])
LIBS="$ac_func_search_save_LIBS"
ifelse("x$3", "x", , [ test "$ac_cv_search_$1" = "no" && for i in $3; do
  LIBS="-L$i -l$2 $ac_func_search_save_LIBS"
  AC_TRY_LINK_FUNC([$1],
  [ac_cv_search_$1="-L$i -l$2"
  break])
  done 
LIBS="$ac_func_search_save_LIBS" ]) ])
if test "$ac_cv_search_$1" != "no"; then
  test "$ac_cv_search_$1" = "none required" || LIBS="$ac_cv_search_$1 $LIBS"
  $4
else :
  $5
fi])

dnl  Check if either va_copy() or __va_copy() is available. On linux systems 
dnl  at least one of these should be present.
AC_DEFUN([RACOON_CHECK_VA_COPY], [
	saved_CFLAGS=$CFLAGS
	CFLAGS="-Wall -O2"
	AC_CACHE_CHECK([for an implementation of va_copy()],
		ac_cv_va_copy,[
		AC_TRY_RUN([#include <stdarg.h>
		void func (int i, ...) {
			va_list args1, args2;
			va_start (args1, i);
			va_copy (args2, args1);
			if (va_arg (args1, int) != 1 || va_arg (args2, int) != 1)
				exit (1);
	 		va_end (args1);
			va_end (args2);
		}
		int main() {
			func (0, 1);
			return 0;
		}],
		[ac_cv_va_copy=yes],
		[ac_cv_va_copy=no],
		AC_MSG_WARN(Cross compiling... Unable to test va_copy)
		[ac_cv_va_copy=no])
	])
	if test x$ac_cv_va_copy != xyes; then
		AC_CACHE_CHECK([for an implementation of __va_copy()],
			ac_cv___va_copy,[
			AC_TRY_RUN([#include <stdarg.h>
			void func (int i, ...) {
				va_list args1, args2;
				va_start (args1, i);
				__va_copy (args2, args1);
				if (va_arg (args1, int) != 1 || va_arg (args2, int) != 1)
					exit (1);
				va_end (args1);
				va_end (args2);
			}
			int main() {
				func (0, 1);
				return 0;
			}],
			[ac_cv___va_copy=yes],
			[ac_cv___va_copy=no],
			AC_MSG_WARN(Cross compiling... Unable to test __va_copy)
			[ac_cv___va_copy=no])
		])
	fi

	if test "x$ac_cv_va_copy" = "xyes"; then
		va_copy_func=va_copy
	elif test "x$ac_cv___va_copy" = "xyes"; then
		va_copy_func=__va_copy
	fi

	if test -n "$va_copy_func"; then
		AC_DEFINE_UNQUOTED(VA_COPY,$va_copy_func,
			[A 'va_copy' style function])
	else
		AC_MSG_WARN([Hmm, neither va_copy() nor __va_copy() found.])
		AC_MSG_WARN([Using a generic fallback.])
	fi
	CFLAGS=$saved_CFLAGS
	unset saved_CFLAGS
])

AC_DEFUN([RACOON_CHECK_BUGGY_GETADDRINFO], [
	AC_MSG_CHECKING(getaddrinfo bug)
	saved_CFLAGS=$CFLAGS
	CFLAGS="-Wall -O2"
	AC_TRY_RUN([
	#include <sys/types.h>
	#include <sys/socket.h>
	#include <netdb.h>
	#include <stdlib.h>
	#include <string.h>
	#include <netinet/in.h>
	
	int main()
	{
	  int passive, gaierr, inet4 = 0, inet6 = 0;
	  struct addrinfo hints, *ai, *aitop;
	  char straddr[INET6_ADDRSTRLEN], strport[16];
	
	  for (passive = 0; passive <= 1; passive++) {
	    memset(&hints, 0, sizeof(hints));
	    hints.ai_family = AF_UNSPEC;
	    hints.ai_flags = passive ? AI_PASSIVE : 0;
	    hints.ai_protocol = IPPROTO_TCP;
	    hints.ai_socktype = SOCK_STREAM;
	    if ((gaierr = getaddrinfo(NULL, "54321", &hints, &aitop)) != 0) {
	      (void)gai_strerror(gaierr);
	      goto bad;
	    }
	    for (ai = aitop; ai; ai = ai->ai_next) {
	      if (ai->ai_addr == NULL ||
	          ai->ai_addrlen == 0 ||
	          getnameinfo(ai->ai_addr, ai->ai_addrlen,
	                      straddr, sizeof(straddr), strport, sizeof(strport),
	                      NI_NUMERICHOST|NI_NUMERICSERV) != 0) {
	        goto bad;
	      }
	      switch (ai->ai_family) {
	      case AF_INET:
		if (strcmp(strport, "54321") != 0) {
		  goto bad;
		}
	        if (passive) {
	          if (strcmp(straddr, "0.0.0.0") != 0) {
	            goto bad;
	          }
	        } else {
	          if (strcmp(straddr, "127.0.0.1") != 0) {
	            goto bad;
	          }
	        }
	        inet4++;
	        break;
	      case AF_INET6:
		if (strcmp(strport, "54321") != 0) {
		  goto bad;
		}
	        if (passive) {
	          if (strcmp(straddr, "::") != 0) {
	            goto bad;
	          }
	        } else {
	          if (strcmp(straddr, "::1") != 0) {
	            goto bad;
	          }
	        }
	        inet6++;
	        break;
	      case AF_UNSPEC:
	        goto bad;
	        break;
	      default:
	        /* another family support? */
	        break;
	      }
	    }
	  }
	
	  if (!(inet4 == 0 || inet4 == 2))
	    goto bad;
	  if (!(inet6 == 0 || inet6 == 2))
	    goto bad;
	
	  if (aitop)
	    freeaddrinfo(aitop);
	  exit(0);
	
	 bad:
	  if (aitop)
	    freeaddrinfo(aitop);
	  exit(1);
	}
	],
	AC_MSG_RESULT(good)
	buggygetaddrinfo=no,
	AC_MSG_RESULT(buggy)
	buggygetaddrinfo=yes,
	AC_MSG_RESULT(Cross compiling ... Assuming getaddrinfo is not buggy.)
	buggygetaddrinfo=no)
	CFLAGS=$saved_CFLAGS
	unset saved_CFLAGS
])