#include <stdlib.h> for exit() prototype
[platform/upstream/c-ares.git] / acinclude.m4
1
2
3 dnl CURL_CHECK_COMPILER_HALT_ON_ERROR
4 dnl -------------------------------------------------
5 dnl Verifies if the compiler actually halts after the
6 dnl compilation phase without generating any object
7 dnl code file, when the source compiles with errors.
8
9 AC_DEFUN([CURL_CHECK_COMPILER_HALT_ON_ERROR], [
10   AC_MSG_CHECKING([if compiler halts on compilation errors])
11   AC_COMPILE_IFELSE([
12     AC_LANG_PROGRAM([[
13     ]],[[
14       force compilation error
15     ]])
16   ],[
17     AC_MSG_RESULT([no])
18     AC_MSG_ERROR([compiler does not halt on compilation errors.])
19   ],[
20     AC_MSG_RESULT([yes])
21   ])
22 ])
23
24
25 dnl CURL_CHECK_COMPILER_ARRAY_SIZE_NEGATIVE
26 dnl -------------------------------------------------
27 dnl Verifies if the compiler actually halts after the
28 dnl compilation phase without generating any object
29 dnl code file, when the source code tries to define a
30 dnl type for a constant array with negative dimension.
31
32 AC_DEFUN([CURL_CHECK_COMPILER_ARRAY_SIZE_NEGATIVE], [
33   AC_REQUIRE([CURL_CHECK_COMPILER_HALT_ON_ERROR])dnl
34   AC_MSG_CHECKING([if compiler halts on negative sized arrays])
35   AC_COMPILE_IFELSE([
36     AC_LANG_PROGRAM([[
37       typedef char bad_t[sizeof(char) == sizeof(int) ? -1 : -1 ];
38     ]],[[
39       bad_t dummy;
40     ]])
41   ],[
42     AC_MSG_RESULT([no])
43     AC_MSG_ERROR([compiler does not halt on negative sized arrays.])
44   ],[
45     AC_MSG_RESULT([yes])
46   ])
47 ])
48
49
50 dnl CURL_CHECK_DEF (SYMBOL, [INCLUDES], [SILENT])
51 dnl -------------------------------------------------
52 dnl Use the C preprocessor to find out if the given object-style symbol
53 dnl is defined and get its expansion. This macro will not use default
54 dnl includes even if no INCLUDES argument is given. This macro will run
55 dnl silently when invoked with three arguments. If the expansion would
56 dnl result in a set of double-quoted strings the returned expansion will
57 dnl actually be a single double-quoted string concatenating all them.
58
59 AC_DEFUN([CURL_CHECK_DEF], [
60   AS_VAR_PUSHDEF([ac_HaveDef], [curl_cv_have_def_$1])dnl
61   AS_VAR_PUSHDEF([ac_Def], [curl_cv_def_$1])dnl
62   if test -z "$SED"; then
63     AC_MSG_ERROR([SED not set. Cannot continue without SED being set.])
64   fi
65   if test -z "$GREP"; then
66     AC_MSG_ERROR([GREP not set. Cannot continue without GREP being set.])
67   fi
68   ifelse($3,,[AC_MSG_CHECKING([for preprocessor definition of $1])])
69   tmp_exp=""
70   AC_PREPROC_IFELSE([
71     AC_LANG_SOURCE(
72 ifelse($2,,,[$2])[[
73 #ifdef $1
74 CURL_DEF_TOKEN $1
75 #endif
76     ]])
77   ],[
78     tmp_exp=`eval "$ac_cpp conftest.$ac_ext" 2>/dev/null | \
79       "$GREP" CURL_DEF_TOKEN 2>/dev/null | \
80       "$SED" 's/.*CURL_DEF_TOKEN[[ ]]//' 2>/dev/null | \
81       "$SED" 's/[["]][[ ]]*[["]]//g' 2>/dev/null`
82     if test -z "$tmp_exp" || test "$tmp_exp" = "$1"; then
83       tmp_exp=""
84     fi
85   ])
86   if test -z "$tmp_exp"; then
87     AS_VAR_SET(ac_HaveDef, no)
88     ifelse($3,,[AC_MSG_RESULT([no])])
89   else
90     AS_VAR_SET(ac_HaveDef, yes)
91     AS_VAR_SET(ac_Def, $tmp_exp)
92     ifelse($3,,[AC_MSG_RESULT([$tmp_exp])])
93   fi
94   AS_VAR_POPDEF([ac_Def])dnl
95   AS_VAR_POPDEF([ac_HaveDef])dnl
96 ])
97
98
99 dnl CARES_CHECK_AIX_ALL_SOURCE
100 dnl -------------------------------------------------
101 dnl Provides a replacement of traditional AC_AIX with
102 dnl an uniform behaviour across all autoconf versions,
103 dnl and with our own placement rules.
104
105 AC_DEFUN([CARES_CHECK_AIX_ALL_SOURCE], [
106   AH_VERBATIM([_ALL_SOURCE],
107     [/* Define to 1 if OS is AIX. */
108 #ifndef _ALL_SOURCE
109 #  undef _ALL_SOURCE
110 #endif])
111   AC_BEFORE([$0], [AC_SYS_LARGEFILE])dnl
112   AC_BEFORE([$0], [CARES_CONFIGURE_REENTRANT])dnl
113   AC_MSG_CHECKING([if OS is AIX (to define _ALL_SOURCE)])
114   AC_EGREP_CPP([yes_this_is_aix],[
115 #ifdef _AIX
116    yes_this_is_aix
117 #endif
118   ],[
119     AC_MSG_RESULT([yes])
120     AC_DEFINE(_ALL_SOURCE)
121   ],[
122     AC_MSG_RESULT([no])
123   ])
124 ])
125
126
127 dnl CURL_CHECK_HEADER_WINDOWS
128 dnl -------------------------------------------------
129 dnl Check for compilable and valid windows.h header 
130
131 AC_DEFUN([CURL_CHECK_HEADER_WINDOWS], [
132   AC_CACHE_CHECK([for windows.h], [ac_cv_header_windows_h], [
133     AC_COMPILE_IFELSE([
134       AC_LANG_PROGRAM([[
135 #undef inline
136 #ifndef WIN32_LEAN_AND_MEAN
137 #define WIN32_LEAN_AND_MEAN
138 #endif
139 #include <windows.h>
140       ]],[[
141 #if defined(__CYGWIN__) || defined(__CEGCC__)
142         HAVE_WINDOWS_H shall not be defined.
143 #else
144         int dummy=2*WINVER;
145 #endif
146       ]])
147     ],[
148       ac_cv_header_windows_h="yes"
149     ],[
150       ac_cv_header_windows_h="no"
151     ])
152   ])
153   case "$ac_cv_header_windows_h" in
154     yes)
155       AC_DEFINE_UNQUOTED(HAVE_WINDOWS_H, 1,
156         [Define to 1 if you have the windows.h header file.])
157       AC_DEFINE_UNQUOTED(WIN32_LEAN_AND_MEAN, 1,
158         [Define to avoid automatic inclusion of winsock.h])
159       ;;
160   esac
161 ])
162
163
164 dnl CURL_CHECK_NATIVE_WINDOWS
165 dnl -------------------------------------------------
166 dnl Check if building a native Windows target
167
168 AC_DEFUN([CURL_CHECK_NATIVE_WINDOWS], [
169   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
170   AC_CACHE_CHECK([whether build target is a native Windows one], [ac_cv_native_windows], [
171     if test "$ac_cv_header_windows_h" = "no"; then
172       ac_cv_native_windows="no"
173     else
174       AC_COMPILE_IFELSE([
175         AC_LANG_PROGRAM([[
176         ]],[[
177 #if defined(__MINGW32__) || defined(__MINGW32CE__) || \
178    (defined(_MSC_VER) && (defined(_WIN32) || defined(_WIN64)))
179           int dummy=1;
180 #else
181           Not a native Windows build target.
182 #endif
183         ]])
184       ],[
185         ac_cv_native_windows="yes"
186       ],[
187         ac_cv_native_windows="no"
188       ])
189     fi
190   ])
191   case "$ac_cv_native_windows" in
192     yes)
193       AC_DEFINE_UNQUOTED(NATIVE_WINDOWS, 1,
194         [Define to 1 if you are building a native Windows target.])
195       ;;
196   esac
197 ])
198
199
200 dnl CURL_CHECK_HEADER_WINSOCK
201 dnl -------------------------------------------------
202 dnl Check for compilable and valid winsock.h header 
203
204 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK], [
205   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
206   AC_CACHE_CHECK([for winsock.h], [ac_cv_header_winsock_h], [
207     AC_COMPILE_IFELSE([
208       AC_LANG_PROGRAM([[
209 #undef inline
210 #ifndef WIN32_LEAN_AND_MEAN
211 #define WIN32_LEAN_AND_MEAN
212 #endif
213 #include <windows.h>
214 #include <winsock.h>
215       ]],[[
216 #if defined(__CYGWIN__) || defined(__CEGCC__)
217         HAVE_WINSOCK_H shall not be defined.
218 #else
219         int dummy=WSACleanup();
220 #endif
221       ]])
222     ],[
223       ac_cv_header_winsock_h="yes"
224     ],[
225       ac_cv_header_winsock_h="no"
226     ])
227   ])
228   case "$ac_cv_header_winsock_h" in
229     yes)
230       AC_DEFINE_UNQUOTED(HAVE_WINSOCK_H, 1,
231         [Define to 1 if you have the winsock.h header file.])
232       ;;
233   esac
234 ])
235
236
237 dnl CURL_CHECK_HEADER_WINSOCK2
238 dnl -------------------------------------------------
239 dnl Check for compilable and valid winsock2.h header 
240
241 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK2], [
242   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
243   AC_CACHE_CHECK([for winsock2.h], [ac_cv_header_winsock2_h], [
244     AC_COMPILE_IFELSE([
245       AC_LANG_PROGRAM([[
246 #undef inline
247 #ifndef WIN32_LEAN_AND_MEAN
248 #define WIN32_LEAN_AND_MEAN
249 #endif
250 #include <windows.h>
251 #include <winsock2.h>
252       ]],[[
253 #if defined(__CYGWIN__) || defined(__CEGCC__) || defined(__MINGW32CE__)
254         HAVE_WINSOCK2_H shall not be defined.
255 #else
256         int dummy=2*IPPROTO_ESP;
257 #endif
258       ]])
259     ],[
260       ac_cv_header_winsock2_h="yes"
261     ],[
262       ac_cv_header_winsock2_h="no"
263     ])
264   ])
265   case "$ac_cv_header_winsock2_h" in
266     yes)
267       AC_DEFINE_UNQUOTED(HAVE_WINSOCK2_H, 1,
268         [Define to 1 if you have the winsock2.h header file.])
269       ;;
270   esac
271 ])
272
273
274 dnl CURL_CHECK_HEADER_WS2TCPIP
275 dnl -------------------------------------------------
276 dnl Check for compilable and valid ws2tcpip.h header
277
278 AC_DEFUN([CURL_CHECK_HEADER_WS2TCPIP], [
279   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
280   AC_CACHE_CHECK([for ws2tcpip.h], [ac_cv_header_ws2tcpip_h], [
281     AC_COMPILE_IFELSE([
282       AC_LANG_PROGRAM([[
283 #undef inline
284 #ifndef WIN32_LEAN_AND_MEAN
285 #define WIN32_LEAN_AND_MEAN
286 #endif
287 #include <windows.h>
288 #include <winsock2.h>
289 #include <ws2tcpip.h>
290       ]],[[
291 #if defined(__CYGWIN__) || defined(__CEGCC__) || defined(__MINGW32CE__)
292         HAVE_WS2TCPIP_H shall not be defined.
293 #else
294         int dummy=2*IP_PKTINFO;
295 #endif
296       ]])
297     ],[
298       ac_cv_header_ws2tcpip_h="yes"
299     ],[
300       ac_cv_header_ws2tcpip_h="no"
301     ])
302   ])
303   case "$ac_cv_header_ws2tcpip_h" in
304     yes)
305       AC_DEFINE_UNQUOTED(HAVE_WS2TCPIP_H, 1,
306         [Define to 1 if you have the ws2tcpip.h header file.])
307       ;;
308   esac
309 ])
310
311
312 dnl CURL_CHECK_HEADER_MALLOC
313 dnl -------------------------------------------------
314 dnl Check for compilable and valid malloc.h header,
315 dnl and check if it is needed even with stdlib.h
316
317 AC_DEFUN([CURL_CHECK_HEADER_MALLOC], [
318   AC_CACHE_CHECK([for malloc.h], [ac_cv_header_malloc_h], [
319     AC_COMPILE_IFELSE([
320       AC_LANG_PROGRAM([[
321 #include <malloc.h>
322       ]],[[
323         void *p = malloc(10);
324         void *q = calloc(10,10);
325         free(p);
326         free(q);
327       ]])
328     ],[
329       ac_cv_header_malloc_h="yes"
330     ],[
331       ac_cv_header_malloc_h="no"
332     ])
333   ])
334   if test "$ac_cv_header_malloc_h" = "yes"; then
335     AC_DEFINE_UNQUOTED(HAVE_MALLOC_H, 1,
336       [Define to 1 if you have the malloc.h header file.])
337     #
338     AC_COMPILE_IFELSE([
339       AC_LANG_PROGRAM([[
340 #include <stdlib.h>
341       ]],[[
342         void *p = malloc(10);
343         void *q = calloc(10,10);
344         free(p);
345         free(q);
346       ]])
347     ],[
348       curl_cv_need_header_malloc_h="no"
349     ],[
350       curl_cv_need_header_malloc_h="yes"
351     ])
352     #
353     case "$curl_cv_need_header_malloc_h" in
354       yes)
355         AC_DEFINE_UNQUOTED(NEED_MALLOC_H, 1,
356           [Define to 1 if you need the malloc.h header file even with stdlib.h])
357         ;;
358     esac
359   fi
360 ])
361
362
363 dnl CURL_CHECK_TYPE_SOCKLEN_T
364 dnl -------------------------------------------------
365 dnl Check for existing socklen_t type, and provide
366 dnl an equivalent type if socklen_t not available
367
368 AC_DEFUN([CURL_CHECK_TYPE_SOCKLEN_T], [
369   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
370   AC_CHECK_TYPE([socklen_t], ,[
371     dnl socklen_t not available
372     AC_CACHE_CHECK([for socklen_t equivalent],
373       [curl_cv_socklen_t_equiv], [
374       curl_cv_socklen_t_equiv="unknown"
375       for arg1 in 'int' 'SOCKET'; do
376         for arg2 in "struct sockaddr" void; do
377           for t in int size_t unsigned long "unsigned long"; do
378             if test "$curl_cv_socklen_t_equiv" = "unknown"; then
379               AC_COMPILE_IFELSE([
380                 AC_LANG_PROGRAM([[
381 #undef inline
382 #ifdef HAVE_WINDOWS_H
383 #ifndef WIN32_LEAN_AND_MEAN
384 #define WIN32_LEAN_AND_MEAN
385 #endif
386 #include <windows.h>
387 #ifdef HAVE_WINSOCK2_H
388 #include <winsock2.h>
389 #else
390 #ifdef HAVE_WINSOCK_H
391 #include <winsock.h>
392 #endif
393 #endif
394 #define GETPEERNCALLCONV PASCAL
395 #else
396 #ifdef HAVE_SYS_TYPES_H
397 #include <sys/types.h>
398 #endif
399 #ifdef HAVE_SYS_SOCKET_H
400 #include <sys/socket.h>
401 #endif
402 #define GETPEERNCALLCONV
403 #endif
404                   extern int GETPEERNCALLCONV getpeername($arg1, $arg2 *, $t *);
405                 ]],[[
406                   $t len=0;
407                   getpeername(0,0,&len);
408                 ]])
409               ],[
410                 curl_cv_socklen_t_equiv="$t"
411               ])
412             fi
413           done
414         done
415       done
416     ])
417     case "$curl_cv_socklen_t_equiv" in
418       unknown)
419         AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
420         ;;
421       *)
422         AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
423           [Type to use in place of socklen_t when system does not provide it.])
424         ;;
425     esac
426   ],[
427 #undef inline
428 #ifdef HAVE_WINDOWS_H
429 #ifndef WIN32_LEAN_AND_MEAN
430 #define WIN32_LEAN_AND_MEAN
431 #endif
432 #include <windows.h>
433 #ifdef HAVE_WINSOCK2_H
434 #include <winsock2.h>
435 #ifdef HAVE_WS2TCPIP_H
436 #include <ws2tcpip.h>
437 #endif
438 #endif
439 #else
440 #ifdef HAVE_SYS_TYPES_H
441 #include <sys/types.h>
442 #endif
443 #ifdef HAVE_SYS_SOCKET_H
444 #include <sys/socket.h>
445 #endif
446 #endif
447   ])
448 ])
449
450
451 dnl CURL_CHECK_FUNC_GETNAMEINFO
452 dnl -------------------------------------------------
453 dnl Test if the getnameinfo function is available, 
454 dnl and check the types of five of its arguments.
455 dnl If the function succeeds HAVE_GETNAMEINFO will be
456 dnl defined, defining the types of the arguments in
457 dnl GETNAMEINFO_TYPE_ARG1, GETNAMEINFO_TYPE_ARG2,
458 dnl GETNAMEINFO_TYPE_ARG46 and GETNAMEINFO_TYPE_ARG7,
459 dnl and also defining the type qualifier of first 
460 dnl argument in GETNAMEINFO_QUAL_ARG1.
461
462 AC_DEFUN([CURL_CHECK_FUNC_GETNAMEINFO], [
463   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
464   AC_REQUIRE([CURL_CHECK_TYPE_SOCKLEN_T])dnl
465   AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h)
466   #
467   AC_MSG_CHECKING([for getnameinfo])
468   AC_LINK_IFELSE([
469     AC_LANG_FUNC_LINK_TRY([getnameinfo])
470   ],[
471     AC_MSG_RESULT([yes])
472     curl_cv_getnameinfo="yes"
473   ],[
474     AC_MSG_RESULT([no])
475     curl_cv_getnameinfo="no"
476   ])
477   #
478   if test "$curl_cv_getnameinfo" != "yes"; then
479     AC_MSG_CHECKING([deeper for getnameinfo])
480     AC_LINK_IFELSE([
481       AC_LANG_PROGRAM([[
482       ]],[[
483         getnameinfo();
484       ]])
485     ],[
486       AC_MSG_RESULT([yes])
487       curl_cv_getnameinfo="yes"
488     ],[
489       AC_MSG_RESULT([but still no])
490       curl_cv_getnameinfo="no"
491     ])
492   fi
493   #
494   if test "$curl_cv_getnameinfo" != "yes"; then
495     AC_MSG_CHECKING([deeper and deeper for getnameinfo])
496     AC_LINK_IFELSE([
497       AC_LANG_PROGRAM([[
498 #undef inline
499 #ifdef HAVE_WINDOWS_H
500 #ifndef WIN32_LEAN_AND_MEAN
501 #define WIN32_LEAN_AND_MEAN
502 #endif
503 #include <windows.h>
504 #ifdef HAVE_WINSOCK2_H
505 #include <winsock2.h>
506 #ifdef HAVE_WS2TCPIP_H
507 #include <ws2tcpip.h>
508 #endif
509 #endif
510 #else
511 #ifdef HAVE_SYS_TYPES_H
512 #include <sys/types.h>
513 #endif
514 #ifdef HAVE_SYS_SOCKET_H
515 #include <sys/socket.h>
516 #endif
517 #ifdef HAVE_NETDB_H
518 #include <netdb.h>
519 #endif
520 #endif
521       ]],[[
522         getnameinfo(0, 0, 0, 0, 0, 0, 0);
523       ]])
524     ],[
525       AC_MSG_RESULT([yes])
526       curl_cv_getnameinfo="yes"
527     ],[
528       AC_MSG_RESULT([but still no])
529       curl_cv_getnameinfo="no"
530     ])
531   fi
532   #
533   if test "$curl_cv_getnameinfo" = "yes"; then
534     AC_CACHE_CHECK([types of arguments for getnameinfo],
535       [curl_cv_func_getnameinfo_args], [
536       curl_cv_func_getnameinfo_args="unknown"
537       for gni_arg1 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
538         for gni_arg2 in 'socklen_t' 'size_t' 'int'; do
539           for gni_arg46 in 'size_t' 'int' 'socklen_t' 'unsigned int' 'DWORD'; do
540             for gni_arg7 in 'int' 'unsigned int'; do
541               if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
542                 AC_COMPILE_IFELSE([
543                   AC_LANG_PROGRAM([[
544 #undef inline 
545 #ifdef HAVE_WINDOWS_H
546 #ifndef WIN32_LEAN_AND_MEAN
547 #define WIN32_LEAN_AND_MEAN
548 #endif
549 #if (!defined(_WIN32_WINNT)) || (_WIN32_WINNT < 0x0501)
550 #undef _WIN32_WINNT
551 #define _WIN32_WINNT 0x0501
552 #endif
553 #include <windows.h>
554 #ifdef HAVE_WINSOCK2_H
555 #include <winsock2.h> 
556 #ifdef HAVE_WS2TCPIP_H
557 #include <ws2tcpip.h>
558 #endif
559 #endif
560 #define GNICALLCONV WSAAPI
561 #else
562 #ifdef HAVE_SYS_TYPES_H
563 #include <sys/types.h>
564 #endif
565 #ifdef HAVE_SYS_SOCKET_H
566 #include <sys/socket.h>
567 #endif
568 #ifdef HAVE_NETDB_H
569 #include <netdb.h>
570 #endif
571 #define GNICALLCONV
572 #endif
573                     extern int GNICALLCONV getnameinfo($gni_arg1, $gni_arg2,
574                                            char *, $gni_arg46,
575                                            char *, $gni_arg46,
576                                            $gni_arg7);
577                   ]],[[
578                     $gni_arg2 salen=0;
579                     $gni_arg46 hostlen=0;
580                     $gni_arg46 servlen=0;
581                     $gni_arg7 flags=0;
582                     int res = getnameinfo(0, salen, 0, hostlen, 0, servlen, flags);
583                   ]])
584                 ],[
585                   curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7"
586                 ])
587               fi
588             done
589           done
590         done
591       done
592     ]) # AC-CACHE-CHECK
593     if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
594       AC_MSG_WARN([Cannot find proper types to use for getnameinfo args])
595       AC_MSG_WARN([HAVE_GETNAMEINFO will not be defined])
596     else
597       gni_prev_IFS=$IFS; IFS=','
598       set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'`
599       IFS=$gni_prev_IFS
600       shift
601       #
602       gni_qual_type_arg1=$[1]
603       #
604       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2],
605         [Define to the type of arg 2 for getnameinfo.])
606       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3],
607         [Define to the type of args 4 and 6 for getnameinfo.])
608       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4],
609         [Define to the type of arg 7 for getnameinfo.])
610       #
611       prev_sh_opts=$-
612       #
613       case $prev_sh_opts in
614         *f*)
615           ;;
616         *)
617           set -f
618           ;;
619       esac
620       #
621       case "$gni_qual_type_arg1" in
622         const*)
623           gni_qual_arg1=const
624           gni_type_arg1=`echo $gni_qual_type_arg1 | sed 's/^const //'`
625         ;;
626         *)
627           gni_qual_arg1=
628           gni_type_arg1=$gni_qual_type_arg1
629         ;;
630       esac
631       #
632       AC_DEFINE_UNQUOTED(GETNAMEINFO_QUAL_ARG1, $gni_qual_arg1,
633         [Define to the type qualifier of arg 1 for getnameinfo.])
634       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $gni_type_arg1,
635         [Define to the type of arg 1 for getnameinfo.])
636       #
637       case $prev_sh_opts in
638         *f*)
639           ;;
640         *)
641           set +f
642           ;;
643       esac
644       #
645       AC_DEFINE_UNQUOTED(HAVE_GETNAMEINFO, 1,
646         [Define to 1 if you have the getnameinfo function.])
647       ac_cv_func_getnameinfo="yes"
648     fi
649   fi
650 ])
651
652
653 dnl TYPE_SOCKADDR_STORAGE
654 dnl -------------------------------------------------
655 dnl Check for struct sockaddr_storage. Most IPv6-enabled 
656 dnl hosts have it, but AIX 4.3 is one known exception.
657
658 AC_DEFUN([TYPE_SOCKADDR_STORAGE],
659 [
660    AC_CHECK_TYPE([struct sockaddr_storage],
661         AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
662                   [if struct sockaddr_storage is defined]), ,
663    [
664 #undef inline
665 #ifdef HAVE_WINDOWS_H
666 #ifndef WIN32_LEAN_AND_MEAN
667 #define WIN32_LEAN_AND_MEAN
668 #endif
669 #include <windows.h>
670 #ifdef HAVE_WINSOCK2_H
671 #include <winsock2.h>
672 #endif
673 #else
674 #ifdef HAVE_SYS_TYPES_H
675 #include <sys/types.h>
676 #endif
677 #ifdef HAVE_SYS_SOCKET_H
678 #include <sys/socket.h>
679 #endif
680 #ifdef HAVE_NETINET_IN_H
681 #include <netinet/in.h>
682 #endif
683 #ifdef HAVE_ARPA_INET_H
684 #include <arpa/inet.h>
685 #endif
686 #endif
687    ])
688 ])
689
690
691 dnl CURL_CHECK_NI_WITHSCOPEID
692 dnl -------------------------------------------------
693 dnl Check for working NI_WITHSCOPEID in getnameinfo()
694
695 AC_DEFUN([CURL_CHECK_NI_WITHSCOPEID], [
696   AC_REQUIRE([CURL_CHECK_FUNC_GETNAMEINFO])dnl
697   AC_REQUIRE([TYPE_SOCKADDR_STORAGE])dnl
698   AC_CHECK_HEADERS(stdio.h sys/types.h sys/socket.h \
699                    netdb.h netinet/in.h arpa/inet.h)
700   #
701   AC_CACHE_CHECK([for working NI_WITHSCOPEID], 
702     [ac_cv_working_ni_withscopeid], [
703     AC_RUN_IFELSE([
704       AC_LANG_PROGRAM([[
705 #ifdef HAVE_STDLIB_H
706 #include <stdlib.h>
707 #endif
708 #ifdef HAVE_STDIO_H
709 #include <stdio.h>
710 #endif
711 #ifdef HAVE_SYS_TYPES_H
712 #include <sys/types.h>
713 #endif
714 #ifdef HAVE_SYS_SOCKET_H
715 #include <sys/socket.h>
716 #endif
717 #ifdef HAVE_NETDB_H
718 #include <netdb.h>
719 #endif
720 #ifdef HAVE_NETINET_IN_H
721 #include <netinet/in.h>
722 #endif
723 #ifdef HAVE_ARPA_INET_H
724 #include <arpa/inet.h>
725 #endif
726       ]],[[
727 #if defined(NI_WITHSCOPEID) && defined(HAVE_GETNAMEINFO)
728 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE
729         struct sockaddr_storage sa;
730 #else
731         unsigned char sa[256];
732 #endif
733         char hostbuf[NI_MAXHOST];
734         int rc;
735         GETNAMEINFO_TYPE_ARG2 salen = (GETNAMEINFO_TYPE_ARG2)sizeof(sa);
736         GETNAMEINFO_TYPE_ARG46 hostlen = (GETNAMEINFO_TYPE_ARG46)sizeof(hostbuf);
737         GETNAMEINFO_TYPE_ARG7 flags = NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
738         int fd = socket(AF_INET6, SOCK_STREAM, 0);
739         if(fd < 0) {
740           perror("socket()");
741           return 1; /* Error creating socket */
742         }
743         rc = getsockname(fd, (GETNAMEINFO_TYPE_ARG1)&sa, &salen);
744         if(rc) {
745           perror("getsockname()");
746           return 2; /* Error retrieving socket name */
747         }
748         rc = getnameinfo((GETNAMEINFO_TYPE_ARG1)&sa, salen, hostbuf, hostlen, NULL, 0, flags);
749         if(rc) {
750           printf("rc = %s\n", gai_strerror(rc));
751           return 3; /* Error translating socket address */
752         }
753         return 0; /* Ok, NI_WITHSCOPEID works */
754 #else
755         return 4; /* Error, NI_WITHSCOPEID not defined or no getnameinfo() */
756 #endif
757       ]]) # AC-LANG-PROGRAM
758     ],[
759       # Exit code == 0. Program worked.
760       ac_cv_working_ni_withscopeid="yes"
761     ],[
762       # Exit code != 0. Program failed.
763       ac_cv_working_ni_withscopeid="no"
764     ],[
765       # Program is not run when cross-compiling. So we assume
766       # NI_WITHSCOPEID will work if we are able to compile it.
767       AC_COMPILE_IFELSE([
768         AC_LANG_PROGRAM([[
769 #include <sys/types.h>
770 #include <sys/socket.h>
771 #include <netdb.h>
772         ]],[[
773           unsigned int dummy= NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
774         ]])
775       ],[
776         ac_cv_working_ni_withscopeid="yes"
777       ],[
778         ac_cv_working_ni_withscopeid="no"
779       ]) # AC-COMPILE-IFELSE
780     ]) # AC-RUN-IFELSE
781   ]) # AC-CACHE-CHECK
782   case "$ac_cv_working_ni_withscopeid" in
783     yes)
784       AC_DEFINE(HAVE_NI_WITHSCOPEID, 1,
785         [Define to 1 if NI_WITHSCOPEID exists and works.])
786       ;;
787   esac
788 ])
789
790
791 dnl CURL_CHECK_FUNC_RECV
792 dnl -------------------------------------------------
793 dnl Test if the socket recv() function is available, 
794 dnl and check its return type and the types of its 
795 dnl arguments. If the function succeeds HAVE_RECV 
796 dnl will be defined, defining the types of the arguments 
797 dnl in RECV_TYPE_ARG1, RECV_TYPE_ARG2, RECV_TYPE_ARG3 
798 dnl and RECV_TYPE_ARG4, defining the type of the function
799 dnl return value in RECV_TYPE_RETV.
800
801 AC_DEFUN([CURL_CHECK_FUNC_RECV], [
802   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
803   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
804   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
805   #
806   AC_MSG_CHECKING([for recv])
807   AC_LINK_IFELSE([
808     AC_LANG_PROGRAM([[
809 #undef inline 
810 #ifdef HAVE_WINDOWS_H
811 #ifndef WIN32_LEAN_AND_MEAN
812 #define WIN32_LEAN_AND_MEAN
813 #endif
814 #include <windows.h>
815 #ifdef HAVE_WINSOCK2_H
816 #include <winsock2.h>
817 #else
818 #ifdef HAVE_WINSOCK_H
819 #include <winsock.h>
820 #endif
821 #endif
822 #else
823 #ifdef HAVE_SYS_TYPES_H
824 #include <sys/types.h>
825 #endif
826 #ifdef HAVE_SYS_SOCKET_H
827 #include <sys/socket.h>
828 #endif
829 #endif
830     ]],[[
831       recv(0, 0, 0, 0);
832     ]])
833   ],[
834     AC_MSG_RESULT([yes])
835     curl_cv_recv="yes"
836   ],[
837     AC_MSG_RESULT([no])
838     curl_cv_recv="no"
839   ])
840   #
841   if test "$curl_cv_recv" = "yes"; then
842     AC_CACHE_CHECK([types of args and return type for recv],
843       [curl_cv_func_recv_args], [
844       curl_cv_func_recv_args="unknown"
845       for recv_retv in 'int' 'ssize_t'; do
846         for recv_arg1 in 'int' 'ssize_t' 'SOCKET'; do
847           for recv_arg2 in 'char *' 'void *'; do
848             for recv_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
849               for recv_arg4 in 'int' 'unsigned int'; do
850                 if test "$curl_cv_func_recv_args" = "unknown"; then
851                   AC_COMPILE_IFELSE([
852                     AC_LANG_PROGRAM([[
853 #undef inline 
854 #ifdef HAVE_WINDOWS_H
855 #ifndef WIN32_LEAN_AND_MEAN
856 #define WIN32_LEAN_AND_MEAN
857 #endif
858 #include <windows.h>
859 #ifdef HAVE_WINSOCK2_H
860 #include <winsock2.h>
861 #else
862 #ifdef HAVE_WINSOCK_H
863 #include <winsock.h>
864 #endif
865 #endif
866 #define RECVCALLCONV PASCAL
867 #else
868 #ifdef HAVE_SYS_TYPES_H
869 #include <sys/types.h>
870 #endif
871 #ifdef HAVE_SYS_SOCKET_H
872 #include <sys/socket.h>
873 #endif
874 #define RECVCALLCONV
875 #endif
876                       extern $recv_retv RECVCALLCONV
877                       recv($recv_arg1, $recv_arg2, $recv_arg3, $recv_arg4);
878                     ]],[[
879                       $recv_arg1 s=0;
880                       $recv_arg2 buf=0;
881                       $recv_arg3 len=0;
882                       $recv_arg4 flags=0;
883                       $recv_retv res = recv(s, buf, len, flags);
884                     ]])
885                   ],[
886                     curl_cv_func_recv_args="$recv_arg1,$recv_arg2,$recv_arg3,$recv_arg4,$recv_retv"
887                   ])
888                 fi
889               done
890             done
891           done
892         done
893       done
894     ]) # AC-CACHE-CHECK
895     if test "$curl_cv_func_recv_args" = "unknown"; then
896       AC_MSG_ERROR([Cannot find proper types to use for recv args])
897     else
898       recv_prev_IFS=$IFS; IFS=','
899       set dummy `echo "$curl_cv_func_recv_args" | sed 's/\*/\*/g'`
900       IFS=$recv_prev_IFS
901       shift
902       #
903       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG1, $[1],
904         [Define to the type of arg 1 for recv.])
905       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG2, $[2],
906         [Define to the type of arg 2 for recv.])
907       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG3, $[3],
908         [Define to the type of arg 3 for recv.])
909       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG4, $[4],
910         [Define to the type of arg 4 for recv.])
911       AC_DEFINE_UNQUOTED(RECV_TYPE_RETV, $[5],
912         [Define to the function return type for recv.])
913       #
914       AC_DEFINE_UNQUOTED(HAVE_RECV, 1,
915         [Define to 1 if you have the recv function.])
916       ac_cv_func_recv="yes"
917     fi
918   else
919     AC_MSG_ERROR([Unable to link function recv])
920   fi
921 ])
922
923
924 dnl CURL_CHECK_FUNC_SEND
925 dnl -------------------------------------------------
926 dnl Test if the socket send() function is available, 
927 dnl and check its return type and the types of its 
928 dnl arguments. If the function succeeds HAVE_SEND 
929 dnl will be defined, defining the types of the arguments 
930 dnl in SEND_TYPE_ARG1, SEND_TYPE_ARG2, SEND_TYPE_ARG3 
931 dnl and SEND_TYPE_ARG4, defining the type of the function
932 dnl return value in SEND_TYPE_RETV, and also defining the 
933 dnl type qualifier of second argument in SEND_QUAL_ARG2.
934
935 AC_DEFUN([CURL_CHECK_FUNC_SEND], [
936   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
937   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
938   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
939   #
940   AC_MSG_CHECKING([for send])
941   AC_LINK_IFELSE([
942     AC_LANG_PROGRAM([[
943 #undef inline 
944 #ifdef HAVE_WINDOWS_H
945 #ifndef WIN32_LEAN_AND_MEAN
946 #define WIN32_LEAN_AND_MEAN
947 #endif
948 #include <windows.h>
949 #ifdef HAVE_WINSOCK2_H
950 #include <winsock2.h>
951 #else
952 #ifdef HAVE_WINSOCK_H
953 #include <winsock.h>
954 #endif
955 #endif
956 #else
957 #ifdef HAVE_SYS_TYPES_H
958 #include <sys/types.h>
959 #endif
960 #ifdef HAVE_SYS_SOCKET_H
961 #include <sys/socket.h>
962 #endif
963 #endif
964     ]],[[
965       send(0, 0, 0, 0);
966     ]])
967   ],[
968     AC_MSG_RESULT([yes])
969     curl_cv_send="yes"
970   ],[
971     AC_MSG_RESULT([no])
972     curl_cv_send="no"
973   ])
974   #
975   if test "$curl_cv_send" = "yes"; then
976     AC_CACHE_CHECK([types of args and return type for send],
977       [curl_cv_func_send_args], [
978       curl_cv_func_send_args="unknown"
979       for send_retv in 'int' 'ssize_t'; do
980         for send_arg1 in 'int' 'ssize_t' 'SOCKET'; do
981           for send_arg2 in 'char *' 'void *' 'const char *' 'const void *'; do
982             for send_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
983               for send_arg4 in 'int' 'unsigned int'; do
984                 if test "$curl_cv_func_send_args" = "unknown"; then
985                   AC_COMPILE_IFELSE([
986                     AC_LANG_PROGRAM([[
987 #undef inline 
988 #ifdef HAVE_WINDOWS_H
989 #ifndef WIN32_LEAN_AND_MEAN
990 #define WIN32_LEAN_AND_MEAN
991 #endif
992 #include <windows.h>
993 #ifdef HAVE_WINSOCK2_H
994 #include <winsock2.h>
995 #else
996 #ifdef HAVE_WINSOCK_H
997 #include <winsock.h>
998 #endif
999 #endif
1000 #define SENDCALLCONV PASCAL
1001 #else
1002 #ifdef HAVE_SYS_TYPES_H
1003 #include <sys/types.h>
1004 #endif
1005 #ifdef HAVE_SYS_SOCKET_H
1006 #include <sys/socket.h>
1007 #endif
1008 #define SENDCALLCONV
1009 #endif
1010                       extern $send_retv SENDCALLCONV
1011                       send($send_arg1, $send_arg2, $send_arg3, $send_arg4);
1012                     ]],[[
1013                       $send_arg1 s=0;
1014                       $send_arg3 len=0;
1015                       $send_arg4 flags=0;
1016                       $send_retv res = send(s, 0, len, flags);
1017                     ]])
1018                   ],[
1019                     curl_cv_func_send_args="$send_arg1,$send_arg2,$send_arg3,$send_arg4,$send_retv"
1020                   ])
1021                 fi
1022               done
1023             done
1024           done
1025         done
1026       done
1027     ]) # AC-CACHE-CHECK
1028     if test "$curl_cv_func_send_args" = "unknown"; then
1029       AC_MSG_ERROR([Cannot find proper types to use for send args])
1030     else
1031       send_prev_IFS=$IFS; IFS=','
1032       set dummy `echo "$curl_cv_func_send_args" | sed 's/\*/\*/g'`
1033       IFS=$send_prev_IFS
1034       shift
1035       #
1036       send_qual_type_arg2=$[2]
1037       #
1038       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG1, $[1],
1039         [Define to the type of arg 1 for send.])
1040       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG3, $[3],
1041         [Define to the type of arg 3 for send.])
1042       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG4, $[4],
1043         [Define to the type of arg 4 for send.])
1044       AC_DEFINE_UNQUOTED(SEND_TYPE_RETV, $[5],
1045         [Define to the function return type for send.])
1046       #
1047       prev_sh_opts=$-
1048       #
1049       case $prev_sh_opts in
1050         *f*)
1051           ;;
1052         *)
1053           set -f
1054           ;;
1055       esac
1056       #
1057       case "$send_qual_type_arg2" in
1058         const*)
1059           send_qual_arg2=const
1060           send_type_arg2=`echo $send_qual_type_arg2 | sed 's/^const //'`
1061         ;;
1062         *)
1063           send_qual_arg2=
1064           send_type_arg2=$send_qual_type_arg2
1065         ;;
1066       esac
1067       #
1068       AC_DEFINE_UNQUOTED(SEND_QUAL_ARG2, $send_qual_arg2,
1069         [Define to the type qualifier of arg 2 for send.])
1070       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG2, $send_type_arg2,
1071         [Define to the type of arg 2 for send.])
1072       #
1073       case $prev_sh_opts in
1074         *f*)
1075           ;;
1076         *)
1077           set +f
1078           ;;
1079       esac
1080       #
1081       AC_DEFINE_UNQUOTED(HAVE_SEND, 1,
1082         [Define to 1 if you have the send function.])
1083       ac_cv_func_send="yes"
1084     fi
1085   else
1086     AC_MSG_ERROR([Unable to link function send])
1087   fi
1088 ])
1089
1090
1091 dnl CURL_CHECK_FUNC_RECVFROM
1092 dnl -------------------------------------------------
1093 dnl Test if the socket recvfrom() function is available,
1094 dnl and check its return type and the types of its
1095 dnl arguments. If the function succeeds HAVE_RECVFROM
1096 dnl will be defined, defining the types of the arguments
1097 dnl in RECVFROM_TYPE_ARG1, RECVFROM_TYPE_ARG2, and so on
1098 dnl to RECVFROM_TYPE_ARG6, defining also the type of the
1099 dnl function return value in RECVFROM_TYPE_RETV.
1100 dnl Notice that the types returned for pointer arguments
1101 dnl will actually be the type pointed by the pointer.
1102
1103 AC_DEFUN([CURL_CHECK_FUNC_RECVFROM], [
1104   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
1105   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
1106   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
1107   #
1108   AC_MSG_CHECKING([for recvfrom])
1109   AC_LINK_IFELSE([
1110     AC_LANG_PROGRAM([[
1111 #undef inline 
1112 #ifdef HAVE_WINDOWS_H
1113 #ifndef WIN32_LEAN_AND_MEAN
1114 #define WIN32_LEAN_AND_MEAN
1115 #endif
1116 #include <windows.h>
1117 #ifdef HAVE_WINSOCK2_H
1118 #include <winsock2.h>
1119 #else
1120 #ifdef HAVE_WINSOCK_H
1121 #include <winsock.h>
1122 #endif
1123 #endif
1124 #else
1125 #ifdef HAVE_SYS_TYPES_H
1126 #include <sys/types.h>
1127 #endif
1128 #ifdef HAVE_SYS_SOCKET_H
1129 #include <sys/socket.h>
1130 #endif
1131 #endif
1132     ]],[[
1133       recvfrom(0, 0, 0, 0, 0, 0);
1134     ]])
1135   ],[
1136     AC_MSG_RESULT([yes])
1137     curl_cv_recvfrom="yes"
1138   ],[
1139     AC_MSG_RESULT([no])
1140     curl_cv_recvfrom="no"
1141   ])
1142   #
1143   if test "$curl_cv_recvfrom" = "yes"; then
1144     AC_CACHE_CHECK([types of args and return type for recvfrom],
1145       [curl_cv_func_recvfrom_args], [
1146       curl_cv_func_recvfrom_args="unknown"
1147       for recvfrom_retv in 'int' 'ssize_t'; do
1148         for recvfrom_arg1 in 'int' 'ssize_t' 'SOCKET'; do
1149           for recvfrom_arg2 in 'char *' 'void *'; do
1150             for recvfrom_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
1151               for recvfrom_arg4 in 'int' 'unsigned int'; do
1152                 for recvfrom_arg5 in 'struct sockaddr *' 'void *'; do
1153                   for recvfrom_arg6 in 'socklen_t *' 'int *' 'unsigned int *' 'size_t *' 'void *'; do
1154                     if test "$curl_cv_func_recvfrom_args" = "unknown"; then
1155                       AC_COMPILE_IFELSE([
1156                         AC_LANG_PROGRAM([[
1157 #undef inline 
1158 #ifdef HAVE_WINDOWS_H
1159 #ifndef WIN32_LEAN_AND_MEAN
1160 #define WIN32_LEAN_AND_MEAN
1161 #endif
1162 #include <windows.h>
1163 #ifdef HAVE_WINSOCK2_H
1164 #include <winsock2.h>
1165 #else
1166 #ifdef HAVE_WINSOCK_H
1167 #include <winsock.h>
1168 #endif
1169 #endif
1170 #define RECVFROMCALLCONV PASCAL
1171 #else
1172 #ifdef HAVE_SYS_TYPES_H
1173 #include <sys/types.h>
1174 #endif
1175 #ifdef HAVE_SYS_SOCKET_H
1176 #include <sys/socket.h>
1177 #endif
1178 #define RECVFROMCALLCONV
1179 #endif
1180                           extern $recvfrom_retv RECVFROMCALLCONV
1181                           recvfrom($recvfrom_arg1, $recvfrom_arg2,
1182                                    $recvfrom_arg3, $recvfrom_arg4,
1183                                    $recvfrom_arg5, $recvfrom_arg6);
1184                         ]],[[
1185                           $recvfrom_arg1 s=0;
1186                           $recvfrom_arg2 buf=0;
1187                           $recvfrom_arg3 len=0;
1188                           $recvfrom_arg4 flags=0;
1189                           $recvfrom_arg5 addr=0;
1190                           $recvfrom_arg6 addrlen=0;
1191                           $recvfrom_retv res=0;
1192                           res = recvfrom(s, buf, len, flags, addr, addrlen);
1193                         ]])
1194                       ],[
1195                         curl_cv_func_recvfrom_args="$recvfrom_arg1,$recvfrom_arg2,$recvfrom_arg3,$recvfrom_arg4,$recvfrom_arg5,$recvfrom_arg6,$recvfrom_retv"
1196                       ])
1197                     fi
1198                   done
1199                 done
1200               done
1201             done
1202           done
1203         done
1204       done
1205     ]) # AC-CACHE-CHECK
1206     # Nearly last minute change for this release starts here
1207     AC_DEFINE_UNQUOTED(HAVE_RECVFROM, 1,
1208       [Define to 1 if you have the recvfrom function.])
1209     ac_cv_func_recvfrom="yes"
1210     # Nearly last minute change for this release ends here
1211     if test "$curl_cv_func_recvfrom_args" = "unknown"; then
1212       AC_MSG_WARN([Cannot find proper types to use for recvfrom args])
1213     else
1214       recvfrom_prev_IFS=$IFS; IFS=','
1215       set dummy `echo "$curl_cv_func_recvfrom_args" | sed 's/\*/\*/g'`
1216       IFS=$recvfrom_prev_IFS
1217       shift
1218       #
1219       recvfrom_ptrt_arg2=$[2]
1220       recvfrom_ptrt_arg5=$[5]
1221       recvfrom_ptrt_arg6=$[6]
1222       #
1223       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG1, $[1],
1224         [Define to the type of arg 1 for recvfrom.])
1225       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG3, $[3],
1226         [Define to the type of arg 3 for recvfrom.])
1227       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG4, $[4],
1228         [Define to the type of arg 4 for recvfrom.])
1229       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_RETV, $[7],
1230         [Define to the function return type for recvfrom.])
1231       #
1232       prev_sh_opts=$-
1233       #
1234       case $prev_sh_opts in
1235         *f*)
1236           ;;
1237         *)
1238           set -f
1239           ;;
1240       esac
1241       #
1242       recvfrom_type_arg2=`echo $recvfrom_ptrt_arg2 | sed 's/ \*//'`
1243       recvfrom_type_arg5=`echo $recvfrom_ptrt_arg5 | sed 's/ \*//'`
1244       recvfrom_type_arg6=`echo $recvfrom_ptrt_arg6 | sed 's/ \*//'`
1245       #
1246       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG2, $recvfrom_type_arg2,
1247         [Define to the type pointed by arg 2 for recvfrom.])
1248       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG5, $recvfrom_type_arg5,
1249         [Define to the type pointed by arg 5 for recvfrom.])
1250       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG6, $recvfrom_type_arg6,
1251         [Define to the type pointed by arg 6 for recvfrom.])
1252       #
1253       if test "$recvfrom_type_arg2" = "void"; then
1254         AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG2_IS_VOID, 1,
1255           [Define to 1 if the type pointed by arg 2 for recvfrom is void.])
1256       fi
1257       if test "$recvfrom_type_arg5" = "void"; then
1258         AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG5_IS_VOID, 1,
1259           [Define to 1 if the type pointed by arg 5 for recvfrom is void.])
1260       fi
1261       if test "$recvfrom_type_arg6" = "void"; then
1262         AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG6_IS_VOID, 1,
1263           [Define to 1 if the type pointed by arg 6 for recvfrom is void.])
1264       fi
1265       #
1266       case $prev_sh_opts in
1267         *f*)
1268           ;;
1269         *)
1270           set +f
1271           ;;
1272       esac
1273       #
1274       AC_DEFINE_UNQUOTED(HAVE_RECVFROM, 1,
1275         [Define to 1 if you have the recvfrom function.])
1276       ac_cv_func_recvfrom="yes"
1277     fi
1278   else
1279     AC_MSG_WARN([Unable to link function recvfrom])
1280     AC_MSG_WARN([Your system will be vulnerable to some forms of DNS cache poisoning])
1281   fi
1282 ])
1283
1284
1285 dnl CURL_CHECK_MSG_NOSIGNAL
1286 dnl -------------------------------------------------
1287 dnl Check for MSG_NOSIGNAL
1288
1289 AC_DEFUN([CURL_CHECK_MSG_NOSIGNAL], [
1290   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
1291   AC_CACHE_CHECK([for MSG_NOSIGNAL], [ac_cv_msg_nosignal], [
1292     AC_COMPILE_IFELSE([
1293       AC_LANG_PROGRAM([[
1294 #undef inline 
1295 #ifdef HAVE_WINDOWS_H
1296 #ifndef WIN32_LEAN_AND_MEAN
1297 #define WIN32_LEAN_AND_MEAN
1298 #endif
1299 #include <windows.h>
1300 #ifdef HAVE_WINSOCK2_H
1301 #include <winsock2.h>
1302 #else
1303 #ifdef HAVE_WINSOCK_H
1304 #include <winsock.h>
1305 #endif
1306 #endif
1307 #else
1308 #ifdef HAVE_SYS_TYPES_H
1309 #include <sys/types.h>
1310 #endif
1311 #ifdef HAVE_SYS_SOCKET_H
1312 #include <sys/socket.h>
1313 #endif
1314 #endif
1315       ]],[[
1316         int flag=MSG_NOSIGNAL;
1317       ]])
1318     ],[
1319       ac_cv_msg_nosignal="yes"
1320     ],[
1321       ac_cv_msg_nosignal="no"
1322     ])
1323   ])
1324   case "$ac_cv_msg_nosignal" in
1325     yes)
1326       AC_DEFINE_UNQUOTED(HAVE_MSG_NOSIGNAL, 1,
1327         [Define to 1 if you have the MSG_NOSIGNAL flag.])
1328       ;;
1329   esac
1330 ])
1331
1332
1333 dnl CURL_CHECK_STRUCT_TIMEVAL
1334 dnl -------------------------------------------------
1335 dnl Check for timeval struct
1336
1337 AC_DEFUN([CURL_CHECK_STRUCT_TIMEVAL], [
1338   AC_REQUIRE([AC_HEADER_TIME])dnl
1339   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
1340   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
1341   AC_CHECK_HEADERS(sys/types.h sys/time.h time.h)
1342   AC_CACHE_CHECK([for struct timeval], [ac_cv_struct_timeval], [
1343     AC_COMPILE_IFELSE([
1344       AC_LANG_PROGRAM([[
1345 #undef inline 
1346 #ifdef HAVE_WINDOWS_H
1347 #ifndef WIN32_LEAN_AND_MEAN
1348 #define WIN32_LEAN_AND_MEAN
1349 #endif
1350 #include <windows.h>
1351 #ifdef HAVE_WINSOCK2_H
1352 #include <winsock2.h>
1353 #else
1354 #ifdef HAVE_WINSOCK_H
1355 #include <winsock.h>
1356 #endif
1357 #endif
1358 #endif
1359 #ifdef HAVE_SYS_TYPES_H
1360 #include <sys/types.h>
1361 #endif
1362 #ifdef HAVE_SYS_TIME_H
1363 #include <sys/time.h>
1364 #ifdef TIME_WITH_SYS_TIME
1365 #include <time.h>
1366 #endif
1367 #else
1368 #ifdef HAVE_TIME_H
1369 #include <time.h>
1370 #endif
1371 #endif
1372       ]],[[
1373         struct timeval ts;
1374         ts.tv_sec  = 0;
1375         ts.tv_usec = 0;
1376       ]])
1377     ],[
1378       ac_cv_struct_timeval="yes"
1379     ],[
1380       ac_cv_struct_timeval="no"
1381     ])
1382   ])
1383   case "$ac_cv_struct_timeval" in
1384     yes)
1385       AC_DEFINE_UNQUOTED(HAVE_STRUCT_TIMEVAL, 1,
1386         [Define to 1 if you have the timeval struct.])
1387       ;;
1388   esac
1389 ])
1390
1391
1392 dnl TYPE_SIG_ATOMIC_T
1393 dnl -------------------------------------------------
1394 dnl Check if the sig_atomic_t type is available, and
1395 dnl verify if it is already defined as volatile.
1396
1397 AC_DEFUN([TYPE_SIG_ATOMIC_T], [
1398   AC_CHECK_HEADERS(signal.h)
1399   AC_CHECK_TYPE([sig_atomic_t],[
1400     AC_DEFINE(HAVE_SIG_ATOMIC_T, 1,
1401       [Define to 1 if sig_atomic_t is an available typedef.])
1402   ], ,[
1403 #ifdef HAVE_SIGNAL_H
1404 #include <signal.h>
1405 #endif
1406   ])
1407   case "$ac_cv_type_sig_atomic_t" in
1408     yes)
1409       #
1410       AC_MSG_CHECKING([if sig_atomic_t is already defined as volatile])
1411       AC_LINK_IFELSE([
1412         AC_LANG_PROGRAM([[
1413 #ifdef HAVE_SIGNAL_H
1414 #include <signal.h>
1415 #endif
1416         ]],[[
1417           static volatile sig_atomic_t dummy = 0;
1418         ]])
1419       ],[
1420         AC_MSG_RESULT([no])
1421         ac_cv_sig_atomic_t_volatile="no"
1422       ],[
1423         AC_MSG_RESULT([yes])
1424         ac_cv_sig_atomic_t_volatile="yes"
1425       ])
1426       #
1427       if test "$ac_cv_sig_atomic_t_volatile" = "yes"; then
1428         AC_DEFINE(HAVE_SIG_ATOMIC_T_VOLATILE, 1,
1429           [Define to 1 if sig_atomic_t is already defined as volatile.])
1430       fi
1431       ;;
1432   esac
1433 ])
1434
1435
1436 dnl CURL_CHECK_NONBLOCKING_SOCKET
1437 dnl -------------------------------------------------
1438 dnl Check for how to set a socket to non-blocking state. There seems to exist
1439 dnl four known different ways, with the one used almost everywhere being POSIX
1440 dnl and XPG3, while the other different ways for different systems (old BSD,
1441 dnl Windows and Amiga).
1442 dnl
1443 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
1444 dnl O_NONBLOCK define is found but does not work. This condition is attempted
1445 dnl to get caught in this script by using an excessive number of #ifdefs...
1446
1447 AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET], [
1448   AC_MSG_CHECKING([non-blocking sockets style])
1449   nonblock="unknown"
1450   #
1451   AC_COMPILE_IFELSE([
1452     AC_LANG_PROGRAM([[
1453 /* headers for O_NONBLOCK test */
1454 #include <sys/types.h>
1455 #include <unistd.h>
1456 #include <fcntl.h>
1457 /* */
1458 #if defined(sun) || defined(__sun__) || \
1459     defined(__SUNPRO_C) || defined(__SUNPRO_CC)
1460 # if defined(__SVR4) || defined(__srv4__)
1461 #  define PLATFORM_SOLARIS
1462 # else
1463 #  define PLATFORM_SUNOS4
1464 # endif
1465 #endif
1466 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41)
1467 # define PLATFORM_AIX_V3
1468 #endif
1469 /* */
1470 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
1471 #error "O_NONBLOCK does not work on this platform"
1472 #endif
1473     ]],[[
1474       /* O_NONBLOCK source test */
1475       int socket;
1476       int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
1477     ]])
1478   ],[
1479     dnl the O_NONBLOCK test was fine
1480     nonblock="O_NONBLOCK"
1481     AC_DEFINE(HAVE_O_NONBLOCK, 1,
1482       [use O_NONBLOCK for non-blocking sockets])
1483   ])
1484   #
1485   if test "$nonblock" = "unknown"; then
1486     AC_COMPILE_IFELSE([
1487       AC_LANG_PROGRAM([[
1488 /* headers for FIONBIO test */
1489 #include <unistd.h>
1490 #include <stropts.h>
1491       ]],[[
1492         /* FIONBIO source test (old-style unix) */
1493         int socket;
1494         int flags = ioctl(socket, FIONBIO, &flags);
1495       ]])
1496     ],[
1497       dnl FIONBIO test was good
1498       nonblock="FIONBIO"
1499       AC_DEFINE(HAVE_FIONBIO, 1,
1500         [use FIONBIO for non-blocking sockets])
1501     ])
1502   fi
1503   #
1504   if test "$nonblock" = "unknown"; then
1505     AC_COMPILE_IFELSE([
1506       AC_LANG_PROGRAM([[
1507 /* headers for ioctlsocket test (Windows) */
1508 #undef inline
1509 #ifdef HAVE_WINDOWS_H
1510 #ifndef WIN32_LEAN_AND_MEAN
1511 #define WIN32_LEAN_AND_MEAN
1512 #endif
1513 #include <windows.h>
1514 #ifdef HAVE_WINSOCK2_H
1515 #include <winsock2.h>
1516 #else
1517 #ifdef HAVE_WINSOCK_H
1518 #include <winsock.h>
1519 #endif
1520 #endif
1521 #endif
1522       ]],[[
1523         /* ioctlsocket source code (Windows) */
1524         SOCKET sd;
1525         unsigned long flags = 0;
1526         sd = socket(0, 0, 0);
1527         ioctlsocket(sd, FIONBIO, &flags);
1528       ]])
1529     ],[
1530       dnl ioctlsocket test was good
1531       nonblock="ioctlsocket"
1532       AC_DEFINE(HAVE_IOCTLSOCKET, 1,
1533         [use ioctlsocket() for non-blocking sockets])
1534     ])
1535   fi
1536   #
1537   if test "$nonblock" = "unknown"; then
1538     AC_LINK_IFELSE([
1539       AC_LANG_PROGRAM([[
1540 /* headers for IoctlSocket test (Amiga?) */
1541 #include <sys/ioctl.h>
1542       ]],[[
1543         /* IoctlSocket source code (Amiga?) */
1544         int socket;
1545         int flags = IoctlSocket(socket, FIONBIO, (long)1);
1546       ]])
1547     ],[
1548       dnl Ioctlsocket test was good
1549       nonblock="IoctlSocket"
1550       AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1,
1551         [use Ioctlsocket() for non-blocking sockets])
1552     ])
1553   fi
1554   #
1555   if test "$nonblock" = "unknown"; then
1556     AC_COMPILE_IFELSE([
1557       AC_LANG_PROGRAM([[
1558 /* headers for SO_NONBLOCK test (BeOS) */
1559 #include <socket.h>
1560       ]],[[
1561         /* SO_NONBLOCK source code (BeOS) */
1562         long b = 1;
1563         int socket;
1564         int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
1565       ]])
1566     ],[
1567       dnl the SO_NONBLOCK test was good
1568       nonblock="SO_NONBLOCK"
1569       AC_DEFINE(HAVE_SO_NONBLOCK, 1,
1570         [use SO_NONBLOCK for non-blocking sockets])
1571     ])
1572   fi
1573   #
1574   AC_MSG_RESULT($nonblock)
1575   #
1576   if test "$nonblock" = "unknown"; then
1577     AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1,
1578       [disabled non-blocking sockets])
1579     AC_MSG_WARN([non-block sockets disabled])
1580   fi
1581 ])
1582
1583
1584 dnl TYPE_IN_ADDR_T
1585 dnl -------------------------------------------------
1586 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
1587 dnl and a few other things.
1588
1589 AC_DEFUN([TYPE_IN_ADDR_T], [
1590   AC_CHECK_TYPE([in_addr_t], ,[
1591     dnl in_addr_t not available
1592     AC_CACHE_CHECK([for in_addr_t equivalent],
1593       [curl_cv_in_addr_t_equiv], [
1594       curl_cv_in_addr_t_equiv="unknown"
1595       for t in "unsigned long" int size_t unsigned long; do
1596         if test "$curl_cv_in_addr_t_equiv" = "unknown"; then
1597           AC_LINK_IFELSE([
1598             AC_LANG_PROGRAM([[
1599 #undef inline
1600 #ifdef HAVE_WINDOWS_H
1601 #ifndef WIN32_LEAN_AND_MEAN
1602 #define WIN32_LEAN_AND_MEAN
1603 #endif
1604 #include <windows.h>
1605 #ifdef HAVE_WINSOCK2_H
1606 #include <winsock2.h>
1607 #else
1608 #ifdef HAVE_WINSOCK_H
1609 #include <winsock.h>
1610 #endif
1611 #endif
1612 #else
1613 #ifdef HAVE_SYS_TYPES_H
1614 #include <sys/types.h>
1615 #endif
1616 #ifdef HAVE_SYS_SOCKET_H
1617 #include <sys/socket.h>
1618 #endif
1619 #ifdef HAVE_NETINET_IN_H
1620 #include <netinet/in.h>
1621 #endif
1622 #ifdef HAVE_ARPA_INET_H
1623 #include <arpa/inet.h>
1624 #endif
1625 #endif
1626             ]],[[
1627               $t data = inet_addr ("1.2.3.4");
1628             ]])
1629           ],[
1630             curl_cv_in_addr_t_equiv="$t"
1631           ])
1632         fi
1633       done
1634     ])
1635     case "$curl_cv_in_addr_t_equiv" in
1636       unknown)
1637         AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
1638         ;;
1639       *)
1640         AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
1641           [Type to use in place of in_addr_t when system does not provide it.])
1642         ;;
1643     esac
1644   ],[
1645 #undef inline
1646 #ifdef HAVE_WINDOWS_H
1647 #ifndef WIN32_LEAN_AND_MEAN
1648 #define WIN32_LEAN_AND_MEAN
1649 #endif
1650 #include <windows.h>
1651 #ifdef HAVE_WINSOCK2_H
1652 #include <winsock2.h>
1653 #else
1654 #ifdef HAVE_WINSOCK_H
1655 #include <winsock.h>
1656 #endif
1657 #endif
1658 #else
1659 #ifdef HAVE_SYS_TYPES_H
1660 #include <sys/types.h>
1661 #endif
1662 #ifdef HAVE_SYS_SOCKET_H
1663 #include <sys/socket.h>
1664 #endif
1665 #ifdef HAVE_NETINET_IN_H
1666 #include <netinet/in.h>
1667 #endif
1668 #ifdef HAVE_ARPA_INET_H
1669 #include <arpa/inet.h>
1670 #endif
1671 #endif
1672   ])
1673 ])
1674
1675
1676 dnl CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC
1677 dnl -------------------------------------------------
1678 dnl Check if monotonic clock_gettime is available.
1679
1680 AC_DEFUN([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC], [
1681   AC_REQUIRE([AC_HEADER_TIME])dnl
1682   AC_CHECK_HEADERS(sys/types.h sys/time.h time.h)
1683   AC_MSG_CHECKING([for monotonic clock_gettime])
1684   AC_COMPILE_IFELSE([
1685     AC_LANG_PROGRAM([[
1686 #ifdef HAVE_SYS_TYPES_H
1687 #include <sys/types.h>
1688 #endif
1689 #ifdef HAVE_SYS_TIME_H
1690 #include <sys/time.h>
1691 #ifdef TIME_WITH_SYS_TIME
1692 #include <time.h>
1693 #endif
1694 #else
1695 #ifdef HAVE_TIME_H
1696 #include <time.h>
1697 #endif
1698 #endif
1699     ]],[[
1700       struct timespec ts;
1701       (void)clock_gettime(CLOCK_MONOTONIC, &ts);
1702     ]])
1703   ],[
1704     AC_MSG_RESULT([yes])
1705     ac_cv_func_clock_gettime="yes"
1706   ],[
1707     AC_MSG_RESULT([no])
1708     ac_cv_func_clock_gettime="no"
1709   ])
1710   dnl Definition of HAVE_CLOCK_GETTIME_MONOTONIC is intentionally postponed
1711   dnl until library linking and run-time checks for clock_gettime succeed.
1712 ])
1713
1714
1715 dnl CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC
1716 dnl -------------------------------------------------
1717 dnl If monotonic clock_gettime is available then,
1718 dnl check and prepended to LIBS any needed libraries.
1719
1720 AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC], [
1721   AC_REQUIRE([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC])dnl
1722   #
1723   if test "$ac_cv_func_clock_gettime" = "yes"; then
1724     #
1725     AC_MSG_CHECKING([for clock_gettime in libraries])
1726     #
1727     curl_cv_save_LIBS="$LIBS"
1728     curl_cv_gclk_LIBS="unknown"
1729     #
1730     for x_xlibs in '' '-lrt' '-lposix4' ; do
1731       if test "$curl_cv_gclk_LIBS" = "unknown"; then
1732         if test -z "$x_xlibs"; then
1733           LIBS="$curl_cv_save_LIBS"
1734         else
1735           LIBS="$x_xlibs $curl_cv_save_LIBS"
1736         fi
1737         AC_LINK_IFELSE([
1738           AC_LANG_PROGRAM([[
1739 #ifdef HAVE_SYS_TYPES_H
1740 #include <sys/types.h>
1741 #endif
1742 #ifdef HAVE_SYS_TIME_H
1743 #include <sys/time.h>
1744 #ifdef TIME_WITH_SYS_TIME
1745 #include <time.h>
1746 #endif
1747 #else
1748 #ifdef HAVE_TIME_H
1749 #include <time.h>
1750 #endif
1751 #endif
1752           ]],[[
1753             struct timespec ts;
1754             (void)clock_gettime(CLOCK_MONOTONIC, &ts);
1755           ]])
1756         ],[
1757           curl_cv_gclk_LIBS="$x_xlibs"
1758         ])
1759       fi
1760     done
1761     #
1762     LIBS="$curl_cv_save_LIBS"
1763     #
1764     case X-"$curl_cv_gclk_LIBS" in
1765       X-unknown)
1766         AC_MSG_RESULT([cannot find clock_gettime])
1767         AC_MSG_WARN([HAVE_CLOCK_GETTIME_MONOTONIC will not be defined])
1768         ac_cv_func_clock_gettime="no"
1769         ;;
1770       X-)
1771         AC_MSG_RESULT([no additional lib required])
1772         ac_cv_func_clock_gettime="yes"
1773         ;;
1774       *)
1775         if test -z "$curl_cv_save_LIBS"; then
1776           LIBS="$curl_cv_gclk_LIBS"
1777         else
1778           LIBS="$curl_cv_gclk_LIBS $curl_cv_save_LIBS"
1779         fi
1780         AC_MSG_RESULT([$curl_cv_gclk_LIBS])
1781         ac_cv_func_clock_gettime="yes"
1782         ;;
1783     esac
1784     #
1785     dnl only do runtime verification when not cross-compiling
1786     if test "x$cross_compiling" != "xyes" &&
1787       test "$ac_cv_func_clock_gettime" = "yes"; then
1788       AC_MSG_CHECKING([if monotonic clock_gettime works])
1789       AC_RUN_IFELSE([
1790         AC_LANG_PROGRAM([[
1791 #ifdef HAVE_STDLIB_H
1792 #include <stdlib.h>
1793 #endif
1794 #ifdef HAVE_SYS_TYPES_H
1795 #include <sys/types.h>
1796 #endif
1797 #ifdef HAVE_SYS_TIME_H
1798 #include <sys/time.h>
1799 #ifdef TIME_WITH_SYS_TIME
1800 #include <time.h>
1801 #endif
1802 #else
1803 #ifdef HAVE_TIME_H
1804 #include <time.h>
1805 #endif
1806 #endif
1807         ]],[[
1808           struct timespec ts;
1809           if (0 == clock_gettime(CLOCK_MONOTONIC, &ts))
1810             exit(0);
1811           else
1812             exit(1);
1813         ]])
1814       ],[
1815         AC_MSG_RESULT([yes])
1816       ],[
1817         AC_MSG_RESULT([no])
1818         AC_MSG_WARN([HAVE_CLOCK_GETTIME_MONOTONIC will not be defined])
1819         ac_cv_func_clock_gettime="no"
1820         LIBS="$curl_cv_save_LIBS"
1821       ])
1822     fi
1823     #
1824     case "$ac_cv_func_clock_gettime" in
1825       yes)
1826         AC_DEFINE_UNQUOTED(HAVE_CLOCK_GETTIME_MONOTONIC, 1,
1827           [Define to 1 if you have the clock_gettime function and monotonic timer.])
1828         ;;
1829     esac
1830     #
1831   fi
1832   #
1833 ])
1834
1835
1836 dnl This macro determines if the specified struct exists in the specified file
1837 dnl Syntax:
1838 dnl CARES_CHECK_STRUCT(headers, struct name, if found, [if not found])
1839
1840 AC_DEFUN([CARES_CHECK_STRUCT], [
1841   AC_MSG_CHECKING([for struct $2])
1842   AC_TRY_COMPILE([$1], 
1843     [
1844       struct $2 struct_instance;
1845     ], ac_struct="yes", ac_found="no")
1846   if test "$ac_struct" = "yes" ; then
1847     AC_MSG_RESULT(yes)
1848     $3
1849   else
1850     AC_MSG_RESULT(no)
1851     $4
1852   fi
1853 ])
1854
1855 dnl This macro determines if the specified constant exists in the specified file
1856 dnl Syntax:
1857 dnl CARES_CHECK_CONSTANT(headers, constant name, if found, [if not found])
1858
1859 AC_DEFUN([CARES_CHECK_CONSTANT], [
1860   AC_MSG_CHECKING([for $2])
1861   AC_EGREP_CPP(VARIABLEWASDEFINED,
1862    [
1863       $1
1864
1865       #ifdef $2
1866         VARIABLEWASDEFINED
1867       #else
1868         NJET
1869       #endif
1870     ], ac_constant="yes", ac_constant="no"
1871   )
1872   if test "$ac_constant" = "yes" ; then
1873     AC_MSG_RESULT(yes)
1874     $3
1875   else
1876     AC_MSG_RESULT(no)
1877     $4
1878   fi
1879 ])
1880