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