1
dnl -----------------------------------------------------------------
2
dnl apr_network.m4: APR's autoconf macros for testing network support
6
dnl check for working getaddrinfo()
8
dnl Note that if the system doesn't have gai_strerror(), we
9
dnl can't use getaddrinfo() because we can't get strings
10
dnl describing the error codes.
12
AC_DEFUN(APR_CHECK_WORKING_GETADDRINFO,[
13
AC_CACHE_CHECK(for working getaddrinfo, ac_cv_working_getaddrinfo,[
21
#ifdef HAVE_SYS_TYPES_H
22
#include <sys/types.h>
24
#ifdef HAVE_SYS_SOCKET_H
25
#include <sys/socket.h>
29
struct addrinfo hints, *ai;
32
memset(&hints, 0, sizeof(hints));
33
hints.ai_family = AF_UNSPEC;
34
hints.ai_socktype = SOCK_STREAM;
35
error = getaddrinfo("127.0.0.1", NULL, &hints, &ai);
39
if (ai->ai_addr->sa_family != AF_INET) {
45
ac_cv_working_getaddrinfo="yes"
47
ac_cv_working_getaddrinfo="no"
49
ac_cv_working_getaddrinfo="yes"
51
if test "$ac_cv_working_getaddrinfo" = "yes"; then
52
if test "$ac_cv_func_gai_strerror" != "yes"; then
53
ac_cv_working_getaddrinfo="no"
55
AC_DEFINE(HAVE_GETADDRINFO, 1, [Define if getaddrinfo exists and works well enough for APR])
61
dnl check for working getnameinfo()
63
AC_DEFUN(APR_CHECK_WORKING_GETNAMEINFO,[
64
AC_CACHE_CHECK(for working getnameinfo, ac_cv_working_getnameinfo,[
72
#ifdef HAVE_SYS_TYPES_H
73
#include <sys/types.h>
75
#ifdef HAVE_SYS_SOCKET_H
76
#include <sys/socket.h>
78
#ifdef HAVE_NETINET_IN_H
79
#include <netinet/in.h>
83
struct sockaddr_in sa;
87
sa.sin_family = AF_INET;
89
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
91
sa.sin_len = sizeof(sa);
94
error = getnameinfo((const struct sockaddr *)&sa, sizeof(sa),
104
ac_cv_working_getnameinfo="yes"
106
ac_cv_working_getnameinfo="no"
108
ac_cv_working_getnameinfo="yes"
110
if test "$ac_cv_working_getnameinfo" = "yes"; then
111
AC_DEFINE(HAVE_GETNAMEINFO, 1, [Define if getnameinfo exists])
116
dnl check for negative error codes for getaddrinfo()
118
AC_DEFUN(APR_CHECK_NEGATIVE_EAI,[
119
AC_CACHE_CHECK(for negative error codes for getaddrinfo, ac_cv_negative_eai,[
126
if (EAI_ADDRFAMILY < 0) {
132
ac_cv_negative_eai="yes"
134
ac_cv_negative_eai="no"
136
ac_cv_negative_eai="no"
138
if test "$ac_cv_negative_eai" = "yes"; then
139
AC_DEFINE(NEGATIVE_EAI, 1, [Define if EAI_ error codes from getaddrinfo are negative])
144
dnl check for presence of retrans/retry variables in the res_state structure
146
AC_DEFUN(APR_CHECK_RESOLV_RETRANS,[
147
AC_CACHE_CHECK(for presence of retrans/retry fields in res_state/resolv.h , ac_cv_retransretry,[
149
#include <sys/types.h>
154
/* _res is a global defined in resolv.h */
162
ac_cv_retransretry="yes"
164
ac_cv_retransretry="no"
166
ac_cv_retransretry="no"
168
if test "$ac_cv_retransretry" = "yes"; then
169
AC_DEFINE(RESOLV_RETRANSRETRY, 1, [Define if resolv.h's res_state has the fields retrans/rety])
174
dnl Checks the definition of gethostbyname_r and gethostbyaddr_r
175
dnl which are different for glibc, solaris and assorted other operating
178
dnl Note that this test is executed too early to see if we have all of
180
AC_DEFUN(APR_CHECK_GETHOSTBYNAME_R_STYLE,[
182
dnl Try and compile a glibc2 gethostbyname_r piece of code, and set the
183
dnl style of the routines to glibc2 on success
184
AC_CACHE_CHECK([style of gethostbyname_r routine], ac_cv_gethostbyname_r_style,
185
APR_TRY_COMPILE_NO_WARNING([
186
#ifdef HAVE_SYS_TYPES_H
187
#include <sys/types.h>
189
#ifdef HAVE_NETINET_IN_H
190
#include <netinet/in.h>
192
#ifdef HAVE_ARPA_INET_H
193
#include <arpa/inet.h>
202
int tmp = gethostbyname_r((const char *) 0, (struct hostent *) 0,
203
(char *) 0, 0, (struct hostent **) 0, &tmp);
204
], ac_cv_gethostbyname_r_style=glibc2, ac_cv_gethostbyname_r_style=none))
206
if test "$ac_cv_gethostbyname_r_style" = "glibc2"; then
207
AC_DEFINE(GETHOSTBYNAME_R_GLIBC2, 1, [Define if gethostbyname_r has the glibc style])
210
AC_CACHE_CHECK([3rd argument to the gethostbyname_r routines], ac_cv_gethostbyname_r_arg,
211
APR_TRY_COMPILE_NO_WARNING([
212
#ifdef HAVE_SYS_TYPES_H
213
#include <sys/types.h>
215
#ifdef HAVE_NETINET_IN_H
216
#include <netinet/in.h>
218
#ifdef HAVE_ARPA_INET_H
219
#include <arpa/inet.h>
228
int tmp = gethostbyname_r((const char *) 0, (struct hostent *) 0,
229
(struct hostent_data *) 0);],
230
ac_cv_gethostbyname_r_arg=hostent_data, ac_cv_gethostbyname_r_arg=char))
232
if test "$ac_cv_gethostbyname_r_arg" = "hostent_data"; then
233
AC_DEFINE(GETHOSTBYNAME_R_HOSTENT_DATA, 1, [Define if gethostbyname_r has the hostent_data for the third argument])
238
dnl see if TCP_NODELAY setting is inherited from listening sockets
240
AC_DEFUN(APR_CHECK_TCP_NODELAY_INHERITED,[
241
AC_CACHE_CHECK(if TCP_NODELAY setting is inherited from listening sockets, ac_cv_tcp_nodelay_inherited,[
244
#ifdef HAVE_SYS_TYPES_H
245
#include <sys/types.h>
247
#ifdef HAVE_SYS_SOCKET_H
248
#include <sys/socket.h>
250
#ifdef HAVE_NETINET_IN_H
251
#include <netinet/in.h>
253
#ifdef HAVE_NETINET_TCP_H
254
#include <netinet/tcp.h>
256
#ifndef HAVE_SOCKLEN_T
257
typedef int socklen_t;
260
int listen_s, connected_s, client_s;
262
struct sockaddr_in sa;
264
socklen_t option_len;
267
listen_s = socket(AF_INET, SOCK_STREAM, 0);
273
rc = setsockopt(listen_s, IPPROTO_TCP, TCP_NODELAY, &option, sizeof option);
275
perror("setsockopt TCP_NODELAY");
278
memset(&sa, 0, sizeof sa);
279
sa.sin_family = AF_INET;
281
sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
283
/* leave port 0 to get ephemeral */
284
rc = bind(listen_s, (struct sockaddr *)&sa, sizeof sa);
286
perror("bind for ephemeral port");
289
/* find ephemeral port */
291
rc = getsockname(listen_s, (struct sockaddr *)&sa, &sa_len);
293
perror("getsockname");
296
listen_port = sa.sin_port;
297
rc = listen(listen_s, 5);
302
client_s = socket(AF_INET, SOCK_STREAM, 0);
307
memset(&sa, 0, sizeof sa);
308
sa.sin_family = AF_INET;
309
sa.sin_port = listen_port;
311
sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
313
/* leave sin_addr all zeros to use loopback */
314
rc = connect(client_s, (struct sockaddr *)&sa, sizeof sa);
320
connected_s = accept(listen_s, (struct sockaddr *)&sa, &sa_len);
321
if (connected_s < 0) {
325
option_len = sizeof option;
326
rc = getsockopt(connected_s, IPPROTO_TCP, TCP_NODELAY, &option, &option_len);
328
perror("getsockopt");
332
fprintf(stderr, "TCP_NODELAY is not set in the child.\n");
338
ac_cv_tcp_nodelay_inherited="yes"
340
ac_cv_tcp_nodelay_inherited="no"
342
ac_cv_tcp_nodelay_inherited="yes"
344
if test "$ac_cv_tcp_nodelay_inherited" = "yes"; then
345
tcp_nodelay_inherited=1
347
tcp_nodelay_inherited=0
352
dnl see if O_NONBLOCK setting is inherited from listening sockets
354
AC_DEFUN(APR_CHECK_O_NONBLOCK_INHERITED,[
355
AC_CACHE_CHECK(if O_NONBLOCK setting is inherited from listening sockets, ac_cv_o_nonblock_inherited,[
358
#ifdef HAVE_SYS_TYPES_H
359
#include <sys/types.h>
361
#ifdef HAVE_SYS_SOCKET_H
362
#include <sys/socket.h>
364
#ifdef HAVE_NETINET_IN_H
365
#include <netinet/in.h>
367
#ifdef HAVE_NETINET_TCP_H
368
#include <netinet/tcp.h>
370
#ifndef HAVE_SOCKLEN_T
371
typedef int socklen_t;
377
int listen_s, connected_s, client_s;
379
struct sockaddr_in sa;
382
listen_s = socket(AF_INET, SOCK_STREAM, 0);
387
memset(&sa, 0, sizeof sa);
388
sa.sin_family = AF_INET;
390
sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
392
/* leave port 0 to get ephemeral */
393
rc = bind(listen_s, (struct sockaddr *)&sa, sizeof sa);
395
perror("bind for ephemeral port");
398
/* find ephemeral port */
400
rc = getsockname(listen_s, (struct sockaddr *)&sa, &sa_len);
402
perror("getsockname");
405
listen_port = sa.sin_port;
406
rc = listen(listen_s, 5);
411
rc = fcntl(listen_s, F_SETFL, O_NONBLOCK);
413
perror("fcntl(F_SETFL)");
416
client_s = socket(AF_INET, SOCK_STREAM, 0);
421
memset(&sa, 0, sizeof sa);
422
sa.sin_family = AF_INET;
423
sa.sin_port = listen_port;
425
sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
427
/* leave sin_addr all zeros to use loopback */
428
rc = connect(client_s, (struct sockaddr *)&sa, sizeof sa);
434
connected_s = accept(listen_s, (struct sockaddr *)&sa, &sa_len);
435
if (connected_s < 0) {
439
rc = fcntl(connected_s, F_GETFL, 0);
441
perror("fcntl(F_GETFL)");
444
if (!(rc & O_NONBLOCK)) {
445
fprintf(stderr, "O_NONBLOCK is not set in the child.\n");
451
ac_cv_o_nonblock_inherited="yes"
453
ac_cv_o_nonblock_inherited="no"
455
ac_cv_o_nonblock_inherited="yes"
457
if test "$ac_cv_o_nonblock_inherited" = "yes"; then
458
o_nonblock_inherited=1
460
o_nonblock_inherited=0
465
dnl check for socklen_t, fall back to unsigned int
467
AC_DEFUN(APR_CHECK_SOCKLEN_T,[
468
AC_CACHE_CHECK(for socklen_t, ac_cv_socklen_t,[
470
#ifdef HAVE_SYS_TYPES_H
471
#include <sys/types.h>
473
#ifdef HAVE_SYS_SOCKET_H
474
#include <sys/socket.h>
477
socklen_t foo = (socklen_t) 0;
485
if test "$ac_cv_socklen_t" = "yes"; then
486
AC_DEFINE(HAVE_SOCKLEN_T, 1, [Whether you have socklen_t])
491
AC_DEFUN(APR_CHECK_INET_ADDR,[
492
AC_CACHE_CHECK(for inet_addr, ac_cv_func_inet_addr,[
494
#ifdef HAVE_SYS_TYPES_H
495
#include <sys/types.h>
497
#ifdef HAVE_ARPA_INET_H
498
#include <arpa/inet.h>
501
inet_addr("127.0.0.1");
503
ac_cv_func_inet_addr=yes
505
ac_cv_func_inet_addr=no
509
if test "$ac_cv_func_inet_addr" = "yes"; then
517
AC_DEFUN(APR_CHECK_INET_NETWORK,[
518
AC_CACHE_CHECK(for inet_network, ac_cv_func_inet_network,[
520
#ifdef HAVE_SYS_TYPES_H
521
#include <sys/types.h>
523
#ifdef HAVE_ARPA_INET_H
524
#include <arpa/inet.h>
527
inet_network("127.0.0.1");
529
ac_cv_func_inet_network=yes
531
ac_cv_func_inet_network=no
535
if test "$ac_cv_func_inet_network" = "yes"; then
543
AC_DEFUN(APR_CHECK_SOCKADDR_IN6,[
544
AC_CACHE_CHECK(for sockaddr_in6, ac_cv_define_sockaddr_in6,[
546
#ifdef HAVE_SYS_TYPES_H
547
#include <sys/types.h>
549
#ifdef HAVE_NETINET_IN_H
550
#include <netinet/in.h>
553
struct sockaddr_in6 sa;
555
ac_cv_define_sockaddr_in6=yes
557
ac_cv_define_sockaddr_in6=no
561
if test "$ac_cv_define_sockaddr_in6" = "yes"; then
571
dnl checks for missing INADDR_NONE macro
573
AC_DEFUN(APR_INADDR_NONE,[
574
AC_CACHE_CHECK(whether system defines INADDR_NONE, ac_cv_inaddr_none,[
576
#ifdef HAVE_SYS_TYPES_H
577
#include <sys/types.h>
579
#ifdef HAVE_SYS_SOCKET_H
580
#include <sys/socket.h>
582
#ifdef HAVE_NETINET_IN_H
583
#include <netinet/in.h>
585
#ifdef HAVE_ARPA_INET_H
586
#include <arpa/inet.h>
589
unsigned long foo = INADDR_NONE;
591
ac_cv_inaddr_none=yes
595
if test "$ac_cv_inaddr_none" = "no"; then
596
apr_inaddr_none="((unsigned int) 0xffffffff)"
598
apr_inaddr_none="INADDR_NONE"
604
dnl APR_H_ERRNO_COMPILE_CHECK
606
AC_DEFUN(APR_H_ERRNO_COMPILE_CHECK,[
607
if test x$1 != x; then
608
CPPFLAGS="-D$1 $CPPFLAGS"
611
#ifdef HAVE_SYS_TYPES_H
612
#include <sys/types.h>
620
if test x$1 != x; then
621
ac_cv_h_errno_cppflags="$1"
623
ac_cv_h_errno_cppflags=yes
626
ac_cv_h_errno_cppflags=no
633
dnl check for presence of SCTP protocol support
635
AC_DEFUN([APR_CHECK_SCTP],
637
AC_CACHE_CHECK([whether SCTP is supported], [apr_cv_sctp], [
639
#ifdef HAVE_SYS_TYPES_H
640
#include <sys/types.h>
642
#ifdef HAVE_SYS_SOCKET_H
643
#include <sys/socket.h>
645
#ifdef HAVE_NETINET_IN_H
646
#include <netinet/in.h>
648
#ifdef HAVE_NETINET_SCTP_H
649
#include <netinet/sctp.h>
651
#ifdef HAVE_NETINET_SCTP_UIO_H
652
#include <netinet/sctp_uio.h>
657
if ((s = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP)) < 0)
659
if (setsockopt(s, IPPROTO_SCTP, SCTP_NODELAY, &opt, sizeof(int)) < 0)
662
}], [apr_cv_sctp=yes], [apr_cv_sctp=no], [apr_cv_sctp=no])])
664
if test "$apr_cv_sctp" = "yes"; then
672
dnl APR_CHECK_H_ERRNO_FLAG
674
dnl checks which flags are necessary for <netdb.h> to define h_errno
676
AC_DEFUN(APR_CHECK_H_ERRNO_FLAG,[
677
AC_MSG_CHECKING([for h_errno in netdb.h])
678
AC_CACHE_VAL(ac_cv_h_errno_cppflags,[
679
APR_H_ERRNO_COMPILE_CHECK
680
if test "$ac_cv_h_errno_cppflags" = "no"; then
682
for flag in _XOPEN_SOURCE_EXTENDED; do
683
APR_H_ERRNO_COMPILE_CHECK($flag)
684
if test "$ac_cv_h_errno_cppflags" != "no"; then
691
if test "$ac_cv_h_errno_cppflags" != "no"; then
692
if test "$ac_cv_h_errno_cppflags" != "yes"; then
693
CPPFLAGS="-D$ac_cv_h_errno_cppflags $CPPFLAGS"
694
AC_MSG_RESULT([yes, with -D$ac_cv_h_errno_cppflags])
696
AC_MSG_RESULT([$ac_cv_h_errno_cppflags])
699
AC_MSG_RESULT([$ac_cv_h_errno_cppflags])
704
AC_DEFUN(APR_EBCDIC,[
705
AC_CACHE_CHECK([whether system uses EBCDIC],ac_cv_ebcdic,[
708
return (unsigned char)'A' != (unsigned char)0xC1;
717
if test "$ac_cv_ebcdic" = "yes"; then
722
AC_SUBST(apr_charset_ebcdic)