Fix CURL_CHECK_HEADERS_ONCE
[platform/upstream/c-ares.git] / acinclude.m4
1
2
3 dnl CURL_CHECK_HEADERS_ONCE
4 dnl -------------------------------------------------
5 dnl Check for headers if check not already done.
6
7 AC_DEFUN([CURL_CHECK_HEADERS_ONCE], [
8   for f_hdr in $1
9   do
10     u_hdr=`echo "$f_hdr" | sed 'y/\.\/-/___/'`
11     eval prev_check_res=\$ac_cv_header_$u_hdr
12     case "$prev_check_res" in
13       yes | no)
14         ;;
15       *)
16         AC_CHECK_HEADERS($f_hdr)
17         ;;
18     esac
19   done
20 ])
21
22
23 dnl CURL_CHECK_HEADER_WINDOWS
24 dnl -------------------------------------------------
25 dnl Check for compilable and valid windows.h header 
26
27 AC_DEFUN([CURL_CHECK_HEADER_WINDOWS], [
28   AC_CACHE_CHECK([for windows.h], [ac_cv_header_windows_h], [
29     AC_COMPILE_IFELSE([
30       AC_LANG_PROGRAM([
31 #undef inline
32 #ifndef WIN32_LEAN_AND_MEAN
33 #define WIN32_LEAN_AND_MEAN
34 #endif
35 #include <windows.h>
36       ],[
37 #ifdef __CYGWIN__
38         HAVE_WINDOWS_H shall not be defined.
39 #else
40         int dummy=2*WINVER;
41 #endif
42       ])
43     ],[
44       ac_cv_header_windows_h="yes"
45     ],[
46       ac_cv_header_windows_h="no"
47     ])
48   ])
49   if test "x$ac_cv_header_windows_h" = "xyes"; then
50     AC_DEFINE_UNQUOTED(HAVE_WINDOWS_H, 1,
51       [Define to 1 if you have the windows.h header file.])
52     AC_DEFINE_UNQUOTED(WIN32_LEAN_AND_MEAN, 1,
53       [Define to avoid automatic inclusion of winsock.h])
54   fi
55 ])
56
57
58 dnl CURL_CHECK_HEADER_WINSOCK
59 dnl -------------------------------------------------
60 dnl Check for compilable and valid winsock.h header 
61
62 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK], [
63   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
64   AC_CACHE_CHECK([for winsock.h], [ac_cv_header_winsock_h], [
65     AC_COMPILE_IFELSE([
66       AC_LANG_PROGRAM([
67 #undef inline
68 #ifndef WIN32_LEAN_AND_MEAN
69 #define WIN32_LEAN_AND_MEAN
70 #endif
71 #include <windows.h>
72 #include <winsock.h>
73       ],[
74 #ifdef __CYGWIN__
75         HAVE_WINSOCK_H shall not be defined.
76 #else
77         int dummy=WSACleanup();
78 #endif
79       ])
80     ],[
81       ac_cv_header_winsock_h="yes"
82     ],[
83       ac_cv_header_winsock_h="no"
84     ])
85   ])
86   if test "x$ac_cv_header_winsock_h" = "xyes"; then
87     AC_DEFINE_UNQUOTED(HAVE_WINSOCK_H, 1,
88       [Define to 1 if you have the winsock.h header file.])
89   fi
90 ])
91
92
93 dnl CURL_CHECK_HEADER_WINSOCK2
94 dnl -------------------------------------------------
95 dnl Check for compilable and valid winsock2.h header 
96
97 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK2], [
98   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
99   AC_CACHE_CHECK([for winsock2.h], [ac_cv_header_winsock2_h], [
100     AC_COMPILE_IFELSE([
101       AC_LANG_PROGRAM([
102 #undef inline
103 #ifndef WIN32_LEAN_AND_MEAN
104 #define WIN32_LEAN_AND_MEAN
105 #endif
106 #include <windows.h>
107 #include <winsock2.h>
108       ],[
109 #ifdef __CYGWIN__
110         HAVE_WINSOCK2_H shall not be defined.
111 #else
112         int dummy=2*IPPROTO_ESP;
113 #endif
114       ])
115     ],[
116       ac_cv_header_winsock2_h="yes"
117     ],[
118       ac_cv_header_winsock2_h="no"
119     ])
120   ])
121   if test "x$ac_cv_header_winsock2_h" = "xyes"; then
122     AC_DEFINE_UNQUOTED(HAVE_WINSOCK2_H, 1,
123       [Define to 1 if you have the winsock2.h header file.])
124   fi
125 ])
126
127
128 dnl CURL_CHECK_HEADER_WS2TCPIP
129 dnl -------------------------------------------------
130 dnl Check for compilable and valid ws2tcpip.h header
131
132 AC_DEFUN([CURL_CHECK_HEADER_WS2TCPIP], [
133   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
134   AC_CACHE_CHECK([for ws2tcpip.h], [ac_cv_header_ws2tcpip_h], [
135     AC_COMPILE_IFELSE([
136       AC_LANG_PROGRAM([
137 #undef inline
138 #ifndef WIN32_LEAN_AND_MEAN
139 #define WIN32_LEAN_AND_MEAN
140 #endif
141 #include <windows.h>
142 #include <winsock2.h>
143 #include <ws2tcpip.h>
144       ],[
145 #ifdef __CYGWIN__
146         HAVE_WS2TCPIP_H shall not be defined.
147 #else
148         int dummy=2*IP_PKTINFO;
149 #endif
150       ])
151     ],[
152       ac_cv_header_ws2tcpip_h="yes"
153     ],[
154       ac_cv_header_ws2tcpip_h="no"
155     ])
156   ])
157   if test "x$ac_cv_header_ws2tcpip_h" = "xyes"; then
158     AC_DEFINE_UNQUOTED(HAVE_WS2TCPIP_H, 1,
159       [Define to 1 if you have the ws2tcpip.h header file.])
160   fi
161 ])
162
163
164 dnl CURL_CHECK_TYPE_SOCKLEN_T
165 dnl -------------------------------------------------
166 dnl Check for existing socklen_t type, and provide
167 dnl an equivalent type if socklen_t not available
168
169 AC_DEFUN([CURL_CHECK_TYPE_SOCKLEN_T], [
170   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
171   AC_CHECK_TYPE([socklen_t], ,[
172     AC_CACHE_CHECK([for socklen_t equivalent], 
173       [curl_cv_socklen_t_equiv], [
174       curl_cv_socklen_t_equiv="unknown"
175       for arg2 in "struct sockaddr" void; do
176         for t in int size_t unsigned long "unsigned long"; do
177           AC_COMPILE_IFELSE([
178             AC_LANG_PROGRAM([
179 #undef inline
180 #ifdef HAVE_WINDOWS_H
181 #ifndef WIN32_LEAN_AND_MEAN
182 #define WIN32_LEAN_AND_MEAN
183 #endif
184 #include <windows.h>
185 #ifdef HAVE_WINSOCK2_H
186 #include <winsock2.h>
187 #else
188 #ifdef HAVE_WINSOCK_H
189 #include <winsock.h>
190 #endif
191 #endif
192 #else
193 #ifdef HAVE_SYS_TYPES_H
194 #include <sys/types.h>
195 #endif
196 #ifdef HAVE_SYS_SOCKET_H
197 #include <sys/socket.h>
198 #endif
199 #endif
200               int getpeername (int, $arg2 *, $t *);
201             ],[
202               $t len=0;
203               getpeername(0,0,&len);
204             ])
205           ],[
206              curl_cv_socklen_t_equiv="$t"
207              break 2
208           ])
209         done
210       done
211     ])
212     if test "$curl_cv_socklen_t_equiv" = "unknown"; then
213       AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
214     else
215       AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
216         [type to use in place of socklen_t if not defined])
217     fi
218   ],[
219 #undef inline
220 #ifdef HAVE_WINDOWS_H
221 #ifndef WIN32_LEAN_AND_MEAN
222 #define WIN32_LEAN_AND_MEAN
223 #endif
224 #include <windows.h>
225 #ifdef HAVE_WINSOCK2_H
226 #include <winsock2.h>
227 #ifdef HAVE_WS2TCPIP_H
228 #include <ws2tcpip.h>
229 #endif
230 #endif
231 #else
232 #ifdef HAVE_SYS_TYPES_H
233 #include <sys/types.h>
234 #endif
235 #ifdef HAVE_SYS_SOCKET_H
236 #include <sys/socket.h>
237 #endif
238 #endif
239   ])
240 ])
241
242
243 dnl CURL_CHECK_FUNC_GETNAMEINFO
244 dnl -------------------------------------------------
245 dnl Test if the getnameinfo function is available, 
246 dnl and check the types of five of its arguments.
247 dnl If the function succeeds HAVE_GETNAMEINFO will be
248 dnl defined, defining the types of the arguments in
249 dnl GETNAMEINFO_TYPE_ARG1, GETNAMEINFO_TYPE_ARG2,
250 dnl GETNAMEINFO_TYPE_ARG46 and GETNAMEINFO_TYPE_ARG7,
251 dnl and also defining the type qualifier of first 
252 dnl argument in GETNAMEINFO_QUAL_ARG1.
253
254 AC_DEFUN([CURL_CHECK_FUNC_GETNAMEINFO], [
255   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
256   AC_REQUIRE([CURL_CHECK_TYPE_SOCKLEN_T])dnl
257   CURL_CHECK_HEADERS_ONCE(sys/types.h sys/socket.h netdb.h)
258   #
259   AC_MSG_CHECKING([for getnameinfo])
260   AC_LINK_IFELSE([
261       AC_LANG_FUNC_LINK_TRY([getnameinfo])
262     ],[
263       AC_MSG_RESULT([yes])
264       curl_cv_getnameinfo="yes"
265     ],[
266       AC_MSG_RESULT([no])
267       curl_cv_getnameinfo="no"
268   ])
269   #
270   if test "$curl_cv_getnameinfo" != "yes"; then
271     AC_MSG_CHECKING([deeper for getnameinfo])
272     AC_TRY_LINK([
273       ],[
274         getnameinfo();
275       ],[
276         AC_MSG_RESULT([yes])
277         curl_cv_getnameinfo="yes"
278       ],[
279         AC_MSG_RESULT([but still no])
280         curl_cv_getnameinfo="no"
281     ])
282   fi
283   #
284   if test "$curl_cv_getnameinfo" != "yes"; then
285     AC_MSG_CHECKING([deeper and deeper for getnameinfo])
286     AC_TRY_LINK([
287 #undef inline
288 #ifdef HAVE_WINDOWS_H
289 #ifndef WIN32_LEAN_AND_MEAN
290 #define WIN32_LEAN_AND_MEAN
291 #endif
292 #include <windows.h>
293 #ifdef HAVE_WINSOCK2_H
294 #include <winsock2.h>
295 #ifdef HAVE_WS2TCPIP_H
296 #include <ws2tcpip.h>
297 #endif
298 #endif
299 #else
300 #ifdef HAVE_SYS_TYPES_H
301 #include <sys/types.h>
302 #endif
303 #ifdef HAVE_SYS_SOCKET_H
304 #include <sys/socket.h>
305 #endif
306 #ifdef HAVE_NETDB_H
307 #include <netdb.h>
308 #endif
309 #endif
310       ],[
311         getnameinfo(0, 0, 0, 0, 0, 0, 0);
312       ],[ 
313         AC_MSG_RESULT([yes])
314         curl_cv_getnameinfo="yes"
315       ],[
316         AC_MSG_RESULT([but still no])
317         curl_cv_getnameinfo="no"
318     ])
319   fi
320   #
321   if test "$curl_cv_getnameinfo" = "yes"; then
322     AC_CACHE_CHECK([types of arguments for getnameinfo],
323       [curl_cv_func_getnameinfo_args], [
324       curl_cv_func_getnameinfo_args="unknown"
325       for gni_arg1 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
326         for gni_arg2 in 'socklen_t' 'size_t' 'int'; do
327           for gni_arg46 in 'size_t' 'int' 'socklen_t' 'unsigned int' 'DWORD'; do
328             for gni_arg7 in 'int' 'unsigned int'; do
329               AC_COMPILE_IFELSE([
330                 AC_LANG_PROGRAM([
331 #undef inline 
332 #ifdef HAVE_WINDOWS_H
333 #ifndef WIN32_LEAN_AND_MEAN
334 #define WIN32_LEAN_AND_MEAN
335 #endif
336 #if (!defined(_WIN32_WINNT)) || (_WIN32_WINNT < 0x0501)
337 #undef _WIN32_WINNT
338 #define _WIN32_WINNT 0x0501
339 #endif
340 #include <windows.h>
341 #ifdef HAVE_WINSOCK2_H
342 #include <winsock2.h> 
343 #ifdef HAVE_WS2TCPIP_H
344 #include <ws2tcpip.h>
345 #endif
346 #endif
347 #define GNICALLCONV WSAAPI
348 #else
349 #ifdef HAVE_SYS_TYPES_H
350 #include <sys/types.h>
351 #endif
352 #ifdef HAVE_SYS_SOCKET_H
353 #include <sys/socket.h>
354 #endif
355 #ifdef HAVE_NETDB_H
356 #include <netdb.h>
357 #endif
358 #define GNICALLCONV
359 #endif
360                   extern int GNICALLCONV getnameinfo($gni_arg1, $gni_arg2,
361                                          char *, $gni_arg46,
362                                          char *, $gni_arg46,
363                                          $gni_arg7);
364                 ],[
365                   $gni_arg2 salen=0;
366                   $gni_arg46 hostlen=0;
367                   $gni_arg46 servlen=0;
368                   $gni_arg7 flags=0;
369                   int res = getnameinfo(0, salen, 0, hostlen, 0, servlen, flags);
370                 ])
371               ],[
372                  curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7"
373                  break 4
374               ])
375             done
376           done
377         done
378       done
379     ]) # AC_CACHE_CHECK
380     if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
381       AC_MSG_WARN([Cannot find proper types to use for getnameinfo args])
382       AC_MSG_WARN([HAVE_GETNAMEINFO will not be defined])
383     else
384       gni_prev_IFS=$IFS; IFS=','
385       set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'`
386       IFS=$gni_prev_IFS
387       shift
388       #
389       gni_qual_type_arg1=$[1]
390       #
391       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2],
392         [Define to the type of arg 2 for getnameinfo.])
393       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3],
394         [Define to the type of args 4 and 6 for getnameinfo.])
395       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4],
396         [Define to the type of arg 7 for getnameinfo.])
397       #
398       prev_sh_opts=$-
399       #
400       case $prev_sh_opts in
401         *f*)
402           ;;
403         *)
404           set -f
405           ;;
406       esac
407       #
408       case "$gni_qual_type_arg1" in
409         const*)
410           gni_qual_arg1=const
411           gni_type_arg1=`echo $gni_qual_type_arg1 | sed 's/^const //'`
412         ;;
413         *)
414           gni_qual_arg1=
415           gni_type_arg1=$gni_qual_type_arg1
416         ;;
417       esac
418       #
419       AC_DEFINE_UNQUOTED(GETNAMEINFO_QUAL_ARG1, $gni_qual_arg1,
420         [Define to the type qualifier of arg 1 for getnameinfo.])
421       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $gni_type_arg1,
422         [Define to the type of arg 1 for getnameinfo.])
423       #
424       case $prev_sh_opts in
425         *f*)
426           ;;
427         *)
428           set +f
429           ;;
430       esac
431       #
432       AC_DEFINE_UNQUOTED(HAVE_GETNAMEINFO, 1,
433         [Define to 1 if you have the getnameinfo function.])
434       ac_cv_func_getnameinfo="yes"
435     fi
436   fi
437 ]) # AC_DEFUN
438
439
440 dnl TYPE_SOCKADDR_STORAGE
441 dnl -------------------------------------------------
442 dnl Check for struct sockaddr_storage. Most IPv6-enabled 
443 dnl hosts have it, but AIX 4.3 is one known exception.
444
445 AC_DEFUN([TYPE_SOCKADDR_STORAGE],
446 [
447    AC_CHECK_TYPE([struct sockaddr_storage],
448         AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
449                   [if struct sockaddr_storage is defined]), ,
450    [
451 #undef inline
452 #ifdef HAVE_WINDOWS_H
453 #ifndef WIN32_LEAN_AND_MEAN
454 #define WIN32_LEAN_AND_MEAN
455 #endif
456 #include <windows.h>
457 #ifdef HAVE_WINSOCK2_H
458 #include <winsock2.h>
459 #endif
460 #else
461 #ifdef HAVE_SYS_TYPES_H
462 #include <sys/types.h>
463 #endif
464 #ifdef HAVE_SYS_SOCKET_H
465 #include <sys/socket.h>
466 #endif
467 #ifdef HAVE_NETINET_IN_H
468 #include <netinet/in.h>
469 #endif
470 #ifdef HAVE_ARPA_INET_H
471 #include <arpa/inet.h>
472 #endif
473 #endif
474    ])
475 ])
476
477
478 dnl CURL_CHECK_NI_WITHSCOPEID
479 dnl -------------------------------------------------
480 dnl Check for working NI_WITHSCOPEID in getnameinfo()
481
482 AC_DEFUN([CURL_CHECK_NI_WITHSCOPEID], [
483   AC_REQUIRE([CURL_CHECK_FUNC_GETNAMEINFO])dnl
484   AC_REQUIRE([TYPE_SOCKADDR_STORAGE])dnl
485   CURL_CHECK_HEADERS_ONCE(stdio.h sys/types.h sys/socket.h \
486                    netdb.h netinet/in.h arpa/inet.h)
487   #
488   AC_CACHE_CHECK([for working NI_WITHSCOPEID], 
489     [ac_cv_working_ni_withscopeid], [
490     AC_RUN_IFELSE([
491       AC_LANG_PROGRAM([
492 #ifdef HAVE_STDIO_H
493 #include <stdio.h>
494 #endif
495 #ifdef HAVE_SYS_TYPES_H
496 #include <sys/types.h>
497 #endif
498 #ifdef HAVE_SYS_SOCKET_H
499 #include <sys/socket.h>
500 #endif
501 #ifdef HAVE_NETDB_H
502 #include <netdb.h>
503 #endif
504 #ifdef HAVE_NETINET_IN_H
505 #include <netinet/in.h>
506 #endif
507 #ifdef HAVE_ARPA_INET_H
508 #include <arpa/inet.h>
509 #endif
510       ],[
511 #if defined(NI_WITHSCOPEID) && defined(HAVE_GETNAMEINFO)
512 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE
513         struct sockaddr_storage sa;
514 #else
515         unsigned char sa[256];
516 #endif
517         char hostbuf[NI_MAXHOST];
518         int rc;
519         GETNAMEINFO_TYPE_ARG2 salen = (GETNAMEINFO_TYPE_ARG2)sizeof(sa);
520         GETNAMEINFO_TYPE_ARG46 hostlen = (GETNAMEINFO_TYPE_ARG46)sizeof(hostbuf);
521         GETNAMEINFO_TYPE_ARG7 flags = NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
522         int fd = socket(AF_INET6, SOCK_STREAM, 0);
523         if(fd < 0) {
524           perror("socket()");
525           return 1; /* Error creating socket */
526         }
527         rc = getsockname(fd, (GETNAMEINFO_TYPE_ARG1)&sa, &salen);
528         if(rc) {
529           perror("getsockname()");
530           return 2; /* Error retrieving socket name */
531         }
532         rc = getnameinfo((GETNAMEINFO_TYPE_ARG1)&sa, salen, hostbuf, hostlen, NULL, 0, flags);
533         if(rc) {
534           printf("rc = %s\n", gai_strerror(rc));
535           return 3; /* Error translating socket address */
536         }
537         return 0; /* Ok, NI_WITHSCOPEID works */
538 #else
539         return 4; /* Error, NI_WITHSCOPEID not defined or no getnameinfo() */
540 #endif
541       ]) # AC_LANG_PROGRAM
542     ],[
543       # Exit code == 0. Program worked.
544       ac_cv_working_ni_withscopeid="yes"
545     ],[
546       # Exit code != 0. Program failed.
547       ac_cv_working_ni_withscopeid="no"
548     ],[
549       # Program is not run when cross-compiling. So we assume
550       # NI_WITHSCOPEID will work if we are able to compile it.
551       AC_COMPILE_IFELSE([
552         AC_LANG_PROGRAM([
553 #include <sys/types.h>
554 #include <sys/socket.h>
555 #include <netdb.h>
556         ],[
557           unsigned int dummy= NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
558         ])
559       ],[
560         ac_cv_working_ni_withscopeid="yes"
561       ],[
562         ac_cv_working_ni_withscopeid="no"
563       ]) # AC_COMPILE_IFELSE
564     ]) # AC_RUN_IFELSE
565   ]) # AC_CACHE_CHECK
566   if test "x$ac_cv_working_ni_withscopeid" = "xyes"; then
567     AC_DEFINE(HAVE_NI_WITHSCOPEID, 1,
568       [Define to 1 if NI_WITHSCOPEID exists and works.])
569   fi
570 ]) # AC_DEFUN
571
572
573 dnl CURL_CHECK_FUNC_RECV
574 dnl -------------------------------------------------
575 dnl Test if the socket recv() function is available, 
576 dnl and check its return type and the types of its 
577 dnl arguments. If the function succeeds HAVE_RECV 
578 dnl will be defined, defining the types of the arguments 
579 dnl in RECV_TYPE_ARG1, RECV_TYPE_ARG2, RECV_TYPE_ARG3 
580 dnl and RECV_TYPE_ARG4, defining the type of the function
581 dnl return value in RECV_TYPE_RETV.
582
583 AC_DEFUN([CURL_CHECK_FUNC_RECV], [
584   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
585   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
586   CURL_CHECK_HEADERS_ONCE(sys/types.h sys/socket.h)
587   #
588   AC_MSG_CHECKING([for recv])
589   AC_TRY_LINK([
590 #undef inline 
591 #ifdef HAVE_WINDOWS_H
592 #ifndef WIN32_LEAN_AND_MEAN
593 #define WIN32_LEAN_AND_MEAN
594 #endif
595 #include <windows.h>
596 #ifdef HAVE_WINSOCK2_H
597 #include <winsock2.h>
598 #else
599 #ifdef HAVE_WINSOCK_H
600 #include <winsock.h>
601 #endif
602 #endif
603 #else
604 #ifdef HAVE_SYS_TYPES_H
605 #include <sys/types.h>
606 #endif
607 #ifdef HAVE_SYS_SOCKET_H
608 #include <sys/socket.h>
609 #endif
610 #endif
611     ],[
612       recv(0, 0, 0, 0);
613     ],[ 
614       AC_MSG_RESULT([yes])
615       curl_cv_recv="yes"
616     ],[
617       AC_MSG_RESULT([no])
618       curl_cv_recv="no"
619   ])
620   #
621   if test "$curl_cv_recv" = "yes"; then
622     AC_CACHE_CHECK([types of arguments and return type for recv],
623       [curl_cv_func_recv_args], [
624       curl_cv_func_recv_args="unknown"
625       for recv_retv in 'int' 'ssize_t'; do
626         for recv_arg1 in 'int' 'ssize_t' 'SOCKET'; do
627           for recv_arg2 in 'char *' 'void *'; do
628             for recv_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
629               for recv_arg4 in 'int' 'unsigned int'; do
630                 AC_COMPILE_IFELSE([
631                   AC_LANG_PROGRAM([
632 #undef inline 
633 #ifdef HAVE_WINDOWS_H
634 #ifndef WIN32_LEAN_AND_MEAN
635 #define WIN32_LEAN_AND_MEAN
636 #endif
637 #include <windows.h>
638 #ifdef HAVE_WINSOCK2_H
639 #include <winsock2.h>
640 #else
641 #ifdef HAVE_WINSOCK_H
642 #include <winsock.h>
643 #endif
644 #endif
645 #define RECVCALLCONV PASCAL
646 #else
647 #ifdef HAVE_SYS_TYPES_H
648 #include <sys/types.h>
649 #endif
650 #ifdef HAVE_SYS_SOCKET_H
651 #include <sys/socket.h>
652 #endif
653 #define RECVCALLCONV
654 #endif
655                     extern $recv_retv RECVCALLCONV recv($recv_arg1, $recv_arg2, $recv_arg3, $recv_arg4);
656                   ],[
657                     $recv_arg1 s=0;
658                     $recv_arg2 buf=0;
659                     $recv_arg3 len=0;
660                     $recv_arg4 flags=0;
661                     $recv_retv res = recv(s, buf, len, flags);
662                   ])
663                 ],[
664                    curl_cv_func_recv_args="$recv_arg1,$recv_arg2,$recv_arg3,$recv_arg4,$recv_retv"
665                    break 5
666                 ])
667               done
668             done
669           done
670         done
671       done
672     ]) # AC_CACHE_CHECK
673     if test "$curl_cv_func_recv_args" = "unknown"; then
674       AC_MSG_WARN([Cannot find proper types to use for recv args])
675       AC_MSG_WARN([HAVE_RECV will not be defined])
676     else
677       recv_prev_IFS=$IFS; IFS=','
678       set dummy `echo "$curl_cv_func_recv_args" | sed 's/\*/\*/g'`
679       IFS=$recv_prev_IFS
680       shift
681       #
682       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG1, $[1],
683         [Define to the type of arg 1 for recv.])
684       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG2, $[2],
685         [Define to the type of arg 2 for recv.])
686       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG3, $[3],
687         [Define to the type of arg 3 for recv.])
688       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG4, $[4],
689         [Define to the type of arg 4 for recv.])
690       AC_DEFINE_UNQUOTED(RECV_TYPE_RETV, $[5],
691         [Define to the function return type for recv.])
692       #
693       AC_DEFINE_UNQUOTED(HAVE_RECV, 1,
694         [Define to 1 if you have the recv function.])
695       ac_cv_func_recv="yes"
696     fi
697   fi
698 ]) # AC_DEFUN
699
700
701 dnl CURL_CHECK_FUNC_SEND
702 dnl -------------------------------------------------
703 dnl Test if the socket send() function is available, 
704 dnl and check its return type and the types of its 
705 dnl arguments. If the function succeeds HAVE_SEND 
706 dnl will be defined, defining the types of the arguments 
707 dnl in SEND_TYPE_ARG1, SEND_TYPE_ARG2, SEND_TYPE_ARG3 
708 dnl and SEND_TYPE_ARG4, defining the type of the function
709 dnl return value in SEND_TYPE_RETV, and also defining the 
710 dnl type qualifier of second argument in SEND_QUAL_ARG2.
711
712 AC_DEFUN([CURL_CHECK_FUNC_SEND], [
713   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
714   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
715   CURL_CHECK_HEADERS_ONCE(sys/types.h sys/socket.h)
716   #
717   AC_MSG_CHECKING([for send])
718   AC_TRY_LINK([
719 #undef inline 
720 #ifdef HAVE_WINDOWS_H
721 #ifndef WIN32_LEAN_AND_MEAN
722 #define WIN32_LEAN_AND_MEAN
723 #endif
724 #include <windows.h>
725 #ifdef HAVE_WINSOCK2_H
726 #include <winsock2.h>
727 #else
728 #ifdef HAVE_WINSOCK_H
729 #include <winsock.h>
730 #endif
731 #endif
732 #else
733 #ifdef HAVE_SYS_TYPES_H
734 #include <sys/types.h>
735 #endif
736 #ifdef HAVE_SYS_SOCKET_H
737 #include <sys/socket.h>
738 #endif
739 #endif
740     ],[
741       send(0, 0, 0, 0);
742     ],[ 
743       AC_MSG_RESULT([yes])
744       curl_cv_send="yes"
745     ],[
746       AC_MSG_RESULT([no])
747       curl_cv_send="no"
748   ])
749   #
750   if test "$curl_cv_send" = "yes"; then
751     AC_CACHE_CHECK([types of arguments and return type for send],
752       [curl_cv_func_send_args], [
753       curl_cv_func_send_args="unknown"
754       for send_retv in 'int' 'ssize_t'; do
755         for send_arg1 in 'int' 'ssize_t' 'SOCKET'; do
756           for send_arg2 in 'char *' 'void *' 'const char *' 'const void *'; do
757             for send_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
758               for send_arg4 in 'int' 'unsigned int'; do
759                 AC_COMPILE_IFELSE([
760                   AC_LANG_PROGRAM([
761 #undef inline 
762 #ifdef HAVE_WINDOWS_H
763 #ifndef WIN32_LEAN_AND_MEAN
764 #define WIN32_LEAN_AND_MEAN
765 #endif
766 #include <windows.h>
767 #ifdef HAVE_WINSOCK2_H
768 #include <winsock2.h>
769 #else
770 #ifdef HAVE_WINSOCK_H
771 #include <winsock.h>
772 #endif
773 #endif
774 #define SENDCALLCONV PASCAL
775 #else
776 #ifdef HAVE_SYS_TYPES_H
777 #include <sys/types.h>
778 #endif
779 #ifdef HAVE_SYS_SOCKET_H
780 #include <sys/socket.h>
781 #endif
782 #define SENDCALLCONV
783 #endif
784                     extern $send_retv SENDCALLCONV send($send_arg1, $send_arg2, $send_arg3, $send_arg4);
785                   ],[
786                     $send_arg1 s=0;
787                     $send_arg3 len=0;
788                     $send_arg4 flags=0;
789                     $send_retv res = send(s, 0, len, flags);
790                   ])
791                 ],[
792                    curl_cv_func_send_args="$send_arg1,$send_arg2,$send_arg3,$send_arg4,$send_retv"
793                    break 5
794                 ])
795               done
796             done
797           done
798         done
799       done
800     ]) # AC_CACHE_CHECK
801     if test "$curl_cv_func_send_args" = "unknown"; then
802       AC_MSG_WARN([Cannot find proper types to use for send args])
803       AC_MSG_WARN([HAVE_SEND will not be defined])
804     else
805       send_prev_IFS=$IFS; IFS=','
806       set dummy `echo "$curl_cv_func_send_args" | sed 's/\*/\*/g'`
807       IFS=$send_prev_IFS
808       shift
809       #
810       send_qual_type_arg2=$[2]
811       #
812       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG1, $[1],
813         [Define to the type of arg 1 for send.])
814       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG3, $[3],
815         [Define to the type of arg 3 for send.])
816       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG4, $[4],
817         [Define to the type of arg 4 for send.])
818       AC_DEFINE_UNQUOTED(SEND_TYPE_RETV, $[5],
819         [Define to the function return type for send.])
820       #
821       prev_sh_opts=$-
822       #
823       case $prev_sh_opts in
824         *f*)
825           ;;
826         *)
827           set -f
828           ;;
829       esac
830       #
831       case "$send_qual_type_arg2" in
832         const*)
833           send_qual_arg2=const
834           send_type_arg2=`echo $send_qual_type_arg2 | sed 's/^const //'`
835         ;;
836         *)
837           send_qual_arg2=
838           send_type_arg2=$send_qual_type_arg2
839         ;;
840       esac
841       #
842       AC_DEFINE_UNQUOTED(SEND_QUAL_ARG2, $send_qual_arg2,
843         [Define to the type qualifier of arg 2 for send.])
844       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG2, $send_type_arg2,
845         [Define to the type of arg 2 for send.])
846       #
847       case $prev_sh_opts in
848         *f*)
849           ;;
850         *)
851           set +f
852           ;;
853       esac
854       #
855       AC_DEFINE_UNQUOTED(HAVE_SEND, 1,
856         [Define to 1 if you have the send function.])
857       ac_cv_func_send="yes"
858     fi
859   fi
860 ]) # AC_DEFUN
861
862
863 dnl CURL_CHECK_NONBLOCKING_SOCKET
864 dnl -------------------------------------------------
865 dnl Check for how to set a socket to non-blocking state. There seems to exist
866 dnl four known different ways, with the one used almost everywhere being POSIX
867 dnl and XPG3, while the other different ways for different systems (old BSD,
868 dnl Windows and Amiga).
869 dnl
870 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
871 dnl O_NONBLOCK define is found but does not work. This condition is attempted
872 dnl to get caught in this script by using an excessive number of #ifdefs...
873 dnl
874 AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
875 [
876   AC_MSG_CHECKING([non-blocking sockets style])
877
878   AC_TRY_COMPILE([
879 /* headers for O_NONBLOCK test */
880 #include <sys/types.h>
881 #include <unistd.h>
882 #include <fcntl.h>
883 ],[
884 /* try to compile O_NONBLOCK */
885
886 #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
887 # if defined(__SVR4) || defined(__srv4__)
888 #  define PLATFORM_SOLARIS
889 # else
890 #  define PLATFORM_SUNOS4
891 # endif
892 #endif
893 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
894 # define PLATFORM_AIX_V3
895 #endif
896
897 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
898 #error "O_NONBLOCK does not work on this platform"
899 #endif
900   int socket;
901   int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
902 ],[
903 dnl the O_NONBLOCK test was fine
904 nonblock="O_NONBLOCK"
905 AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
906 ],[
907 dnl the code was bad, try a different program now, test 2
908
909   AC_TRY_COMPILE([
910 /* headers for FIONBIO test */
911 #include <unistd.h>
912 #include <stropts.h>
913 ],[
914 /* FIONBIO source test (old-style unix) */
915  int socket;
916  int flags = ioctl(socket, FIONBIO, &flags);
917 ],[
918 dnl FIONBIO test was good
919 nonblock="FIONBIO"
920 AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
921 ],[
922 dnl FIONBIO test was also bad
923 dnl the code was bad, try a different program now, test 3
924
925   AC_TRY_COMPILE([
926 /* headers for ioctlsocket test (Windows) */
927 #undef inline
928 #ifdef HAVE_WINDOWS_H
929 #ifndef WIN32_LEAN_AND_MEAN
930 #define WIN32_LEAN_AND_MEAN
931 #endif
932 #include <windows.h>
933 #ifdef HAVE_WINSOCK2_H
934 #include <winsock2.h>
935 #else
936 #ifdef HAVE_WINSOCK_H
937 #include <winsock.h>
938 #endif
939 #endif
940 #endif
941 ],[
942 /* ioctlsocket source code */
943  SOCKET sd;
944  unsigned long flags = 0;
945  sd = socket(0, 0, 0);
946  ioctlsocket(sd, FIONBIO, &flags);
947 ],[
948 dnl ioctlsocket test was good
949 nonblock="ioctlsocket"
950 AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets])
951 ],[
952 dnl ioctlsocket didnt compile!, go to test 4
953
954   AC_TRY_LINK([
955 /* headers for IoctlSocket test (Amiga?) */
956 #include <sys/ioctl.h>
957 ],[
958 /* IoctlSocket source code */
959  int socket;
960  int flags = IoctlSocket(socket, FIONBIO, (long)1);
961 ],[
962 dnl ioctlsocket test was good
963 nonblock="IoctlSocket"
964 AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
965 ],[
966 dnl Ioctlsocket didnt compile, do test 5!
967   AC_TRY_COMPILE([
968 /* headers for SO_NONBLOCK test (BeOS) */
969 #include <socket.h>
970 ],[
971 /* SO_NONBLOCK source code */
972  long b = 1;
973  int socket;
974  int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
975 ],[
976 dnl the SO_NONBLOCK test was good
977 nonblock="SO_NONBLOCK"
978 AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])
979 ],[
980 dnl test 5 didnt compile!
981 nonblock="nada"
982 AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets])
983 ])
984 dnl end of fifth test
985
986 ])
987 dnl end of forth test
988
989 ])
990 dnl end of third test
991
992 ])
993 dnl end of second test
994
995 ])
996 dnl end of non-blocking try-compile test
997   AC_MSG_RESULT($nonblock)
998
999   if test "$nonblock" = "nada"; then
1000     AC_MSG_WARN([non-block sockets disabled])
1001   fi
1002 ])
1003
1004
1005 dnl TYPE_SOCKADDR_STORAGE
1006 dnl -------------------------------------------------
1007 dnl Check for struct sockaddr_storage. Most IPv6-enabled hosts have it, but
1008 dnl AIX 4.3 is one known exception.
1009 AC_DEFUN([TYPE_SOCKADDR_STORAGE],
1010 [
1011    AC_CHECK_TYPE([struct sockaddr_storage],
1012         AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
1013                   [if struct sockaddr_storage is defined]), ,
1014    [
1015 #undef inline
1016 #ifdef HAVE_WINDOWS_H
1017 #ifndef WIN32_LEAN_AND_MEAN
1018 #define WIN32_LEAN_AND_MEAN
1019 #endif
1020 #include <windows.h>
1021 #ifdef HAVE_WINSOCK2_H
1022 #include <winsock2.h>
1023 #endif
1024 #else
1025 #ifdef HAVE_SYS_TYPES_H
1026 #include <sys/types.h>
1027 #endif
1028 #ifdef HAVE_SYS_SOCKET_H
1029 #include <sys/socket.h>
1030 #endif
1031 #ifdef HAVE_NETINET_IN_H
1032 #include <netinet/in.h>
1033 #endif
1034 #ifdef HAVE_ARPA_INET_H
1035 #include <arpa/inet.h>
1036 #endif
1037 #endif
1038    ])
1039 ])
1040
1041
1042 dnl TYPE_IN_ADDR_T
1043 dnl -------------------------------------------------
1044 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
1045 dnl and a few other things.
1046 AC_DEFUN([TYPE_IN_ADDR_T],
1047 [
1048    AC_CHECK_TYPE([in_addr_t], ,[
1049       AC_MSG_CHECKING([for in_addr_t equivalent])
1050       AC_CACHE_VAL([curl_cv_in_addr_t_equiv],
1051       [
1052          curl_cv_in_addr_t_equiv=
1053          for t in "unsigned long" int size_t unsigned long; do
1054             AC_TRY_COMPILE([
1055 #undef inline
1056 #ifdef HAVE_WINDOWS_H
1057 #ifndef WIN32_LEAN_AND_MEAN
1058 #define WIN32_LEAN_AND_MEAN
1059 #endif
1060 #include <windows.h>
1061 #ifdef HAVE_WINSOCK2_H
1062 #include <winsock2.h>
1063 #else
1064 #ifdef HAVE_WINSOCK_H
1065 #include <winsock.h>
1066 #endif
1067 #endif
1068 #else
1069 #ifdef HAVE_SYS_TYPES_H
1070 #include <sys/types.h>
1071 #endif
1072 #ifdef HAVE_SYS_SOCKET_H
1073 #include <sys/socket.h>
1074 #endif
1075 #ifdef HAVE_NETINET_IN_H
1076 #include <netinet/in.h>
1077 #endif
1078 #ifdef HAVE_ARPA_INET_H
1079 #include <arpa/inet.h>
1080 #endif
1081 #endif
1082             ],[
1083                $t data = inet_addr ("1.2.3.4");
1084             ],[
1085                curl_cv_in_addr_t_equiv="$t"
1086                break
1087             ])
1088          done
1089
1090          if test "x$curl_cv_in_addr_t_equiv" = x; then
1091             AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
1092          fi
1093       ])
1094       AC_MSG_RESULT($curl_cv_in_addr_t_equiv)
1095       AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
1096                         [type to use in place of in_addr_t if not defined])],
1097       [
1098 #undef inline
1099 #ifdef HAVE_WINDOWS_H
1100 #ifndef WIN32_LEAN_AND_MEAN
1101 #define WIN32_LEAN_AND_MEAN
1102 #endif
1103 #include <windows.h>
1104 #ifdef HAVE_WINSOCK2_H
1105 #include <winsock2.h>
1106 #else
1107 #ifdef HAVE_WINSOCK_H
1108 #include <winsock.h>
1109 #endif
1110 #endif
1111 #else
1112 #ifdef HAVE_SYS_TYPES_H
1113 #include <sys/types.h>
1114 #endif
1115 #ifdef HAVE_SYS_SOCKET_H
1116 #include <sys/socket.h>
1117 #endif
1118 #ifdef HAVE_NETINET_IN_H
1119 #include <netinet/in.h>
1120 #endif
1121 #ifdef HAVE_ARPA_INET_H
1122 #include <arpa/inet.h>
1123 #endif
1124
1125 #endif
1126   ]) dnl AC_CHECK_TYPE
1127 ]) dnl AC_DEFUN
1128
1129
1130 dnl We create a function for detecting which compiler we use and then set as
1131 dnl pendantic compiler options as possible for that particular compiler. The
1132 dnl options are only used for debug-builds.
1133
1134 dnl This is a copy of the original found in curl's configure script. Don't
1135 dnl modify this one, edit the one in curl and copy it back here when that one
1136 dnl is changed.
1137
1138 AC_DEFUN([CURL_CC_DEBUG_OPTS],
1139 [
1140     if test "$GCC" = "yes"; then
1141
1142        dnl figure out gcc version!
1143        AC_MSG_CHECKING([gcc version])
1144        gccver=`$CC -dumpversion`
1145        num1=`echo $gccver | cut -d . -f1`
1146        num2=`echo $gccver | cut -d . -f2`
1147        gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
1148        AC_MSG_RESULT($gccver)
1149
1150        AC_MSG_CHECKING([if this is icc in disguise])
1151        AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
1152          dnl action if the text is found, this it has not been replaced by the
1153          dnl cpp
1154          ICC="no"
1155          AC_MSG_RESULT([no]),
1156          dnl the text was not found, it was replaced by the cpp
1157          ICC="yes"
1158          AC_MSG_RESULT([yes])
1159        )
1160
1161        if test "$ICC" = "yes"; then
1162          dnl this is icc, not gcc.
1163
1164          dnl ICC warnings we ignore:
1165          dnl * 279 warns on static conditions in while expressions
1166          dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
1167          dnl   "invalid format string conversion"
1168
1169          WARN="-wd279,269"
1170
1171          if test "$gccnum" -gt "600"; then
1172             dnl icc 6.0 and older doesn't have the -Wall flag
1173             WARN="-Wall $WARN"
1174          fi
1175        else dnl $ICC = yes
1176          dnl 
1177          WARN="-W -Wall -Wwrite-strings -pedantic -Wno-long-long -Wundef -Wpointer-arith -Wnested-externs -Winline -Wmissing-declarations -Wmissing-prototypes -Wsign-compare"
1178
1179          dnl -Wcast-align is a bit too annoying ;-)
1180
1181          if test "$gccnum" -ge "296"; then
1182            dnl gcc 2.96 or later
1183            WARN="$WARN -Wfloat-equal"
1184
1185            if test "$gccnum" -gt "296"; then
1186              dnl this option does not exist in 2.96
1187              WARN="$WARN -Wno-format-nonliteral"
1188            fi
1189
1190            dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
1191            dnl on i686-Linux as it gives us heaps with false positives
1192            if test "$gccnum" -ge "303"; then
1193              dnl gcc 3.3 and later
1194              WARN="$WARN -Wendif-labels -Wstrict-prototypes"
1195            fi
1196          fi
1197
1198          for flag in $CPPFLAGS; do
1199            case "$flag" in
1200             -I*)
1201               dnl include path
1202               add=`echo $flag | sed 's/^-I/-isystem /g'`
1203               WARN="$WARN $add"
1204               ;;
1205            esac
1206          done
1207
1208        fi dnl $ICC = no
1209
1210        CFLAGS="$CFLAGS $WARN"
1211
1212     fi dnl $GCC = yes
1213
1214     dnl strip off optimizer flags
1215     NEWFLAGS=""
1216     for flag in $CFLAGS; do
1217       case "$flag" in
1218       -O*)
1219         dnl echo "cut off $flag"
1220         ;;
1221       *)
1222         NEWFLAGS="$NEWFLAGS $flag"
1223         ;;
1224       esac
1225     done
1226     CFLAGS=$NEWFLAGS
1227
1228 ]) dnl end of AC_DEFUN()
1229
1230
1231 dnl This macro determines if the specified struct exists in the specified file
1232 dnl Syntax:
1233 dnl CARES_CHECK_STRUCT(headers, struct name, if found, [if not found])
1234
1235 AC_DEFUN([CARES_CHECK_STRUCT], [
1236   AC_MSG_CHECKING([for struct $2])
1237   AC_TRY_COMPILE([$1], 
1238     [
1239       struct $2 struct_instance;
1240     ], ac_struct="yes", ac_found="no")
1241   if test "$ac_struct" = "yes" ; then
1242     AC_MSG_RESULT(yes)
1243     $3
1244   else
1245     AC_MSG_RESULT(no)
1246     $4
1247   fi
1248 ])
1249
1250 dnl This macro determines if the specified constant exists in the specified file
1251 dnl Syntax:
1252 dnl CARES_CHECK_CONSTANT(headers, constant name, if found, [if not found])
1253
1254 AC_DEFUN([CARES_CHECK_CONSTANT], [
1255   AC_MSG_CHECKING([for $2])
1256   AC_EGREP_CPP(VARIABLEWASDEFINED,
1257    [
1258       $1
1259
1260       #ifdef $2
1261         VARIABLEWASDEFINED
1262       #else
1263         NJET
1264       #endif
1265     ], ac_constant="yes", ac_constant="no"
1266   )
1267   if test "$ac_constant" = "yes" ; then
1268     AC_MSG_RESULT(yes)
1269     $3
1270   else
1271     AC_MSG_RESULT(no)
1272     $4
1273   fi
1274 ])
1275
1276
1277 dnl This macro determines how many parameters getservbyport_r takes
1278 AC_DEFUN([CARES_CHECK_GETSERVBYPORT_R], [
1279   AC_MSG_CHECKING([how many arguments getservbyport_r takes])
1280   AC_TRY_LINK(
1281     [#include <netdb.h>],
1282     [
1283       int p1, p5;
1284       char *p2, p4[4096];
1285       struct servent *p3, *p6;
1286       getservbyport_r(p1, p2, p3, p4, p5, &p6);
1287     ], ac_func_getservbyport_r=6,
1288     [AC_TRY_LINK(
1289       [#include <netdb.h>],
1290       [
1291         int p1, p5;
1292         char *p2, p4[4096];
1293         struct servent *p3;
1294         getservbyport_r(p1, p2, p3, p4, p5);
1295       ], ac_func_getservbyport_r=5,
1296       [AC_TRY_LINK(
1297         [#include <netdb.h>],
1298         [
1299           int p1;
1300           char *p2;
1301           struct servent *p3;
1302           struct servent_data p4;
1303           getservbyport_r(p1, p2, p3, &p4);
1304         ], ac_func_getservbyport_r=4, ac_func_getservbyport_r=0
1305       )]
1306     )]
1307   )
1308 if test $ac_func_getservbyport_r != "0" ; then
1309   AC_MSG_RESULT($ac_func_getservbyport_r)
1310   AC_DEFINE(HAVE_GETSERVBYPORT_R, 1, [Specifies whether getservbyport_r is present])
1311   AC_DEFINE_UNQUOTED(GETSERVBYPORT_R_ARGS, $ac_func_getservbyport_r, [Specifies the number of arguments to 
1312 getservbyport_r])
1313   if test $ac_func_getservbyport_r = "4" ; then
1314    AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, sizeof(struct servent_data), [Specifies the size of the buffer to pass to 
1315 getservbyport_r])
1316   else
1317    AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, 4096, [Specifies the size of the buffer to pass to getservbyport_r])
1318   fi
1319 else
1320   AC_MSG_RESULT([not found])
1321 fi
1322 ])
1323
1324 # Prevent libtool for checking how to run C++ compiler and check for other
1325 # tools we don't want to use. We do this by m4-defining the _LT_AC_TAGCONFIG
1326 # variable to the code to run, as by default it uses a much more complicated
1327 # approach. The code below that is actually added seems to be used for cases
1328 # where configure has trouble figuring out what C compiler to use but where
1329 # the installed libtool has an idea.
1330 #
1331 # This function is a re-implemented version of the Paolo Bonzini fix posted to
1332 # the c-ares mailing list by Bram Matthys on May 6 2006. My version removes
1333 # redundant code but also adds the LTCFLAGS check that wasn't in that patch.
1334 #
1335 # Some code in this function was extracted from the generated configure script.
1336 #
1337 # CARES_CLEAR_LIBTOOL_TAGS
1338 AC_DEFUN([CARES_CLEAR_LIBTOOL_TAGS],
1339   [m4_define([_LT_AC_TAGCONFIG], [
1340   if test -f "$ltmain"; then
1341     if test ! -f "${ofile}"; then
1342       AC_MSG_WARN([output file `$ofile' does not exist])
1343     fi
1344
1345     if test -z "$LTCC"; then
1346       eval "`$SHELL ${ofile} --config | grep '^LTCC='`"
1347       if test -z "$LTCC"; then
1348         AC_MSG_WARN([output file `$ofile' does not look like a libtool
1349 script])
1350       else
1351         AC_MSG_WARN([using `LTCC=$LTCC', extracted from `$ofile'])
1352       fi
1353     fi
1354     if test -z "$LTCFLAGS"; then
1355       eval "`$SHELL ${ofile} --config | grep '^LTCFLAGS='`"
1356     fi
1357   fi
1358   ])]
1359 )