1
dnl -------------------------------------------------------- -*- autoconf -*-
2
dnl Copyright 2000-2005 The Apache Software Foundation
4
dnl Licensed under the Apache License, Version 2.0 (the "License");
5
dnl you may not use this file except in compliance with the License.
6
dnl You may obtain a copy of the License at
8
dnl http://www.apache.org/licenses/LICENSE-2.0
10
dnl Unless required by applicable law or agreed to in writing, software
11
dnl distributed under the License is distributed on an "AS IS" BASIS,
12
dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
dnl See the License for the specific language governing permissions and
14
dnl limitations under the License.
16
dnl -----------------------------------------------------------------
17
dnl apr_network.m4: APR's autoconf macros for testing network support
21
dnl check for working getaddrinfo()
23
dnl Note that if the system doesn't have gai_strerror(), we
24
dnl can't use getaddrinfo() because we can't get strings
25
dnl describing the error codes.
27
AC_DEFUN(APR_CHECK_WORKING_GETADDRINFO,[
28
AC_CACHE_CHECK(for working getaddrinfo, ac_cv_working_getaddrinfo,[
36
#ifdef HAVE_SYS_TYPES_H
37
#include <sys/types.h>
39
#ifdef HAVE_SYS_SOCKET_H
40
#include <sys/socket.h>
44
struct addrinfo hints, *ai;
47
memset(&hints, 0, sizeof(hints));
48
hints.ai_family = AF_UNSPEC;
49
hints.ai_socktype = SOCK_STREAM;
50
error = getaddrinfo("127.0.0.1", NULL, &hints, &ai);
54
if (ai->ai_addr->sa_family != AF_INET) {
60
ac_cv_working_getaddrinfo="yes"
62
ac_cv_working_getaddrinfo="no"
64
ac_cv_working_getaddrinfo="yes"
66
if test "$ac_cv_working_getaddrinfo" = "yes"; then
67
if test "$ac_cv_func_gai_strerror" != "yes"; then
68
ac_cv_working_getaddrinfo="no"
70
AC_DEFINE(HAVE_GETADDRINFO, 1, [Define if getaddrinfo exists and works well enough for APR])
75
dnl Check whether the AI_ADDRCONFIG flag can be used with getaddrinfo
76
AC_DEFUN(APR_CHECK_GETADDRINFO_ADDRCONFIG, [
77
AC_CACHE_CHECK(for working AI_ADDRCONFIG, apr_cv_gai_addrconfig, [
85
#ifdef HAVE_SYS_TYPES_H
86
#include <sys/types.h>
88
#ifdef HAVE_SYS_SOCKET_H
89
#include <sys/socket.h>
92
int main(int argc, char **argv) {
93
struct addrinfo hints, *ai;
95
memset(&hints, 0, sizeof(hints));
96
hints.ai_family = AF_UNSPEC;
97
hints.ai_socktype = SOCK_STREAM;
98
hints.ai_flags = AI_ADDRCONFIG;
99
return getaddrinfo("localhost", NULL, &hints, &ai) != 0;
100
}], [apr_cv_gai_addrconfig=yes],
101
[apr_cv_gai_addrconfig=no],
102
[apr_cv_gai_addrconfig=no])])
104
if test $apr_cv_gai_addrconfig = yes; then
105
AC_DEFINE(HAVE_GAI_ADDRCONFIG, 1, [Define if getaddrinfo accepts the AI_ADDRCONFIG flag])
110
dnl check for working getnameinfo()
112
AC_DEFUN(APR_CHECK_WORKING_GETNAMEINFO,[
113
AC_CACHE_CHECK(for working getnameinfo, ac_cv_working_getnameinfo,[
121
#ifdef HAVE_SYS_TYPES_H
122
#include <sys/types.h>
124
#ifdef HAVE_SYS_SOCKET_H
125
#include <sys/socket.h>
127
#ifdef HAVE_NETINET_IN_H
128
#include <netinet/in.h>
132
struct sockaddr_in sa;
136
sa.sin_family = AF_INET;
138
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
140
sa.sin_len = sizeof(sa);
143
error = getnameinfo((const struct sockaddr *)&sa, sizeof(sa),
153
ac_cv_working_getnameinfo="yes"
155
ac_cv_working_getnameinfo="no"
157
ac_cv_working_getnameinfo="yes"
159
if test "$ac_cv_working_getnameinfo" = "yes"; then
160
AC_DEFINE(HAVE_GETNAMEINFO, 1, [Define if getnameinfo exists])
165
dnl check for negative error codes for getaddrinfo()
167
AC_DEFUN(APR_CHECK_NEGATIVE_EAI,[
168
AC_CACHE_CHECK(for negative error codes for getaddrinfo, ac_cv_negative_eai,[
175
if (EAI_ADDRFAMILY < 0) {
181
ac_cv_negative_eai="yes"
183
ac_cv_negative_eai="no"
185
ac_cv_negative_eai="no"
187
if test "$ac_cv_negative_eai" = "yes"; then
188
AC_DEFINE(NEGATIVE_EAI, 1, [Define if EAI_ error codes from getaddrinfo are negative])
193
dnl Checks the definition of gethostbyname_r and gethostbyaddr_r
194
dnl which are different for glibc, solaris and assorted other operating
197
dnl Note that this test is executed too early to see if we have all of
199
AC_DEFUN(APR_CHECK_GETHOSTBYNAME_R_STYLE,[
201
dnl Try and compile a glibc2 gethostbyname_r piece of code, and set the
202
dnl style of the routines to glibc2 on success
203
AC_CACHE_CHECK([style of gethostbyname_r routine], ac_cv_gethostbyname_r_style,
204
APR_TRY_COMPILE_NO_WARNING([
205
#ifdef HAVE_SYS_TYPES_H
206
#include <sys/types.h>
208
#ifdef HAVE_NETINET_IN_H
209
#include <netinet/in.h>
211
#ifdef HAVE_ARPA_INET_H
212
#include <arpa/inet.h>
221
int tmp = gethostbyname_r((const char *) 0, (struct hostent *) 0,
222
(char *) 0, 0, (struct hostent **) 0, &tmp);
223
], ac_cv_gethostbyname_r_style=glibc2, ac_cv_gethostbyname_r_style=none))
225
if test "$ac_cv_gethostbyname_r_style" = "glibc2"; then
226
AC_DEFINE(GETHOSTBYNAME_R_GLIBC2, 1, [Define if gethostbyname_r has the glibc style])
229
AC_CACHE_CHECK([3rd argument to the gethostbyname_r routines], ac_cv_gethostbyname_r_arg,
230
APR_TRY_COMPILE_NO_WARNING([
231
#ifdef HAVE_SYS_TYPES_H
232
#include <sys/types.h>
234
#ifdef HAVE_NETINET_IN_H
235
#include <netinet/in.h>
237
#ifdef HAVE_ARPA_INET_H
238
#include <arpa/inet.h>
247
int tmp = gethostbyname_r((const char *) 0, (struct hostent *) 0,
248
(struct hostent_data *) 0);],
249
ac_cv_gethostbyname_r_arg=hostent_data, ac_cv_gethostbyname_r_arg=char))
251
if test "$ac_cv_gethostbyname_r_arg" = "hostent_data"; then
252
AC_DEFINE(GETHOSTBYNAME_R_HOSTENT_DATA, 1, [Define if gethostbyname_r has the hostent_data for the third argument])
257
dnl see if TCP_NODELAY setting is inherited from listening sockets
259
AC_DEFUN(APR_CHECK_TCP_NODELAY_INHERITED,[
260
AC_CACHE_CHECK(if TCP_NODELAY setting is inherited from listening sockets, ac_cv_tcp_nodelay_inherited,[
263
#ifdef HAVE_SYS_TYPES_H
264
#include <sys/types.h>
266
#ifdef HAVE_SYS_SOCKET_H
267
#include <sys/socket.h>
269
#ifdef HAVE_NETINET_IN_H
270
#include <netinet/in.h>
272
#ifdef HAVE_NETINET_TCP_H
273
#include <netinet/tcp.h>
275
#ifndef HAVE_SOCKLEN_T
276
typedef int socklen_t;
279
int listen_s, connected_s, client_s;
281
struct sockaddr_in sa;
283
socklen_t option_len;
286
listen_s = socket(AF_INET, SOCK_STREAM, 0);
292
rc = setsockopt(listen_s, IPPROTO_TCP, TCP_NODELAY, &option, sizeof option);
294
perror("setsockopt TCP_NODELAY");
297
memset(&sa, 0, sizeof sa);
298
sa.sin_family = AF_INET;
300
sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
302
/* leave port 0 to get ephemeral */
303
rc = bind(listen_s, (struct sockaddr *)&sa, sizeof sa);
305
perror("bind for ephemeral port");
308
/* find ephemeral port */
310
rc = getsockname(listen_s, (struct sockaddr *)&sa, &sa_len);
312
perror("getsockname");
315
listen_port = sa.sin_port;
316
rc = listen(listen_s, 5);
321
client_s = socket(AF_INET, SOCK_STREAM, 0);
326
memset(&sa, 0, sizeof sa);
327
sa.sin_family = AF_INET;
328
sa.sin_port = listen_port;
330
sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
332
/* leave sin_addr all zeros to use loopback */
333
rc = connect(client_s, (struct sockaddr *)&sa, sizeof sa);
339
connected_s = accept(listen_s, (struct sockaddr *)&sa, &sa_len);
340
if (connected_s < 0) {
344
option_len = sizeof option;
345
rc = getsockopt(connected_s, IPPROTO_TCP, TCP_NODELAY, &option, &option_len);
347
perror("getsockopt");
351
fprintf(stderr, "TCP_NODELAY is not set in the child.\n");
357
ac_cv_tcp_nodelay_inherited="yes"
359
ac_cv_tcp_nodelay_inherited="no"
361
ac_cv_tcp_nodelay_inherited="yes"
363
if test "$ac_cv_tcp_nodelay_inherited" = "yes"; then
364
tcp_nodelay_inherited=1
366
tcp_nodelay_inherited=0
371
dnl Determine whether TCP_NODELAY and TCP_CORK can both be set
374
AC_DEFUN([APR_CHECK_TCP_NODELAY_WITH_CORK], [
375
AC_CACHE_CHECK([whether TCP_NODELAY and TCP_CORK can both be enabled],
376
[apr_cv_tcp_nodelay_with_cork],
377
[AC_RUN_IFELSE([AC_LANG_PROGRAM([[
378
#ifdef HAVE_SYS_TYPES_H
379
#include <sys/types.h>
381
#ifdef HAVE_SYS_SOCKET_H
382
#include <sys/socket.h>
384
#ifdef HAVE_NETINET_IN_H
385
#include <netinet/in.h>
387
#ifdef HAVE_NETINET_TCP_H
388
#include <netinet/tcp.h>
395
fd = socket(AF_INET, SOCK_STREAM, 0);
401
rc = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof flag);
403
perror("setsockopt TCP_NODELAY");
408
rc = setsockopt(fd, IPPROTO_TCP, TCP_CORK, &flag, sizeof flag);
410
perror("setsockopt TCP_CORK");
415
]])], [apr_cv_tcp_nodelay_with_cork=yes], [apr_cv_tcp_nodelay_with_cork=no])])
417
if test "$apr_cv_tcp_nodelay_with_cork" = "yes"; then
418
AC_DEFINE([HAVE_TCP_NODELAY_WITH_CORK], 1,
419
[Define if TCP_NODELAY and TCP_CORK can be enabled at the same time])
425
dnl see if O_NONBLOCK setting is inherited from listening sockets
427
AC_DEFUN(APR_CHECK_O_NONBLOCK_INHERITED,[
428
AC_CACHE_CHECK(if O_NONBLOCK setting is inherited from listening sockets, ac_cv_o_nonblock_inherited,[
431
#ifdef HAVE_SYS_TYPES_H
432
#include <sys/types.h>
434
#ifdef HAVE_SYS_SOCKET_H
435
#include <sys/socket.h>
437
#ifdef HAVE_NETINET_IN_H
438
#include <netinet/in.h>
440
#ifdef HAVE_NETINET_TCP_H
441
#include <netinet/tcp.h>
443
#ifndef HAVE_SOCKLEN_T
444
typedef int socklen_t;
450
int listen_s, connected_s, client_s;
452
struct sockaddr_in sa;
455
listen_s = socket(AF_INET, SOCK_STREAM, 0);
460
memset(&sa, 0, sizeof sa);
461
sa.sin_family = AF_INET;
463
sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
465
/* leave port 0 to get ephemeral */
466
rc = bind(listen_s, (struct sockaddr *)&sa, sizeof sa);
468
perror("bind for ephemeral port");
471
/* find ephemeral port */
473
rc = getsockname(listen_s, (struct sockaddr *)&sa, &sa_len);
475
perror("getsockname");
478
listen_port = sa.sin_port;
479
rc = listen(listen_s, 5);
484
rc = fcntl(listen_s, F_SETFL, O_NONBLOCK);
486
perror("fcntl(F_SETFL)");
489
client_s = socket(AF_INET, SOCK_STREAM, 0);
494
memset(&sa, 0, sizeof sa);
495
sa.sin_family = AF_INET;
496
sa.sin_port = listen_port;
498
sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
500
/* leave sin_addr all zeros to use loopback */
501
rc = connect(client_s, (struct sockaddr *)&sa, sizeof sa);
507
connected_s = accept(listen_s, (struct sockaddr *)&sa, &sa_len);
508
if (connected_s < 0) {
512
rc = fcntl(connected_s, F_GETFL, 0);
514
perror("fcntl(F_GETFL)");
517
if (!(rc & O_NONBLOCK)) {
518
fprintf(stderr, "O_NONBLOCK is not set in the child.\n");
524
ac_cv_o_nonblock_inherited="yes"
526
ac_cv_o_nonblock_inherited="no"
528
ac_cv_o_nonblock_inherited="yes"
530
if test "$ac_cv_o_nonblock_inherited" = "yes"; then
531
o_nonblock_inherited=1
533
o_nonblock_inherited=0
538
dnl check for socklen_t, fall back to unsigned int
540
AC_DEFUN(APR_CHECK_SOCKLEN_T,[
541
AC_CACHE_CHECK(for socklen_t, ac_cv_socklen_t,[
543
#ifdef HAVE_SYS_TYPES_H
544
#include <sys/types.h>
546
#ifdef HAVE_SYS_SOCKET_H
547
#include <sys/socket.h>
550
socklen_t foo = (socklen_t) 0;
558
if test "$ac_cv_socklen_t" = "yes"; then
559
AC_DEFINE(HAVE_SOCKLEN_T, 1, [Whether you have socklen_t])
564
AC_DEFUN(APR_CHECK_INET_ADDR,[
565
AC_CACHE_CHECK(for inet_addr, ac_cv_func_inet_addr,[
567
#ifdef HAVE_SYS_TYPES_H
568
#include <sys/types.h>
570
#ifdef HAVE_ARPA_INET_H
571
#include <arpa/inet.h>
574
inet_addr("127.0.0.1");
576
ac_cv_func_inet_addr=yes
578
ac_cv_func_inet_addr=no
582
if test "$ac_cv_func_inet_addr" = "yes"; then
590
AC_DEFUN(APR_CHECK_INET_NETWORK,[
591
AC_CACHE_CHECK(for inet_network, ac_cv_func_inet_network,[
593
#ifdef HAVE_SYS_TYPES_H
594
#include <sys/types.h>
596
#ifdef HAVE_ARPA_INET_H
597
#include <arpa/inet.h>
600
inet_network("127.0.0.1");
602
ac_cv_func_inet_network=yes
604
ac_cv_func_inet_network=no
608
if test "$ac_cv_func_inet_network" = "yes"; then
615
dnl Check for presence of struct sockaddr_storage.
616
AC_DEFUN(APR_CHECK_SOCKADDR_STORAGE,[
617
AC_CACHE_CHECK(for sockaddr_storage, apr_cv_define_sockaddr_storage,[
619
#ifdef HAVE_SYS_TYPES_H
620
#include <sys/types.h>
622
#ifdef HAVE_NETINET_IN_H
623
#include <netinet/in.h>
625
],[struct sockaddr_storage sa;],
626
[apr_cv_define_sockaddr_storage=yes],
627
[apr_cv_define_sockaddr_storage=no])])
629
if test "$apr_cv_define_sockaddr_storage" = "yes"; then
634
AC_SUBST(have_sa_storage)
637
dnl Check for presence of struct sockaddr_in6.
638
AC_DEFUN(APR_CHECK_SOCKADDR_IN6,[
639
AC_CACHE_CHECK(for sockaddr_in6, ac_cv_define_sockaddr_in6,[
641
#ifdef HAVE_SYS_TYPES_H
642
#include <sys/types.h>
644
#ifdef HAVE_NETINET_IN_H
645
#include <netinet/in.h>
648
struct sockaddr_in6 sa;
650
ac_cv_define_sockaddr_in6=yes
652
ac_cv_define_sockaddr_in6=no
656
if test "$ac_cv_define_sockaddr_in6" = "yes"; then
664
dnl APR_H_ERRNO_COMPILE_CHECK
666
AC_DEFUN(APR_H_ERRNO_COMPILE_CHECK,[
667
if test x$1 != x; then
668
CPPFLAGS="-D$1 $CPPFLAGS"
671
#ifdef HAVE_SYS_TYPES_H
672
#include <sys/types.h>
680
if test x$1 != x; then
681
ac_cv_h_errno_cppflags="$1"
683
ac_cv_h_errno_cppflags=yes
686
ac_cv_h_errno_cppflags=no
693
dnl check for presence of SCTP protocol support
695
AC_DEFUN([APR_CHECK_SCTP],
697
AC_CACHE_CHECK([whether SCTP is supported], [apr_cv_sctp], [
699
#ifdef HAVE_SYS_TYPES_H
700
#include <sys/types.h>
702
#ifdef HAVE_SYS_SOCKET_H
703
#include <sys/socket.h>
705
#ifdef HAVE_NETINET_IN_H
706
#include <netinet/in.h>
708
#ifdef HAVE_NETINET_SCTP_H
709
#include <netinet/sctp.h>
711
#ifdef HAVE_NETINET_SCTP_UIO_H
712
#include <netinet/sctp_uio.h>
717
if ((s = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP)) < 0)
719
if (setsockopt(s, IPPROTO_SCTP, SCTP_NODELAY, &opt, sizeof(int)) < 0)
722
}], [apr_cv_sctp=yes], [apr_cv_sctp=no], [apr_cv_sctp=no])])
724
if test "$apr_cv_sctp" = "yes"; then
731
dnl APR_CHECK_MCAST: check for multicast interfaces
732
AC_DEFUN([APR_CHECK_MCAST], [
733
AC_CACHE_CHECK([for struct ip_mreq], [apr_cv_struct_ipmreq], [
735
#include <sys/types.h>
736
#include <netinet/in.h>
739
mip.imr_interface.s_addr = INADDR_ANY;
740
], [apr_cv_struct_ipmreq=yes], [apr_cv_struct_ipmreq=no], [apr_cv_struct_ipmreq=yes])])
742
if test $apr_cv_struct_ipmreq = yes; then
743
AC_DEFINE([HAVE_STRUCT_IPMREQ], 1, [Define if struct impreq was found])
748
dnl APR_CHECK_H_ERRNO_FLAG
750
dnl checks which flags are necessary for <netdb.h> to define h_errno
752
AC_DEFUN(APR_CHECK_H_ERRNO_FLAG,[
753
AC_MSG_CHECKING([for h_errno in netdb.h])
754
AC_CACHE_VAL(ac_cv_h_errno_cppflags,[
755
APR_H_ERRNO_COMPILE_CHECK
756
if test "$ac_cv_h_errno_cppflags" = "no"; then
758
for flag in _XOPEN_SOURCE_EXTENDED; do
759
APR_H_ERRNO_COMPILE_CHECK($flag)
760
if test "$ac_cv_h_errno_cppflags" != "no"; then
767
if test "$ac_cv_h_errno_cppflags" != "no"; then
768
if test "$ac_cv_h_errno_cppflags" != "yes"; then
769
CPPFLAGS="-D$ac_cv_h_errno_cppflags $CPPFLAGS"
770
AC_MSG_RESULT([yes, with -D$ac_cv_h_errno_cppflags])
772
AC_MSG_RESULT([$ac_cv_h_errno_cppflags])
775
AC_MSG_RESULT([$ac_cv_h_errno_cppflags])
780
AC_DEFUN(APR_EBCDIC,[
781
AC_CACHE_CHECK([whether system uses EBCDIC],ac_cv_ebcdic,[
784
return (unsigned char)'A' != (unsigned char)0xC1;
793
if test "$ac_cv_ebcdic" = "yes"; then
798
AC_SUBST(apr_charset_ebcdic)