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