Initial step towards a configure time ares_socklen_t definition
[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_HEADER_MEMORY
364 dnl -------------------------------------------------
365 dnl Check for compilable and valid memory.h header,
366 dnl and check if it is needed even with stdlib.h for
367 dnl memory related functions.
368
369 AC_DEFUN([CURL_CHECK_HEADER_MEMORY], [
370   AC_CACHE_CHECK([for memory.h], [ac_cv_header_memory_h], [
371     AC_COMPILE_IFELSE([
372       AC_LANG_PROGRAM([[
373 #include <memory.h>
374       ]],[[
375         void *p = malloc(10);
376         void *q = calloc(10,10);
377         free(p);
378         free(q);
379       ]])
380     ],[
381       ac_cv_header_memory_h="yes"
382     ],[
383       ac_cv_header_memory_h="no"
384     ])
385   ])
386   if test "$ac_cv_header_memory_h" = "yes"; then
387     AC_DEFINE_UNQUOTED(HAVE_MEMORY_H, 1,
388       [Define to 1 if you have the memory.h header file.])
389     #
390     AC_COMPILE_IFELSE([
391       AC_LANG_PROGRAM([[
392 #include <stdlib.h>
393       ]],[[
394         void *p = malloc(10);
395         void *q = calloc(10,10);
396         free(p);
397         free(q);
398       ]])
399     ],[
400       curl_cv_need_header_memory_h="no"
401     ],[
402       curl_cv_need_header_memory_h="yes"
403     ])
404     #
405     case "$curl_cv_need_header_memory_h" in
406       yes)
407         AC_DEFINE_UNQUOTED(NEED_MEMORY_H, 1,
408           [Define to 1 if you need the memory.h header file even with stdlib.h])
409         ;;
410     esac
411   fi
412 ])
413
414
415 dnl CURL_CHECK_TYPE_SOCKLEN_T
416 dnl -------------------------------------------------
417 dnl Check for existing socklen_t type, and provide
418 dnl an equivalent type if socklen_t not available
419
420 AC_DEFUN([CURL_CHECK_TYPE_SOCKLEN_T], [
421   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
422   AC_CHECK_TYPE([socklen_t], ,[
423     dnl socklen_t not available
424     AC_CACHE_CHECK([for socklen_t equivalent],
425       [curl_cv_socklen_t_equiv], [
426       curl_cv_socklen_t_equiv="unknown"
427       for arg1 in 'int' 'SOCKET'; do
428         for arg2 in "struct sockaddr" void; do
429           for t in int size_t unsigned long "unsigned long"; do
430             if test "$curl_cv_socklen_t_equiv" = "unknown"; then
431               AC_COMPILE_IFELSE([
432                 AC_LANG_PROGRAM([[
433 #undef inline
434 #ifdef HAVE_WINDOWS_H
435 #ifndef WIN32_LEAN_AND_MEAN
436 #define WIN32_LEAN_AND_MEAN
437 #endif
438 #include <windows.h>
439 #ifdef HAVE_WINSOCK2_H
440 #include <winsock2.h>
441 #else
442 #ifdef HAVE_WINSOCK_H
443 #include <winsock.h>
444 #endif
445 #endif
446 #define GETPEERNCALLCONV PASCAL
447 #else
448 #ifdef HAVE_SYS_TYPES_H
449 #include <sys/types.h>
450 #endif
451 #ifdef HAVE_SYS_SOCKET_H
452 #include <sys/socket.h>
453 #endif
454 #define GETPEERNCALLCONV
455 #endif
456                   extern int GETPEERNCALLCONV getpeername($arg1, $arg2 *, $t *);
457                 ]],[[
458                   $t len=0;
459                   getpeername(0,0,&len);
460                 ]])
461               ],[
462                 curl_cv_socklen_t_equiv="$t"
463               ])
464             fi
465           done
466         done
467       done
468     ])
469     case "$curl_cv_socklen_t_equiv" in
470       unknown)
471         AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
472         ;;
473       *)
474         AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
475           [Type to use in place of socklen_t when system does not provide it.])
476         ;;
477     esac
478   ],[
479 #undef inline
480 #ifdef HAVE_WINDOWS_H
481 #ifndef WIN32_LEAN_AND_MEAN
482 #define WIN32_LEAN_AND_MEAN
483 #endif
484 #include <windows.h>
485 #ifdef HAVE_WINSOCK2_H
486 #include <winsock2.h>
487 #ifdef HAVE_WS2TCPIP_H
488 #include <ws2tcpip.h>
489 #endif
490 #endif
491 #else
492 #ifdef HAVE_SYS_TYPES_H
493 #include <sys/types.h>
494 #endif
495 #ifdef HAVE_SYS_SOCKET_H
496 #include <sys/socket.h>
497 #endif
498 #endif
499   ])
500 ])
501
502
503 dnl CURL_CHECK_FUNC_GETNAMEINFO
504 dnl -------------------------------------------------
505 dnl Test if the getnameinfo function is available, 
506 dnl and check the types of five of its arguments.
507 dnl If the function succeeds HAVE_GETNAMEINFO will be
508 dnl defined, defining the types of the arguments in
509 dnl GETNAMEINFO_TYPE_ARG1, GETNAMEINFO_TYPE_ARG2,
510 dnl GETNAMEINFO_TYPE_ARG46 and GETNAMEINFO_TYPE_ARG7,
511 dnl and also defining the type qualifier of first 
512 dnl argument in GETNAMEINFO_QUAL_ARG1.
513
514 AC_DEFUN([CURL_CHECK_FUNC_GETNAMEINFO], [
515   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
516   AC_REQUIRE([CURL_CHECK_TYPE_SOCKLEN_T])dnl
517   AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h)
518   #
519   AC_MSG_CHECKING([for getnameinfo])
520   AC_LINK_IFELSE([
521     AC_LANG_FUNC_LINK_TRY([getnameinfo])
522   ],[
523     AC_MSG_RESULT([yes])
524     curl_cv_getnameinfo="yes"
525   ],[
526     AC_MSG_RESULT([no])
527     curl_cv_getnameinfo="no"
528   ])
529   #
530   if test "$curl_cv_getnameinfo" != "yes"; then
531     AC_MSG_CHECKING([deeper for getnameinfo])
532     AC_LINK_IFELSE([
533       AC_LANG_PROGRAM([[
534       ]],[[
535         getnameinfo();
536       ]])
537     ],[
538       AC_MSG_RESULT([yes])
539       curl_cv_getnameinfo="yes"
540     ],[
541       AC_MSG_RESULT([but still no])
542       curl_cv_getnameinfo="no"
543     ])
544   fi
545   #
546   if test "$curl_cv_getnameinfo" != "yes"; then
547     AC_MSG_CHECKING([deeper and deeper for getnameinfo])
548     AC_LINK_IFELSE([
549       AC_LANG_PROGRAM([[
550 #undef inline
551 #ifdef HAVE_WINDOWS_H
552 #ifndef WIN32_LEAN_AND_MEAN
553 #define WIN32_LEAN_AND_MEAN
554 #endif
555 #include <windows.h>
556 #ifdef HAVE_WINSOCK2_H
557 #include <winsock2.h>
558 #ifdef HAVE_WS2TCPIP_H
559 #include <ws2tcpip.h>
560 #endif
561 #endif
562 #else
563 #ifdef HAVE_SYS_TYPES_H
564 #include <sys/types.h>
565 #endif
566 #ifdef HAVE_SYS_SOCKET_H
567 #include <sys/socket.h>
568 #endif
569 #ifdef HAVE_NETDB_H
570 #include <netdb.h>
571 #endif
572 #endif
573       ]],[[
574         getnameinfo(0, 0, 0, 0, 0, 0, 0);
575       ]])
576     ],[
577       AC_MSG_RESULT([yes])
578       curl_cv_getnameinfo="yes"
579     ],[
580       AC_MSG_RESULT([but still no])
581       curl_cv_getnameinfo="no"
582     ])
583   fi
584   #
585   if test "$curl_cv_getnameinfo" = "yes"; then
586     AC_CACHE_CHECK([types of arguments for getnameinfo],
587       [curl_cv_func_getnameinfo_args], [
588       curl_cv_func_getnameinfo_args="unknown"
589       for gni_arg1 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
590         for gni_arg2 in 'socklen_t' 'size_t' 'int'; do
591           for gni_arg46 in 'size_t' 'int' 'socklen_t' 'unsigned int' 'DWORD'; do
592             for gni_arg7 in 'int' 'unsigned int'; do
593               if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
594                 AC_COMPILE_IFELSE([
595                   AC_LANG_PROGRAM([[
596 #undef inline 
597 #ifdef HAVE_WINDOWS_H
598 #ifndef WIN32_LEAN_AND_MEAN
599 #define WIN32_LEAN_AND_MEAN
600 #endif
601 #if (!defined(_WIN32_WINNT)) || (_WIN32_WINNT < 0x0501)
602 #undef _WIN32_WINNT
603 #define _WIN32_WINNT 0x0501
604 #endif
605 #include <windows.h>
606 #ifdef HAVE_WINSOCK2_H
607 #include <winsock2.h> 
608 #ifdef HAVE_WS2TCPIP_H
609 #include <ws2tcpip.h>
610 #endif
611 #endif
612 #define GNICALLCONV WSAAPI
613 #else
614 #ifdef HAVE_SYS_TYPES_H
615 #include <sys/types.h>
616 #endif
617 #ifdef HAVE_SYS_SOCKET_H
618 #include <sys/socket.h>
619 #endif
620 #ifdef HAVE_NETDB_H
621 #include <netdb.h>
622 #endif
623 #define GNICALLCONV
624 #endif
625                     extern int GNICALLCONV getnameinfo($gni_arg1, $gni_arg2,
626                                            char *, $gni_arg46,
627                                            char *, $gni_arg46,
628                                            $gni_arg7);
629                   ]],[[
630                     $gni_arg2 salen=0;
631                     $gni_arg46 hostlen=0;
632                     $gni_arg46 servlen=0;
633                     $gni_arg7 flags=0;
634                     int res = getnameinfo(0, salen, 0, hostlen, 0, servlen, flags);
635                   ]])
636                 ],[
637                   curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7"
638                 ])
639               fi
640             done
641           done
642         done
643       done
644     ]) # AC-CACHE-CHECK
645     if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
646       AC_MSG_WARN([Cannot find proper types to use for getnameinfo args])
647       AC_MSG_WARN([HAVE_GETNAMEINFO will not be defined])
648     else
649       gni_prev_IFS=$IFS; IFS=','
650       set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'`
651       IFS=$gni_prev_IFS
652       shift
653       #
654       gni_qual_type_arg1=$[1]
655       #
656       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2],
657         [Define to the type of arg 2 for getnameinfo.])
658       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3],
659         [Define to the type of args 4 and 6 for getnameinfo.])
660       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4],
661         [Define to the type of arg 7 for getnameinfo.])
662       #
663       prev_sh_opts=$-
664       #
665       case $prev_sh_opts in
666         *f*)
667           ;;
668         *)
669           set -f
670           ;;
671       esac
672       #
673       case "$gni_qual_type_arg1" in
674         const*)
675           gni_qual_arg1=const
676           gni_type_arg1=`echo $gni_qual_type_arg1 | sed 's/^const //'`
677         ;;
678         *)
679           gni_qual_arg1=
680           gni_type_arg1=$gni_qual_type_arg1
681         ;;
682       esac
683       #
684       AC_DEFINE_UNQUOTED(GETNAMEINFO_QUAL_ARG1, $gni_qual_arg1,
685         [Define to the type qualifier of arg 1 for getnameinfo.])
686       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $gni_type_arg1,
687         [Define to the type of arg 1 for getnameinfo.])
688       #
689       case $prev_sh_opts in
690         *f*)
691           ;;
692         *)
693           set +f
694           ;;
695       esac
696       #
697       AC_DEFINE_UNQUOTED(HAVE_GETNAMEINFO, 1,
698         [Define to 1 if you have the getnameinfo function.])
699       ac_cv_func_getnameinfo="yes"
700     fi
701   fi
702 ])
703
704
705 dnl TYPE_SOCKADDR_STORAGE
706 dnl -------------------------------------------------
707 dnl Check for struct sockaddr_storage. Most IPv6-enabled 
708 dnl hosts have it, but AIX 4.3 is one known exception.
709
710 AC_DEFUN([TYPE_SOCKADDR_STORAGE],
711 [
712    AC_CHECK_TYPE([struct sockaddr_storage],
713         AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
714                   [if struct sockaddr_storage is defined]), ,
715    [
716 #undef inline
717 #ifdef HAVE_WINDOWS_H
718 #ifndef WIN32_LEAN_AND_MEAN
719 #define WIN32_LEAN_AND_MEAN
720 #endif
721 #include <windows.h>
722 #ifdef HAVE_WINSOCK2_H
723 #include <winsock2.h>
724 #endif
725 #else
726 #ifdef HAVE_SYS_TYPES_H
727 #include <sys/types.h>
728 #endif
729 #ifdef HAVE_SYS_SOCKET_H
730 #include <sys/socket.h>
731 #endif
732 #ifdef HAVE_NETINET_IN_H
733 #include <netinet/in.h>
734 #endif
735 #ifdef HAVE_ARPA_INET_H
736 #include <arpa/inet.h>
737 #endif
738 #endif
739    ])
740 ])
741
742
743 dnl CURL_CHECK_NI_WITHSCOPEID
744 dnl -------------------------------------------------
745 dnl Check for working NI_WITHSCOPEID in getnameinfo()
746
747 AC_DEFUN([CURL_CHECK_NI_WITHSCOPEID], [
748   AC_REQUIRE([CURL_CHECK_FUNC_GETNAMEINFO])dnl
749   AC_REQUIRE([TYPE_SOCKADDR_STORAGE])dnl
750   AC_CHECK_HEADERS(stdio.h sys/types.h sys/socket.h \
751                    netdb.h netinet/in.h arpa/inet.h)
752   #
753   AC_CACHE_CHECK([for working NI_WITHSCOPEID], 
754     [ac_cv_working_ni_withscopeid], [
755     AC_RUN_IFELSE([
756       AC_LANG_PROGRAM([[
757 #ifdef HAVE_STDLIB_H
758 #include <stdlib.h>
759 #endif
760 #ifdef HAVE_STDIO_H
761 #include <stdio.h>
762 #endif
763 #ifdef HAVE_SYS_TYPES_H
764 #include <sys/types.h>
765 #endif
766 #ifdef HAVE_SYS_SOCKET_H
767 #include <sys/socket.h>
768 #endif
769 #ifdef HAVE_NETDB_H
770 #include <netdb.h>
771 #endif
772 #ifdef HAVE_NETINET_IN_H
773 #include <netinet/in.h>
774 #endif
775 #ifdef HAVE_ARPA_INET_H
776 #include <arpa/inet.h>
777 #endif
778       ]],[[
779 #if defined(NI_WITHSCOPEID) && defined(HAVE_GETNAMEINFO)
780 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE
781         struct sockaddr_storage sa;
782 #else
783         unsigned char sa[256];
784 #endif
785         char hostbuf[NI_MAXHOST];
786         int rc;
787         GETNAMEINFO_TYPE_ARG2 salen = (GETNAMEINFO_TYPE_ARG2)sizeof(sa);
788         GETNAMEINFO_TYPE_ARG46 hostlen = (GETNAMEINFO_TYPE_ARG46)sizeof(hostbuf);
789         GETNAMEINFO_TYPE_ARG7 flags = NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
790         int fd = socket(AF_INET6, SOCK_STREAM, 0);
791         if(fd < 0) {
792           perror("socket()");
793           return 1; /* Error creating socket */
794         }
795         rc = getsockname(fd, (GETNAMEINFO_TYPE_ARG1)&sa, &salen);
796         if(rc) {
797           perror("getsockname()");
798           return 2; /* Error retrieving socket name */
799         }
800         rc = getnameinfo((GETNAMEINFO_TYPE_ARG1)&sa, salen, hostbuf, hostlen, NULL, 0, flags);
801         if(rc) {
802           printf("rc = %s\n", gai_strerror(rc));
803           return 3; /* Error translating socket address */
804         }
805         return 0; /* Ok, NI_WITHSCOPEID works */
806 #else
807         return 4; /* Error, NI_WITHSCOPEID not defined or no getnameinfo() */
808 #endif
809       ]]) # AC-LANG-PROGRAM
810     ],[
811       # Exit code == 0. Program worked.
812       ac_cv_working_ni_withscopeid="yes"
813     ],[
814       # Exit code != 0. Program failed.
815       ac_cv_working_ni_withscopeid="no"
816     ],[
817       # Program is not run when cross-compiling. So we assume
818       # NI_WITHSCOPEID will work if we are able to compile it.
819       AC_COMPILE_IFELSE([
820         AC_LANG_PROGRAM([[
821 #include <sys/types.h>
822 #include <sys/socket.h>
823 #include <netdb.h>
824         ]],[[
825           unsigned int dummy= NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
826         ]])
827       ],[
828         ac_cv_working_ni_withscopeid="yes"
829       ],[
830         ac_cv_working_ni_withscopeid="no"
831       ]) # AC-COMPILE-IFELSE
832     ]) # AC-RUN-IFELSE
833   ]) # AC-CACHE-CHECK
834   case "$ac_cv_working_ni_withscopeid" in
835     yes)
836       AC_DEFINE(HAVE_NI_WITHSCOPEID, 1,
837         [Define to 1 if NI_WITHSCOPEID exists and works.])
838       ;;
839   esac
840 ])
841
842
843 dnl CURL_CHECK_FUNC_RECV
844 dnl -------------------------------------------------
845 dnl Test if the socket recv() function is available, 
846 dnl and check its return type and the types of its 
847 dnl arguments. If the function succeeds HAVE_RECV 
848 dnl will be defined, defining the types of the arguments 
849 dnl in RECV_TYPE_ARG1, RECV_TYPE_ARG2, RECV_TYPE_ARG3 
850 dnl and RECV_TYPE_ARG4, defining the type of the function
851 dnl return value in RECV_TYPE_RETV.
852
853 AC_DEFUN([CURL_CHECK_FUNC_RECV], [
854   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
855   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
856   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
857   #
858   AC_MSG_CHECKING([for recv])
859   AC_LINK_IFELSE([
860     AC_LANG_PROGRAM([[
861 #undef inline 
862 #ifdef HAVE_WINDOWS_H
863 #ifndef WIN32_LEAN_AND_MEAN
864 #define WIN32_LEAN_AND_MEAN
865 #endif
866 #include <windows.h>
867 #ifdef HAVE_WINSOCK2_H
868 #include <winsock2.h>
869 #else
870 #ifdef HAVE_WINSOCK_H
871 #include <winsock.h>
872 #endif
873 #endif
874 #else
875 #ifdef HAVE_SYS_TYPES_H
876 #include <sys/types.h>
877 #endif
878 #ifdef HAVE_SYS_SOCKET_H
879 #include <sys/socket.h>
880 #endif
881 #endif
882     ]],[[
883       recv(0, 0, 0, 0);
884     ]])
885   ],[
886     AC_MSG_RESULT([yes])
887     curl_cv_recv="yes"
888   ],[
889     AC_MSG_RESULT([no])
890     curl_cv_recv="no"
891   ])
892   #
893   if test "$curl_cv_recv" = "yes"; then
894     AC_CACHE_CHECK([types of args and return type for recv],
895       [curl_cv_func_recv_args], [
896       curl_cv_func_recv_args="unknown"
897       for recv_retv in 'int' 'ssize_t'; do
898         for recv_arg1 in 'int' 'ssize_t' 'SOCKET'; do
899           for recv_arg2 in 'char *' 'void *'; do
900             for recv_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
901               for recv_arg4 in 'int' 'unsigned int'; do
902                 if test "$curl_cv_func_recv_args" = "unknown"; then
903                   AC_COMPILE_IFELSE([
904                     AC_LANG_PROGRAM([[
905 #undef inline 
906 #ifdef HAVE_WINDOWS_H
907 #ifndef WIN32_LEAN_AND_MEAN
908 #define WIN32_LEAN_AND_MEAN
909 #endif
910 #include <windows.h>
911 #ifdef HAVE_WINSOCK2_H
912 #include <winsock2.h>
913 #else
914 #ifdef HAVE_WINSOCK_H
915 #include <winsock.h>
916 #endif
917 #endif
918 #define RECVCALLCONV PASCAL
919 #else
920 #ifdef HAVE_SYS_TYPES_H
921 #include <sys/types.h>
922 #endif
923 #ifdef HAVE_SYS_SOCKET_H
924 #include <sys/socket.h>
925 #endif
926 #define RECVCALLCONV
927 #endif
928                       extern $recv_retv RECVCALLCONV
929                       recv($recv_arg1, $recv_arg2, $recv_arg3, $recv_arg4);
930                     ]],[[
931                       $recv_arg1 s=0;
932                       $recv_arg2 buf=0;
933                       $recv_arg3 len=0;
934                       $recv_arg4 flags=0;
935                       $recv_retv res = recv(s, buf, len, flags);
936                     ]])
937                   ],[
938                     curl_cv_func_recv_args="$recv_arg1,$recv_arg2,$recv_arg3,$recv_arg4,$recv_retv"
939                   ])
940                 fi
941               done
942             done
943           done
944         done
945       done
946     ]) # AC-CACHE-CHECK
947     if test "$curl_cv_func_recv_args" = "unknown"; then
948       AC_MSG_ERROR([Cannot find proper types to use for recv args])
949     else
950       recv_prev_IFS=$IFS; IFS=','
951       set dummy `echo "$curl_cv_func_recv_args" | sed 's/\*/\*/g'`
952       IFS=$recv_prev_IFS
953       shift
954       #
955       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG1, $[1],
956         [Define to the type of arg 1 for recv.])
957       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG2, $[2],
958         [Define to the type of arg 2 for recv.])
959       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG3, $[3],
960         [Define to the type of arg 3 for recv.])
961       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG4, $[4],
962         [Define to the type of arg 4 for recv.])
963       AC_DEFINE_UNQUOTED(RECV_TYPE_RETV, $[5],
964         [Define to the function return type for recv.])
965       #
966       AC_DEFINE_UNQUOTED(HAVE_RECV, 1,
967         [Define to 1 if you have the recv function.])
968       ac_cv_func_recv="yes"
969     fi
970   else
971     AC_MSG_ERROR([Unable to link function recv])
972   fi
973 ])
974
975
976 dnl CURL_CHECK_FUNC_SEND
977 dnl -------------------------------------------------
978 dnl Test if the socket send() function is available, 
979 dnl and check its return type and the types of its 
980 dnl arguments. If the function succeeds HAVE_SEND 
981 dnl will be defined, defining the types of the arguments 
982 dnl in SEND_TYPE_ARG1, SEND_TYPE_ARG2, SEND_TYPE_ARG3 
983 dnl and SEND_TYPE_ARG4, defining the type of the function
984 dnl return value in SEND_TYPE_RETV, and also defining the 
985 dnl type qualifier of second argument in SEND_QUAL_ARG2.
986
987 AC_DEFUN([CURL_CHECK_FUNC_SEND], [
988   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
989   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
990   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
991   #
992   AC_MSG_CHECKING([for send])
993   AC_LINK_IFELSE([
994     AC_LANG_PROGRAM([[
995 #undef inline 
996 #ifdef HAVE_WINDOWS_H
997 #ifndef WIN32_LEAN_AND_MEAN
998 #define WIN32_LEAN_AND_MEAN
999 #endif
1000 #include <windows.h>
1001 #ifdef HAVE_WINSOCK2_H
1002 #include <winsock2.h>
1003 #else
1004 #ifdef HAVE_WINSOCK_H
1005 #include <winsock.h>
1006 #endif
1007 #endif
1008 #else
1009 #ifdef HAVE_SYS_TYPES_H
1010 #include <sys/types.h>
1011 #endif
1012 #ifdef HAVE_SYS_SOCKET_H
1013 #include <sys/socket.h>
1014 #endif
1015 #endif
1016     ]],[[
1017       send(0, 0, 0, 0);
1018     ]])
1019   ],[
1020     AC_MSG_RESULT([yes])
1021     curl_cv_send="yes"
1022   ],[
1023     AC_MSG_RESULT([no])
1024     curl_cv_send="no"
1025   ])
1026   #
1027   if test "$curl_cv_send" = "yes"; then
1028     AC_CACHE_CHECK([types of args and return type for send],
1029       [curl_cv_func_send_args], [
1030       curl_cv_func_send_args="unknown"
1031       for send_retv in 'int' 'ssize_t'; do
1032         for send_arg1 in 'int' 'ssize_t' 'SOCKET'; do
1033           for send_arg2 in 'char *' 'void *' 'const char *' 'const void *'; do
1034             for send_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
1035               for send_arg4 in 'int' 'unsigned int'; do
1036                 if test "$curl_cv_func_send_args" = "unknown"; then
1037                   AC_COMPILE_IFELSE([
1038                     AC_LANG_PROGRAM([[
1039 #undef inline 
1040 #ifdef HAVE_WINDOWS_H
1041 #ifndef WIN32_LEAN_AND_MEAN
1042 #define WIN32_LEAN_AND_MEAN
1043 #endif
1044 #include <windows.h>
1045 #ifdef HAVE_WINSOCK2_H
1046 #include <winsock2.h>
1047 #else
1048 #ifdef HAVE_WINSOCK_H
1049 #include <winsock.h>
1050 #endif
1051 #endif
1052 #define SENDCALLCONV PASCAL
1053 #else
1054 #ifdef HAVE_SYS_TYPES_H
1055 #include <sys/types.h>
1056 #endif
1057 #ifdef HAVE_SYS_SOCKET_H
1058 #include <sys/socket.h>
1059 #endif
1060 #define SENDCALLCONV
1061 #endif
1062                       extern $send_retv SENDCALLCONV
1063                       send($send_arg1, $send_arg2, $send_arg3, $send_arg4);
1064                     ]],[[
1065                       $send_arg1 s=0;
1066                       $send_arg3 len=0;
1067                       $send_arg4 flags=0;
1068                       $send_retv res = send(s, 0, len, flags);
1069                     ]])
1070                   ],[
1071                     curl_cv_func_send_args="$send_arg1,$send_arg2,$send_arg3,$send_arg4,$send_retv"
1072                   ])
1073                 fi
1074               done
1075             done
1076           done
1077         done
1078       done
1079     ]) # AC-CACHE-CHECK
1080     if test "$curl_cv_func_send_args" = "unknown"; then
1081       AC_MSG_ERROR([Cannot find proper types to use for send args])
1082     else
1083       send_prev_IFS=$IFS; IFS=','
1084       set dummy `echo "$curl_cv_func_send_args" | sed 's/\*/\*/g'`
1085       IFS=$send_prev_IFS
1086       shift
1087       #
1088       send_qual_type_arg2=$[2]
1089       #
1090       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG1, $[1],
1091         [Define to the type of arg 1 for send.])
1092       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG3, $[3],
1093         [Define to the type of arg 3 for send.])
1094       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG4, $[4],
1095         [Define to the type of arg 4 for send.])
1096       AC_DEFINE_UNQUOTED(SEND_TYPE_RETV, $[5],
1097         [Define to the function return type for send.])
1098       #
1099       prev_sh_opts=$-
1100       #
1101       case $prev_sh_opts in
1102         *f*)
1103           ;;
1104         *)
1105           set -f
1106           ;;
1107       esac
1108       #
1109       case "$send_qual_type_arg2" in
1110         const*)
1111           send_qual_arg2=const
1112           send_type_arg2=`echo $send_qual_type_arg2 | sed 's/^const //'`
1113         ;;
1114         *)
1115           send_qual_arg2=
1116           send_type_arg2=$send_qual_type_arg2
1117         ;;
1118       esac
1119       #
1120       AC_DEFINE_UNQUOTED(SEND_QUAL_ARG2, $send_qual_arg2,
1121         [Define to the type qualifier of arg 2 for send.])
1122       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG2, $send_type_arg2,
1123         [Define to the type of arg 2 for send.])
1124       #
1125       case $prev_sh_opts in
1126         *f*)
1127           ;;
1128         *)
1129           set +f
1130           ;;
1131       esac
1132       #
1133       AC_DEFINE_UNQUOTED(HAVE_SEND, 1,
1134         [Define to 1 if you have the send function.])
1135       ac_cv_func_send="yes"
1136     fi
1137   else
1138     AC_MSG_ERROR([Unable to link function send])
1139   fi
1140 ])
1141
1142
1143 dnl CURL_CHECK_FUNC_RECVFROM
1144 dnl -------------------------------------------------
1145 dnl Test if the socket recvfrom() function is available,
1146 dnl and check its return type and the types of its
1147 dnl arguments. If the function succeeds HAVE_RECVFROM
1148 dnl will be defined, defining the types of the arguments
1149 dnl in RECVFROM_TYPE_ARG1, RECVFROM_TYPE_ARG2, and so on
1150 dnl to RECVFROM_TYPE_ARG6, defining also the type of the
1151 dnl function return value in RECVFROM_TYPE_RETV.
1152 dnl Notice that the types returned for pointer arguments
1153 dnl will actually be the type pointed by the pointer.
1154
1155 AC_DEFUN([CURL_CHECK_FUNC_RECVFROM], [
1156   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
1157   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
1158   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
1159   #
1160   AC_MSG_CHECKING([for recvfrom])
1161   AC_LINK_IFELSE([
1162     AC_LANG_PROGRAM([[
1163 #undef inline 
1164 #ifdef HAVE_WINDOWS_H
1165 #ifndef WIN32_LEAN_AND_MEAN
1166 #define WIN32_LEAN_AND_MEAN
1167 #endif
1168 #include <windows.h>
1169 #ifdef HAVE_WINSOCK2_H
1170 #include <winsock2.h>
1171 #else
1172 #ifdef HAVE_WINSOCK_H
1173 #include <winsock.h>
1174 #endif
1175 #endif
1176 #else
1177 #ifdef HAVE_SYS_TYPES_H
1178 #include <sys/types.h>
1179 #endif
1180 #ifdef HAVE_SYS_SOCKET_H
1181 #include <sys/socket.h>
1182 #endif
1183 #endif
1184     ]],[[
1185       recvfrom(0, 0, 0, 0, 0, 0);
1186     ]])
1187   ],[
1188     AC_MSG_RESULT([yes])
1189     curl_cv_recvfrom="yes"
1190   ],[
1191     AC_MSG_RESULT([no])
1192     curl_cv_recvfrom="no"
1193   ])
1194   #
1195   if test "$curl_cv_recvfrom" = "yes"; then
1196     AC_CACHE_CHECK([types of args and return type for recvfrom],
1197       [curl_cv_func_recvfrom_args], [
1198       curl_cv_func_recvfrom_args="unknown"
1199       for recvfrom_retv in 'int' 'ssize_t'; do
1200         for recvfrom_arg1 in 'int' 'ssize_t' 'SOCKET'; do
1201           for recvfrom_arg2 in 'char *' 'void *'; do
1202             for recvfrom_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
1203               for recvfrom_arg4 in 'int' 'unsigned int'; do
1204                 for recvfrom_arg5 in 'struct sockaddr *' 'void *'; do
1205                   for recvfrom_arg6 in 'socklen_t *' 'int *' 'unsigned int *' 'size_t *' 'void *'; do
1206                     if test "$curl_cv_func_recvfrom_args" = "unknown"; then
1207                       AC_COMPILE_IFELSE([
1208                         AC_LANG_PROGRAM([[
1209 #undef inline 
1210 #ifdef HAVE_WINDOWS_H
1211 #ifndef WIN32_LEAN_AND_MEAN
1212 #define WIN32_LEAN_AND_MEAN
1213 #endif
1214 #include <windows.h>
1215 #ifdef HAVE_WINSOCK2_H
1216 #include <winsock2.h>
1217 #else
1218 #ifdef HAVE_WINSOCK_H
1219 #include <winsock.h>
1220 #endif
1221 #endif
1222 #define RECVFROMCALLCONV PASCAL
1223 #else
1224 #ifdef HAVE_SYS_TYPES_H
1225 #include <sys/types.h>
1226 #endif
1227 #ifdef HAVE_SYS_SOCKET_H
1228 #include <sys/socket.h>
1229 #endif
1230 #define RECVFROMCALLCONV
1231 #endif
1232                           extern $recvfrom_retv RECVFROMCALLCONV
1233                           recvfrom($recvfrom_arg1, $recvfrom_arg2,
1234                                    $recvfrom_arg3, $recvfrom_arg4,
1235                                    $recvfrom_arg5, $recvfrom_arg6);
1236                         ]],[[
1237                           $recvfrom_arg1 s=0;
1238                           $recvfrom_arg2 buf=0;
1239                           $recvfrom_arg3 len=0;
1240                           $recvfrom_arg4 flags=0;
1241                           $recvfrom_arg5 addr=0;
1242                           $recvfrom_arg6 addrlen=0;
1243                           $recvfrom_retv res=0;
1244                           res = recvfrom(s, buf, len, flags, addr, addrlen);
1245                         ]])
1246                       ],[
1247                         curl_cv_func_recvfrom_args="$recvfrom_arg1,$recvfrom_arg2,$recvfrom_arg3,$recvfrom_arg4,$recvfrom_arg5,$recvfrom_arg6,$recvfrom_retv"
1248                       ])
1249                     fi
1250                   done
1251                 done
1252               done
1253             done
1254           done
1255         done
1256       done
1257     ]) # AC-CACHE-CHECK
1258     # Nearly last minute change for this release starts here
1259     AC_DEFINE_UNQUOTED(HAVE_RECVFROM, 1,
1260       [Define to 1 if you have the recvfrom function.])
1261     ac_cv_func_recvfrom="yes"
1262     # Nearly last minute change for this release ends here
1263     if test "$curl_cv_func_recvfrom_args" = "unknown"; then
1264       AC_MSG_WARN([Cannot find proper types to use for recvfrom args])
1265     else
1266       recvfrom_prev_IFS=$IFS; IFS=','
1267       set dummy `echo "$curl_cv_func_recvfrom_args" | sed 's/\*/\*/g'`
1268       IFS=$recvfrom_prev_IFS
1269       shift
1270       #
1271       recvfrom_ptrt_arg2=$[2]
1272       recvfrom_ptrt_arg5=$[5]
1273       recvfrom_ptrt_arg6=$[6]
1274       #
1275       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG1, $[1],
1276         [Define to the type of arg 1 for recvfrom.])
1277       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG3, $[3],
1278         [Define to the type of arg 3 for recvfrom.])
1279       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG4, $[4],
1280         [Define to the type of arg 4 for recvfrom.])
1281       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_RETV, $[7],
1282         [Define to the function return type for recvfrom.])
1283       #
1284       prev_sh_opts=$-
1285       #
1286       case $prev_sh_opts in
1287         *f*)
1288           ;;
1289         *)
1290           set -f
1291           ;;
1292       esac
1293       #
1294       recvfrom_type_arg2=`echo $recvfrom_ptrt_arg2 | sed 's/ \*//'`
1295       recvfrom_type_arg5=`echo $recvfrom_ptrt_arg5 | sed 's/ \*//'`
1296       recvfrom_type_arg6=`echo $recvfrom_ptrt_arg6 | sed 's/ \*//'`
1297       #
1298       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG2, $recvfrom_type_arg2,
1299         [Define to the type pointed by arg 2 for recvfrom.])
1300       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG5, $recvfrom_type_arg5,
1301         [Define to the type pointed by arg 5 for recvfrom.])
1302       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG6, $recvfrom_type_arg6,
1303         [Define to the type pointed by arg 6 for recvfrom.])
1304       #
1305       if test "$recvfrom_type_arg2" = "void"; then
1306         AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG2_IS_VOID, 1,
1307           [Define to 1 if the type pointed by arg 2 for recvfrom is void.])
1308       fi
1309       if test "$recvfrom_type_arg5" = "void"; then
1310         AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG5_IS_VOID, 1,
1311           [Define to 1 if the type pointed by arg 5 for recvfrom is void.])
1312       fi
1313       if test "$recvfrom_type_arg6" = "void"; then
1314         AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG6_IS_VOID, 1,
1315           [Define to 1 if the type pointed by arg 6 for recvfrom is void.])
1316       fi
1317       #
1318       case $prev_sh_opts in
1319         *f*)
1320           ;;
1321         *)
1322           set +f
1323           ;;
1324       esac
1325       #
1326       AC_DEFINE_UNQUOTED(HAVE_RECVFROM, 1,
1327         [Define to 1 if you have the recvfrom function.])
1328       ac_cv_func_recvfrom="yes"
1329     fi
1330   else
1331     AC_MSG_WARN([Unable to link function recvfrom])
1332     AC_MSG_WARN([Your system will be vulnerable to some forms of DNS cache poisoning])
1333   fi
1334 ])
1335
1336
1337 dnl CURL_CHECK_MSG_NOSIGNAL
1338 dnl -------------------------------------------------
1339 dnl Check for MSG_NOSIGNAL
1340
1341 AC_DEFUN([CURL_CHECK_MSG_NOSIGNAL], [
1342   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
1343   AC_CACHE_CHECK([for MSG_NOSIGNAL], [ac_cv_msg_nosignal], [
1344     AC_COMPILE_IFELSE([
1345       AC_LANG_PROGRAM([[
1346 #undef inline 
1347 #ifdef HAVE_WINDOWS_H
1348 #ifndef WIN32_LEAN_AND_MEAN
1349 #define WIN32_LEAN_AND_MEAN
1350 #endif
1351 #include <windows.h>
1352 #ifdef HAVE_WINSOCK2_H
1353 #include <winsock2.h>
1354 #else
1355 #ifdef HAVE_WINSOCK_H
1356 #include <winsock.h>
1357 #endif
1358 #endif
1359 #else
1360 #ifdef HAVE_SYS_TYPES_H
1361 #include <sys/types.h>
1362 #endif
1363 #ifdef HAVE_SYS_SOCKET_H
1364 #include <sys/socket.h>
1365 #endif
1366 #endif
1367       ]],[[
1368         int flag=MSG_NOSIGNAL;
1369       ]])
1370     ],[
1371       ac_cv_msg_nosignal="yes"
1372     ],[
1373       ac_cv_msg_nosignal="no"
1374     ])
1375   ])
1376   case "$ac_cv_msg_nosignal" in
1377     yes)
1378       AC_DEFINE_UNQUOTED(HAVE_MSG_NOSIGNAL, 1,
1379         [Define to 1 if you have the MSG_NOSIGNAL flag.])
1380       ;;
1381   esac
1382 ])
1383
1384
1385 dnl CURL_CHECK_STRUCT_TIMEVAL
1386 dnl -------------------------------------------------
1387 dnl Check for timeval struct
1388
1389 AC_DEFUN([CURL_CHECK_STRUCT_TIMEVAL], [
1390   AC_REQUIRE([AC_HEADER_TIME])dnl
1391   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
1392   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
1393   AC_CHECK_HEADERS(sys/types.h sys/time.h time.h)
1394   AC_CACHE_CHECK([for struct timeval], [ac_cv_struct_timeval], [
1395     AC_COMPILE_IFELSE([
1396       AC_LANG_PROGRAM([[
1397 #undef inline 
1398 #ifdef HAVE_WINDOWS_H
1399 #ifndef WIN32_LEAN_AND_MEAN
1400 #define WIN32_LEAN_AND_MEAN
1401 #endif
1402 #include <windows.h>
1403 #ifdef HAVE_WINSOCK2_H
1404 #include <winsock2.h>
1405 #else
1406 #ifdef HAVE_WINSOCK_H
1407 #include <winsock.h>
1408 #endif
1409 #endif
1410 #endif
1411 #ifdef HAVE_SYS_TYPES_H
1412 #include <sys/types.h>
1413 #endif
1414 #ifdef HAVE_SYS_TIME_H
1415 #include <sys/time.h>
1416 #ifdef TIME_WITH_SYS_TIME
1417 #include <time.h>
1418 #endif
1419 #else
1420 #ifdef HAVE_TIME_H
1421 #include <time.h>
1422 #endif
1423 #endif
1424       ]],[[
1425         struct timeval ts;
1426         ts.tv_sec  = 0;
1427         ts.tv_usec = 0;
1428       ]])
1429     ],[
1430       ac_cv_struct_timeval="yes"
1431     ],[
1432       ac_cv_struct_timeval="no"
1433     ])
1434   ])
1435   case "$ac_cv_struct_timeval" in
1436     yes)
1437       AC_DEFINE_UNQUOTED(HAVE_STRUCT_TIMEVAL, 1,
1438         [Define to 1 if you have the timeval struct.])
1439       ;;
1440   esac
1441 ])
1442
1443
1444 dnl TYPE_SIG_ATOMIC_T
1445 dnl -------------------------------------------------
1446 dnl Check if the sig_atomic_t type is available, and
1447 dnl verify if it is already defined as volatile.
1448
1449 AC_DEFUN([TYPE_SIG_ATOMIC_T], [
1450   AC_CHECK_HEADERS(signal.h)
1451   AC_CHECK_TYPE([sig_atomic_t],[
1452     AC_DEFINE(HAVE_SIG_ATOMIC_T, 1,
1453       [Define to 1 if sig_atomic_t is an available typedef.])
1454   ], ,[
1455 #ifdef HAVE_SIGNAL_H
1456 #include <signal.h>
1457 #endif
1458   ])
1459   case "$ac_cv_type_sig_atomic_t" in
1460     yes)
1461       #
1462       AC_MSG_CHECKING([if sig_atomic_t is already defined as volatile])
1463       AC_LINK_IFELSE([
1464         AC_LANG_PROGRAM([[
1465 #ifdef HAVE_SIGNAL_H
1466 #include <signal.h>
1467 #endif
1468         ]],[[
1469           static volatile sig_atomic_t dummy = 0;
1470         ]])
1471       ],[
1472         AC_MSG_RESULT([no])
1473         ac_cv_sig_atomic_t_volatile="no"
1474       ],[
1475         AC_MSG_RESULT([yes])
1476         ac_cv_sig_atomic_t_volatile="yes"
1477       ])
1478       #
1479       if test "$ac_cv_sig_atomic_t_volatile" = "yes"; then
1480         AC_DEFINE(HAVE_SIG_ATOMIC_T_VOLATILE, 1,
1481           [Define to 1 if sig_atomic_t is already defined as volatile.])
1482       fi
1483       ;;
1484   esac
1485 ])
1486
1487
1488 dnl TYPE_IN_ADDR_T
1489 dnl -------------------------------------------------
1490 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
1491 dnl and a few other things.
1492
1493 AC_DEFUN([TYPE_IN_ADDR_T], [
1494   AC_CHECK_TYPE([in_addr_t], ,[
1495     dnl in_addr_t not available
1496     AC_CACHE_CHECK([for in_addr_t equivalent],
1497       [curl_cv_in_addr_t_equiv], [
1498       curl_cv_in_addr_t_equiv="unknown"
1499       for t in "unsigned long" int size_t unsigned long; do
1500         if test "$curl_cv_in_addr_t_equiv" = "unknown"; then
1501           AC_LINK_IFELSE([
1502             AC_LANG_PROGRAM([[
1503 #undef inline
1504 #ifdef HAVE_WINDOWS_H
1505 #ifndef WIN32_LEAN_AND_MEAN
1506 #define WIN32_LEAN_AND_MEAN
1507 #endif
1508 #include <windows.h>
1509 #ifdef HAVE_WINSOCK2_H
1510 #include <winsock2.h>
1511 #else
1512 #ifdef HAVE_WINSOCK_H
1513 #include <winsock.h>
1514 #endif
1515 #endif
1516 #else
1517 #ifdef HAVE_SYS_TYPES_H
1518 #include <sys/types.h>
1519 #endif
1520 #ifdef HAVE_SYS_SOCKET_H
1521 #include <sys/socket.h>
1522 #endif
1523 #ifdef HAVE_NETINET_IN_H
1524 #include <netinet/in.h>
1525 #endif
1526 #ifdef HAVE_ARPA_INET_H
1527 #include <arpa/inet.h>
1528 #endif
1529 #endif
1530             ]],[[
1531               $t data = inet_addr ("1.2.3.4");
1532             ]])
1533           ],[
1534             curl_cv_in_addr_t_equiv="$t"
1535           ])
1536         fi
1537       done
1538     ])
1539     case "$curl_cv_in_addr_t_equiv" in
1540       unknown)
1541         AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
1542         ;;
1543       *)
1544         AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
1545           [Type to use in place of in_addr_t when system does not provide it.])
1546         ;;
1547     esac
1548   ],[
1549 #undef inline
1550 #ifdef HAVE_WINDOWS_H
1551 #ifndef WIN32_LEAN_AND_MEAN
1552 #define WIN32_LEAN_AND_MEAN
1553 #endif
1554 #include <windows.h>
1555 #ifdef HAVE_WINSOCK2_H
1556 #include <winsock2.h>
1557 #else
1558 #ifdef HAVE_WINSOCK_H
1559 #include <winsock.h>
1560 #endif
1561 #endif
1562 #else
1563 #ifdef HAVE_SYS_TYPES_H
1564 #include <sys/types.h>
1565 #endif
1566 #ifdef HAVE_SYS_SOCKET_H
1567 #include <sys/socket.h>
1568 #endif
1569 #ifdef HAVE_NETINET_IN_H
1570 #include <netinet/in.h>
1571 #endif
1572 #ifdef HAVE_ARPA_INET_H
1573 #include <arpa/inet.h>
1574 #endif
1575 #endif
1576   ])
1577 ])
1578
1579
1580 dnl CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC
1581 dnl -------------------------------------------------
1582 dnl Check if monotonic clock_gettime is available.
1583
1584 AC_DEFUN([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC], [
1585   AC_REQUIRE([AC_HEADER_TIME])dnl
1586   AC_CHECK_HEADERS(sys/types.h sys/time.h time.h)
1587   AC_MSG_CHECKING([for monotonic clock_gettime])
1588   AC_COMPILE_IFELSE([
1589     AC_LANG_PROGRAM([[
1590 #ifdef HAVE_SYS_TYPES_H
1591 #include <sys/types.h>
1592 #endif
1593 #ifdef HAVE_SYS_TIME_H
1594 #include <sys/time.h>
1595 #ifdef TIME_WITH_SYS_TIME
1596 #include <time.h>
1597 #endif
1598 #else
1599 #ifdef HAVE_TIME_H
1600 #include <time.h>
1601 #endif
1602 #endif
1603     ]],[[
1604       struct timespec ts;
1605       (void)clock_gettime(CLOCK_MONOTONIC, &ts);
1606     ]])
1607   ],[
1608     AC_MSG_RESULT([yes])
1609     ac_cv_func_clock_gettime="yes"
1610   ],[
1611     AC_MSG_RESULT([no])
1612     ac_cv_func_clock_gettime="no"
1613   ])
1614   dnl Definition of HAVE_CLOCK_GETTIME_MONOTONIC is intentionally postponed
1615   dnl until library linking and run-time checks for clock_gettime succeed.
1616 ])
1617
1618
1619 dnl CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC
1620 dnl -------------------------------------------------
1621 dnl If monotonic clock_gettime is available then,
1622 dnl check and prepended to LIBS any needed libraries.
1623
1624 AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC], [
1625   AC_REQUIRE([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC])dnl
1626   #
1627   if test "$ac_cv_func_clock_gettime" = "yes"; then
1628     #
1629     AC_MSG_CHECKING([for clock_gettime in libraries])
1630     #
1631     curl_cv_save_LIBS="$LIBS"
1632     curl_cv_gclk_LIBS="unknown"
1633     #
1634     for x_xlibs in '' '-lrt' '-lposix4' ; do
1635       if test "$curl_cv_gclk_LIBS" = "unknown"; then
1636         if test -z "$x_xlibs"; then
1637           LIBS="$curl_cv_save_LIBS"
1638         else
1639           LIBS="$x_xlibs $curl_cv_save_LIBS"
1640         fi
1641         AC_LINK_IFELSE([
1642           AC_LANG_PROGRAM([[
1643 #ifdef HAVE_SYS_TYPES_H
1644 #include <sys/types.h>
1645 #endif
1646 #ifdef HAVE_SYS_TIME_H
1647 #include <sys/time.h>
1648 #ifdef TIME_WITH_SYS_TIME
1649 #include <time.h>
1650 #endif
1651 #else
1652 #ifdef HAVE_TIME_H
1653 #include <time.h>
1654 #endif
1655 #endif
1656           ]],[[
1657             struct timespec ts;
1658             (void)clock_gettime(CLOCK_MONOTONIC, &ts);
1659           ]])
1660         ],[
1661           curl_cv_gclk_LIBS="$x_xlibs"
1662         ])
1663       fi
1664     done
1665     #
1666     LIBS="$curl_cv_save_LIBS"
1667     #
1668     case X-"$curl_cv_gclk_LIBS" in
1669       X-unknown)
1670         AC_MSG_RESULT([cannot find clock_gettime])
1671         AC_MSG_WARN([HAVE_CLOCK_GETTIME_MONOTONIC will not be defined])
1672         ac_cv_func_clock_gettime="no"
1673         ;;
1674       X-)
1675         AC_MSG_RESULT([no additional lib required])
1676         ac_cv_func_clock_gettime="yes"
1677         ;;
1678       *)
1679         if test -z "$curl_cv_save_LIBS"; then
1680           LIBS="$curl_cv_gclk_LIBS"
1681         else
1682           LIBS="$curl_cv_gclk_LIBS $curl_cv_save_LIBS"
1683         fi
1684         AC_MSG_RESULT([$curl_cv_gclk_LIBS])
1685         ac_cv_func_clock_gettime="yes"
1686         ;;
1687     esac
1688     #
1689     dnl only do runtime verification when not cross-compiling
1690     if test "x$cross_compiling" != "xyes" &&
1691       test "$ac_cv_func_clock_gettime" = "yes"; then
1692       AC_MSG_CHECKING([if monotonic clock_gettime works])
1693       AC_RUN_IFELSE([
1694         AC_LANG_PROGRAM([[
1695 #ifdef HAVE_STDLIB_H
1696 #include <stdlib.h>
1697 #endif
1698 #ifdef HAVE_SYS_TYPES_H
1699 #include <sys/types.h>
1700 #endif
1701 #ifdef HAVE_SYS_TIME_H
1702 #include <sys/time.h>
1703 #ifdef TIME_WITH_SYS_TIME
1704 #include <time.h>
1705 #endif
1706 #else
1707 #ifdef HAVE_TIME_H
1708 #include <time.h>
1709 #endif
1710 #endif
1711         ]],[[
1712           struct timespec ts;
1713           if (0 == clock_gettime(CLOCK_MONOTONIC, &ts))
1714             exit(0);
1715           else
1716             exit(1);
1717         ]])
1718       ],[
1719         AC_MSG_RESULT([yes])
1720       ],[
1721         AC_MSG_RESULT([no])
1722         AC_MSG_WARN([HAVE_CLOCK_GETTIME_MONOTONIC will not be defined])
1723         ac_cv_func_clock_gettime="no"
1724         LIBS="$curl_cv_save_LIBS"
1725       ])
1726     fi
1727     #
1728     case "$ac_cv_func_clock_gettime" in
1729       yes)
1730         AC_DEFINE_UNQUOTED(HAVE_CLOCK_GETTIME_MONOTONIC, 1,
1731           [Define to 1 if you have the clock_gettime function and monotonic timer.])
1732         ;;
1733     esac
1734     #
1735   fi
1736   #
1737 ])
1738
1739
1740 dnl CARES_DEFINE_UNQUOTED (VARIABLE, [VALUE])
1741 dnl -------------------------------------------------
1742 dnl Like AC_DEFINE_UNQUOTED this macro will define a C preprocessor
1743 dnl symbol that can be further used in custom template configuration
1744 dnl files. This macro, unlike AC_DEFINE_UNQUOTED, does not use a third
1745 dnl argument for the description. Symbol definitions done with this
1746 dnl macro are intended to be exclusively used in handcrafted *.h.in
1747 dnl template files. Contrary to what AC_DEFINE_UNQUOTED does, this one
1748 dnl prevents autoheader generation and insertion of symbol template
1749 dnl stub and definition into the first configuration header file. Do
1750 dnl not use this macro as a replacement for AC_DEFINE_UNQUOTED, each
1751 dnl one serves different functional needs.
1752
1753 AC_DEFUN([CARES_DEFINE_UNQUOTED], [
1754 cat >>confdefs.h <<_EOF
1755 [@%:@define] $1 ifelse($#, 2, [$2], 1)
1756 _EOF
1757 ])
1758
1759
1760 dnl CARES_CONFIGURE_LONG
1761 dnl -------------------------------------------------
1762 dnl Find out the size of long as reported by sizeof() and define
1763 dnl CARES_SIZEOF_LONG as appropriate to be used in template file
1764 dnl ares_build.h.in to properly configure the library.
1765 dnl The size of long is a build time characteristic and as such
1766 dnl must be recorded in ares_build.h
1767
1768 AC_DEFUN([CARES_CONFIGURE_LONG], [
1769   if test -z "$ac_cv_sizeof_long" ||
1770     test "$ac_cv_sizeof_long" -eq "0"; then
1771     AC_MSG_ERROR([cannot find out size of long.])
1772   fi
1773   CARES_DEFINE_UNQUOTED([CARES_SIZEOF_LONG], [$ac_cv_sizeof_long])
1774 ])
1775
1776
1777 dnl CARES_CONFIGURE_ARES_SOCKLEN_T
1778 dnl -------------------------------------------------
1779 dnl Find out suitable ares_socklen_t data type definition and size, making
1780 dnl appropriate definitions for template file ares_build.h.in
1781 dnl to properly configure and use the library.
1782 dnl
1783 dnl The need for the ares_socklen_t definition arises mainly to properly
1784 dnl interface HP-UX systems which on one hand have a typedef'ed socklen_t
1785 dnl data type which is 32 or 64-Bit wide depending on the data model being
1786 dnl used, and that on the other hand is only actually used when interfacing
1787 dnl the X/Open sockets provided in the xnet library.
1788
1789 AC_DEFUN([CARES_CONFIGURE_ARES_SOCKLEN_T], [
1790   AC_REQUIRE([CARES_INCLUDES_WS2TCPIP])dnl
1791   AC_REQUIRE([CARES_INCLUDES_SYS_SOCKET])dnl
1792   AC_REQUIRE([CARES_PREPROCESS_CALLCONV])dnl
1793   #
1794   AC_MSG_CHECKING([for ares_socklen_t data type])
1795   cares_typeof_ares_socklen_t="unknown"
1796   for arg1 in int SOCKET; do
1797     for arg2 in 'struct sockaddr' void; do
1798       for t in socklen_t int size_t 'unsigned int' long 'unsigned long' void; do
1799         if test "$cares_typeof_ares_socklen_t" = "unknown"; then
1800           AC_COMPILE_IFELSE([
1801             AC_LANG_PROGRAM([[
1802               $cares_includes_ws2tcpip
1803               $cares_includes_sys_socket
1804               $cares_preprocess_callconv
1805               extern int FUNCALLCONV getpeername($arg1, $arg2 *, $t *);
1806             ]],[[
1807               $t *lenptr = 0;
1808               if(0 != getpeername(0, 0, lenptr))
1809                 return 1;
1810             ]])
1811           ],[
1812             cares_typeof_ares_socklen_t="$t"
1813           ])
1814         fi
1815       done
1816     done
1817   done
1818   for t in socklen_t int; do
1819     if test "$cares_typeof_ares_socklen_t" = "void"; then
1820       AC_COMPILE_IFELSE([
1821         AC_LANG_PROGRAM([[
1822           $cares_includes_sys_socket
1823           typedef $t ares_socklen_t;
1824         ]],[[
1825           ares_socklen_t dummy;
1826         ]])
1827       ],[
1828         cares_typeof_ares_socklen_t="$t"
1829       ])
1830     fi
1831   done
1832   AC_MSG_RESULT([$cares_typeof_ares_socklen_t])
1833   if test "$cares_typeof_ares_socklen_t" = "void" ||
1834     test "$cares_typeof_ares_socklen_t" = "unknown"; then
1835     AC_MSG_ERROR([cannot find data type for ares_socklen_t.])
1836   fi
1837   #
1838   AC_MSG_CHECKING([size of ares_socklen_t])
1839   cares_sizeof_ares_socklen_t="unknown"
1840   cares_pull_headers_socklen_t="unknown"
1841   if test "$ac_cv_header_ws2tcpip_h" = "yes"; then
1842     tst_pull_header_checks='none ws2tcpip'
1843     tst_size_checks='4'
1844   else
1845     tst_pull_header_checks='none systypes syssocket'
1846     tst_size_checks='4 8 2'
1847   fi
1848   for tst_size in $tst_size_checks; do
1849     for tst_pull_headers in $tst_pull_header_checks; do
1850       if test "$cares_sizeof_ares_socklen_t" = "unknown"; then
1851         case $tst_pull_headers in
1852           ws2tcpip)
1853             tmp_includes="$cares_includes_ws2tcpip"
1854             ;;
1855           systypes)
1856             tmp_includes="$cares_includes_sys_types"
1857             ;;
1858           syssocket)
1859             tmp_includes="$cares_includes_sys_socket"
1860             ;;
1861           *)
1862             tmp_includes=""
1863             ;;
1864         esac
1865         AC_COMPILE_IFELSE([
1866           AC_LANG_PROGRAM([[
1867             $tmp_includes
1868             typedef $cares_typeof_ares_socklen_t ares_socklen_t;
1869             typedef char dummy_arr[sizeof(ares_socklen_t) == $tst_size ? 1 : -1];
1870           ]],[[
1871             ares_socklen_t dummy;
1872           ]])
1873         ],[
1874           cares_sizeof_ares_socklen_t="$tst_size"
1875           cares_pull_headers_socklen_t="$tst_pull_headers"
1876         ])
1877       fi
1878     done
1879   done
1880   AC_MSG_RESULT([$cares_sizeof_ares_socklen_t])
1881   if test "$cares_sizeof_ares_socklen_t" = "unknown"; then
1882     AC_MSG_ERROR([cannot find out size of ares_socklen_t.])
1883   fi
1884   #
1885   case $cares_pull_headers_socklen_t in
1886     ws2tcpip)
1887       CARES_DEFINE_UNQUOTED([CARES_PULL_WS2TCPIP_H])
1888       ;;
1889     systypes)
1890       CARES_DEFINE_UNQUOTED([CARES_PULL_SYS_TYPES_H])
1891       ;;
1892     syssocket)
1893       CARES_DEFINE_UNQUOTED([CARES_PULL_SYS_TYPES_H])
1894       CARES_DEFINE_UNQUOTED([CARES_PULL_SYS_SOCKET_H])
1895       ;;
1896   esac
1897   CARES_DEFINE_UNQUOTED([CARES_TYPEOF_ARES_SOCKLEN_T], [$cares_typeof_ares_socklen_t])
1898   CARES_DEFINE_UNQUOTED([CARES_SIZEOF_ARES_SOCKLEN_T], [$cares_sizeof_ares_socklen_t])
1899 ])
1900
1901
1902 dnl This macro determines if the specified struct exists in the specified file
1903 dnl Syntax:
1904 dnl CARES_CHECK_STRUCT(headers, struct name, if found, [if not found])
1905
1906 AC_DEFUN([CARES_CHECK_STRUCT], [
1907   AC_MSG_CHECKING([for struct $2])
1908   AC_TRY_COMPILE([$1], 
1909     [
1910       struct $2 struct_instance;
1911     ], ac_struct="yes", ac_found="no")
1912   if test "$ac_struct" = "yes" ; then
1913     AC_MSG_RESULT(yes)
1914     $3
1915   else
1916     AC_MSG_RESULT(no)
1917     $4
1918   fi
1919 ])
1920
1921 dnl This macro determines if the specified constant exists in the specified file
1922 dnl Syntax:
1923 dnl CARES_CHECK_CONSTANT(headers, constant name, if found, [if not found])
1924
1925 AC_DEFUN([CARES_CHECK_CONSTANT], [
1926   AC_MSG_CHECKING([for $2])
1927   AC_EGREP_CPP(VARIABLEWASDEFINED,
1928    [
1929       $1
1930
1931       #ifdef $2
1932         VARIABLEWASDEFINED
1933       #else
1934         NJET
1935       #endif
1936     ], ac_constant="yes", ac_constant="no"
1937   )
1938   if test "$ac_constant" = "yes" ; then
1939     AC_MSG_RESULT(yes)
1940     $3
1941   else
1942     AC_MSG_RESULT(no)
1943     $4
1944   fi
1945 ])
1946