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