xref: /aosp_15_r20/external/cronet/third_party/apache-portable-runtime/src/build/apr_network.m4 (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1dnl -------------------------------------------------------- -*- autoconf -*-
2dnl Licensed to the Apache Software Foundation (ASF) under one or more
3dnl contributor license agreements.  See the NOTICE file distributed with
4dnl this work for additional information regarding copyright ownership.
5dnl The ASF licenses this file to You under the Apache License, Version 2.0
6dnl (the "License"); you may not use this file except in compliance with
7dnl the License.  You may obtain a copy of the License at
8dnl
9dnl     http://www.apache.org/licenses/LICENSE-2.0
10dnl
11dnl Unless required by applicable law or agreed to in writing, software
12dnl distributed under the License is distributed on an "AS IS" BASIS,
13dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14dnl See the License for the specific language governing permissions and
15dnl limitations under the License.
16
17dnl -----------------------------------------------------------------
18dnl apr_network.m4: APR's autoconf macros for testing network support
19dnl
20
21dnl
22dnl check for type in_addr
23dnl
24AC_DEFUN(APR_TYPE_IN_ADDR,[
25  AC_CACHE_CHECK(for type in_addr, ac_cv_type_in_addr,[
26  AC_TRY_COMPILE([
27#ifdef HAVE_SYS_TYPES_H
28#include <sys/types.h>
29#endif
30#ifdef HAVE_NETINET_IN_H
31#include <netinet/in.h>
32#endif
33#ifdef HAVE_WINSOCK2_H
34#include <winsock2.h>
35#endif
36],[
37 struct in_addr arg;
38 arg.s_addr = htonl(INADDR_ANY);
39], [ ac_cv_type_in_addr="yes"] , [
40ac_cv_type_in_addr="no"])
41])
42])
43
44dnl
45dnl check for working getaddrinfo()
46dnl
47dnl Note that if the system doesn't have gai_strerror(), we
48dnl can't use getaddrinfo() because we can't get strings
49dnl describing the error codes.
50dnl
51AC_DEFUN([APR_CHECK_WORKING_GETADDRINFO], [
52  AC_CACHE_CHECK(for working getaddrinfo, ac_cv_working_getaddrinfo,[
53  AC_TRY_RUN( [
54#ifdef HAVE_NETDB_H
55#include <netdb.h>
56#endif
57#ifdef HAVE_STRING_H
58#include <string.h>
59#endif
60#ifdef HAVE_SYS_TYPES_H
61#include <sys/types.h>
62#endif
63#ifdef HAVE_SYS_SOCKET_H
64#include <sys/socket.h>
65#endif
66
67int main(void) {
68    struct addrinfo hints, *ai;
69    int error;
70
71    memset(&hints, 0, sizeof(hints));
72    hints.ai_family = AF_UNSPEC;
73    hints.ai_socktype = SOCK_STREAM;
74    error = getaddrinfo("127.0.0.1", NULL, &hints, &ai);
75    if (error) {
76        exit(1);
77    }
78    if (ai->ai_addr->sa_family != AF_INET) {
79        exit(1);
80    }
81    exit(0);
82}
83],[
84  ac_cv_working_getaddrinfo="yes"
85],[
86  ac_cv_working_getaddrinfo="no"
87],[
88  ac_cv_working_getaddrinfo="yes"
89])])
90if test "$ac_cv_working_getaddrinfo" = "yes"; then
91  if test "$ac_cv_func_gai_strerror" != "yes"; then
92    ac_cv_working_getaddrinfo="no"
93  else
94    AC_DEFINE(HAVE_GETADDRINFO, 1, [Define if getaddrinfo exists and works well enough for APR])
95  fi
96fi
97])
98
99dnl Check whether the AI_ADDRCONFIG flag can be used with getaddrinfo
100AC_DEFUN([APR_CHECK_GETADDRINFO_ADDRCONFIG], [
101  AC_CACHE_CHECK(for working AI_ADDRCONFIG, apr_cv_gai_addrconfig, [
102  AC_TRY_RUN([
103#ifdef HAVE_NETDB_H
104#include <netdb.h>
105#endif
106#ifdef HAVE_STRING_H
107#include <string.h>
108#endif
109#ifdef HAVE_SYS_TYPES_H
110#include <sys/types.h>
111#endif
112#ifdef HAVE_SYS_SOCKET_H
113#include <sys/socket.h>
114#endif
115
116int main(int argc, char **argv) {
117    struct addrinfo hints, *ai;
118
119    memset(&hints, 0, sizeof(hints));
120    hints.ai_family = AF_UNSPEC;
121    hints.ai_socktype = SOCK_STREAM;
122    hints.ai_flags = AI_ADDRCONFIG;
123    return getaddrinfo("localhost", NULL, &hints, &ai) != 0;
124}], [apr_cv_gai_addrconfig=yes],
125    [apr_cv_gai_addrconfig=no],
126    [apr_cv_gai_addrconfig=no])])
127
128if test $apr_cv_gai_addrconfig = yes; then
129   AC_DEFINE(HAVE_GAI_ADDRCONFIG, 1, [Define if getaddrinfo accepts the AI_ADDRCONFIG flag])
130fi
131])
132
133dnl
134dnl check for working getnameinfo()
135dnl
136AC_DEFUN([APR_CHECK_WORKING_GETNAMEINFO], [
137  AC_CACHE_CHECK(for working getnameinfo, ac_cv_working_getnameinfo,[
138  AC_TRY_RUN( [
139#ifdef HAVE_NETDB_H
140#include <netdb.h>
141#endif
142#ifdef HAVE_STRING_H
143#include <string.h>
144#endif
145#ifdef HAVE_SYS_TYPES_H
146#include <sys/types.h>
147#endif
148#ifdef HAVE_SYS_SOCKET_H
149#include <sys/socket.h>
150#endif
151#ifdef HAVE_NETINET_IN_H
152#include <netinet/in.h>
153#endif
154
155int main(void) {
156    struct sockaddr_in sa;
157    char hbuf[256];
158    int error;
159
160    sa.sin_family = AF_INET;
161    sa.sin_port = 0;
162    sa.sin_addr.s_addr = inet_addr("127.0.0.1");
163#ifdef SIN6_LEN
164    sa.sin_len = sizeof(sa);
165#endif
166
167    error = getnameinfo((const struct sockaddr *)&sa, sizeof(sa),
168                        hbuf, 256, NULL, 0,
169                        NI_NUMERICHOST);
170    if (error) {
171        exit(1);
172    } else {
173        exit(0);
174    }
175}
176],[
177  ac_cv_working_getnameinfo="yes"
178],[
179  ac_cv_working_getnameinfo="no"
180],[
181  ac_cv_working_getnameinfo="yes"
182])])
183if test "$ac_cv_working_getnameinfo" = "yes"; then
184  AC_DEFINE(HAVE_GETNAMEINFO, 1, [Define if getnameinfo exists])
185fi
186])
187
188dnl
189dnl check for negative error codes for getaddrinfo()
190dnl
191AC_DEFUN([APR_CHECK_NEGATIVE_EAI], [
192  AC_CACHE_CHECK(for negative error codes for getaddrinfo, ac_cv_negative_eai,[
193  AC_TRY_RUN( [
194#ifdef HAVE_NETDB_H
195#include <netdb.h>
196#endif
197
198int main(void) {
199    if (EAI_ADDRFAMILY < 0) {
200        exit(0);
201    }
202    exit(1);
203}
204],[
205  ac_cv_negative_eai="yes"
206],[
207  ac_cv_negative_eai="no"
208],[
209  ac_cv_negative_eai="no"
210])])
211if test "$ac_cv_negative_eai" = "yes"; then
212  AC_DEFINE(NEGATIVE_EAI, 1, [Define if EAI_ error codes from getaddrinfo are negative])
213fi
214])
215
216dnl
217dnl Checks the definition of gethostbyname_r and gethostbyaddr_r
218dnl which are different for glibc, solaris and assorted other operating
219dnl systems
220dnl
221dnl Note that this test is executed too early to see if we have all of
222dnl the headers.
223AC_DEFUN([APR_CHECK_GETHOSTBYNAME_R_STYLE], [
224
225dnl Try and compile a glibc2 gethostbyname_r piece of code, and set the
226dnl style of the routines to glibc2 on success
227AC_CACHE_CHECK([style of gethostbyname_r routine], ac_cv_gethostbyname_r_style,
228APR_TRY_COMPILE_NO_WARNING([
229#ifdef HAVE_SYS_TYPES_H
230#include <sys/types.h>
231#endif
232#ifdef HAVE_NETINET_IN_H
233#include <netinet/in.h>
234#endif
235#ifdef HAVE_ARPA_INET_H
236#include <arpa/inet.h>
237#endif
238#ifdef HAVE_NETDB_H
239#include <netdb.h>
240#endif
241#ifdef HAVE_STDLIB_H
242#include <stdlib.h>
243#endif
244],[
245int tmp = gethostbyname_r((const char *) 0, (struct hostent *) 0,
246                          (char *) 0, 0, (struct hostent **) 0, &tmp);
247/* use tmp to suppress the warning */
248tmp=0;
249], ac_cv_gethostbyname_r_style=glibc2, ac_cv_gethostbyname_r_style=none))
250
251if test "$ac_cv_gethostbyname_r_style" = "glibc2"; then
252    AC_DEFINE(GETHOSTBYNAME_R_GLIBC2, 1, [Define if gethostbyname_r has the glibc style])
253fi
254
255AC_CACHE_CHECK([3rd argument to the gethostbyname_r routines], ac_cv_gethostbyname_r_arg,
256APR_TRY_COMPILE_NO_WARNING([
257#ifdef HAVE_SYS_TYPES_H
258#include <sys/types.h>
259#endif
260#ifdef HAVE_NETINET_IN_H
261#include <netinet/in.h>
262#endif
263#ifdef HAVE_ARPA_INET_H
264#include <arpa/inet.h>
265#endif
266#ifdef HAVE_NETDB_H
267#include <netdb.h>
268#endif
269#ifdef HAVE_STDLIB_H
270#include <stdlib.h>
271#endif
272],[
273int tmp = gethostbyname_r((const char *) 0, (struct hostent *) 0,
274                          (struct hostent_data *) 0);
275/* use tmp to suppress the warning */
276tmp=0;
277], ac_cv_gethostbyname_r_arg=hostent_data, ac_cv_gethostbyname_r_arg=char))
278
279if test "$ac_cv_gethostbyname_r_arg" = "hostent_data"; then
280    AC_DEFINE(GETHOSTBYNAME_R_HOSTENT_DATA, 1, [Define if gethostbyname_r has the hostent_data for the third argument])
281fi
282])
283
284dnl
285dnl Checks the definition of getservbyname_r
286dnl which are different for glibc, solaris and assorted other operating
287dnl systems
288dnl
289dnl Note that this test is executed too early to see if we have all of
290dnl the headers.
291AC_DEFUN([APR_CHECK_GETSERVBYNAME_R_STYLE], [
292
293dnl Try and compile a glibc2 getservbyname_r piece of code, and set the
294dnl style of the routines to glibc2 on success
295AC_CACHE_CHECK([style of getservbyname_r routine], ac_cv_getservbyname_r_style, [
296APR_TRY_COMPILE_NO_WARNING([
297#ifdef HAVE_SYS_TYPES_H
298#include <sys/types.h>
299#endif
300#ifdef HAVE_NETINET_IN_H
301#include <netinet/in.h>
302#endif
303#ifdef HAVE_ARPA_INET_H
304#include <arpa/inet.h>
305#endif
306#ifdef HAVE_NETDB_H
307#include <netdb.h>
308#endif
309#ifdef HAVE_STDLIB_H
310#include <stdlib.h>
311#endif
312],[
313int tmp = getservbyname_r((const char *) 0, (const char *) 0,
314                          (struct servent *) 0, (char *) 0, 0,
315                          (struct servent **) 0);
316/* use tmp to suppress the warning */
317tmp=0;
318], ac_cv_getservbyname_r_style=glibc2, ac_cv_getservbyname_r_style=none)
319
320if test "$ac_cv_getservbyname_r_style" = "none"; then
321    dnl Try and compile a Solaris getservbyname_r piece of code, and set the
322    dnl style of the routines to solaris on success
323    APR_TRY_COMPILE_NO_WARNING([
324    #ifdef HAVE_SYS_TYPES_H
325    #include <sys/types.h>
326    #endif
327    #ifdef HAVE_NETINET_IN_H
328    #include <netinet/in.h>
329    #endif
330    #ifdef HAVE_ARPA_INET_H
331    #include <arpa/inet.h>
332    #endif
333    #ifdef HAVE_NETDB_H
334    #include <netdb.h>
335    #endif
336    #ifdef HAVE_STDLIB_H
337    #include <stdlib.h>
338    #endif
339    ],[
340    struct servent *tmp = getservbyname_r((const char *) 0, (const char *) 0,
341                                          (struct servent *) 0, (char *) 0, 0);
342    /* use tmp to suppress the warning */
343    tmp=NULL;
344    ], ac_cv_getservbyname_r_style=solaris, ac_cv_getservbyname_r_style=none)
345fi
346
347if test "$ac_cv_getservbyname_r_style" = "none"; then
348    dnl Try and compile a OSF/1 getservbyname_r piece of code, and set the
349    dnl style of the routines to osf1 on success
350    APR_TRY_COMPILE_NO_WARNING([
351    #ifdef HAVE_SYS_TYPES_H
352    #include <sys/types.h>
353    #endif
354    #ifdef HAVE_NETINET_IN_H
355    #include <netinet/in.h>
356    #endif
357    #ifdef HAVE_ARPA_INET_H
358    #include <arpa/inet.h>
359    #endif
360    #ifdef HAVE_NETDB_H
361    #include <netdb.h>
362    #endif
363    #ifdef HAVE_STDLIB_H
364    #include <stdlib.h>
365    #endif
366    ],[
367    int tmp = getservbyname_r((const char *) 0, (const char *) 0,
368                              (struct servent *) 0, (struct servent_data *) 0);
369    /* use tmp to suppress the warning */
370    tmp=0;
371    ], ac_cv_getservbyname_r_style=osf1, ac_cv_getservbyname_r_style=none)
372fi
373])
374
375if test "$ac_cv_getservbyname_r_style" = "glibc2"; then
376    AC_DEFINE(GETSERVBYNAME_R_GLIBC2, 1, [Define if getservbyname_r has the glibc style])
377elif test "$ac_cv_getservbyname_r_style" = "solaris"; then
378    AC_DEFINE(GETSERVBYNAME_R_SOLARIS, 1, [Define if getservbyname_r has the Solaris style])
379elif test "$ac_cv_getservbyname_r_style" = "osf1"; then
380    AC_DEFINE(GETSERVBYNAME_R_OSF1, 1, [Define if getservbyname_r has the OSF/1 style])
381fi
382])
383
384dnl
385dnl see if TCP_NODELAY setting is inherited from listening sockets
386dnl
387AC_DEFUN([APR_CHECK_TCP_NODELAY_INHERITED], [
388  AC_CACHE_CHECK(if TCP_NODELAY setting is inherited from listening sockets, ac_cv_tcp_nodelay_inherited,[
389  AC_TRY_RUN( [
390#include <stdio.h>
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_NETINET_IN_H
398#include <netinet/in.h>
399#endif
400#ifdef HAVE_NETINET_TCP_H
401#include <netinet/tcp.h>
402#endif
403#ifndef HAVE_SOCKLEN_T
404typedef int socklen_t;
405#endif
406int main(void) {
407    int listen_s, connected_s, client_s;
408    int listen_port, rc;
409    struct sockaddr_in sa;
410    socklen_t sa_len;
411    socklen_t option_len;
412    int option;
413
414    listen_s = socket(AF_INET, SOCK_STREAM, 0);
415    if (listen_s < 0) {
416        perror("socket");
417        exit(1);
418    }
419    option = 1;
420    rc = setsockopt(listen_s, IPPROTO_TCP, TCP_NODELAY, &option, sizeof option);
421    if (rc < 0) {
422        perror("setsockopt TCP_NODELAY");
423        exit(1);
424    }
425    memset(&sa, 0, sizeof sa);
426    sa.sin_family = AF_INET;
427#ifdef BEOS
428    sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
429#endif
430    /* leave port 0 to get ephemeral */
431    rc = bind(listen_s, (struct sockaddr *)&sa, sizeof sa);
432    if (rc < 0) {
433        perror("bind for ephemeral port");
434        exit(1);
435    }
436    /* find ephemeral port */
437    sa_len = sizeof(sa);
438    rc = getsockname(listen_s, (struct sockaddr *)&sa, &sa_len);
439    if (rc < 0) {
440        perror("getsockname");
441        exit(1);
442    }
443    listen_port = sa.sin_port;
444    rc = listen(listen_s, 5);
445    if (rc < 0) {
446        perror("listen");
447        exit(1);
448    }
449    client_s = socket(AF_INET, SOCK_STREAM, 0);
450    if (client_s < 0) {
451        perror("socket");
452        exit(1);
453    }
454    memset(&sa, 0, sizeof sa);
455    sa.sin_family = AF_INET;
456    sa.sin_port   = listen_port;
457#ifdef BEOS
458    sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
459#endif
460    /* leave sin_addr all zeros to use loopback */
461    rc = connect(client_s, (struct sockaddr *)&sa, sizeof sa);
462    if (rc < 0) {
463        perror("connect");
464        exit(1);
465    }
466    sa_len = sizeof sa;
467    connected_s = accept(listen_s, (struct sockaddr *)&sa, &sa_len);
468    if (connected_s < 0) {
469        perror("accept");
470        exit(1);
471    }
472    option_len = sizeof option;
473    rc = getsockopt(connected_s, IPPROTO_TCP, TCP_NODELAY, &option, &option_len);
474    if (rc < 0) {
475        perror("getsockopt");
476        exit(1);
477    }
478    if (!option) {
479        fprintf(stderr, "TCP_NODELAY is not set in the child.\n");
480        exit(1);
481    }
482    return 0;
483}
484],[
485    ac_cv_tcp_nodelay_inherited="yes"
486],[
487    ac_cv_tcp_nodelay_inherited="no"
488],[
489    ac_cv_tcp_nodelay_inherited="yes"
490])])
491if test "$ac_cv_tcp_nodelay_inherited" = "yes"; then
492    tcp_nodelay_inherited=1
493else
494    tcp_nodelay_inherited=0
495fi
496])
497
498dnl
499dnl Determine whether TCP_NODELAY and TCP_CORK can both be set
500dnl on a TCP socket.
501dnl
502AC_DEFUN([APR_CHECK_TCP_NODELAY_WITH_CORK], [
503AC_CACHE_CHECK([whether TCP_NODELAY and TCP_CORK can both be enabled],
504[apr_cv_tcp_nodelay_with_cork],
505[AC_RUN_IFELSE([AC_LANG_PROGRAM([[
506#ifdef HAVE_SYS_TYPES_H
507#include <sys/types.h>
508#endif
509#ifdef HAVE_SYS_SOCKET_H
510#include <sys/socket.h>
511#endif
512#ifdef HAVE_NETINET_IN_H
513#include <netinet/in.h>
514#endif
515#ifdef HAVE_NETINET_TCP_H
516#include <netinet/tcp.h>
517#endif
518#include <stdio.h>
519#include <stdlib.h>
520]], [[
521    int fd, flag, rc;
522
523    fd = socket(AF_INET, SOCK_STREAM, 0);
524    if (fd < 0) {
525       exit(1);
526    }
527
528    flag = 1;
529    rc = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof flag);
530    if (rc < 0) {
531        perror("setsockopt TCP_NODELAY");
532        exit(2);
533    }
534
535    flag = 1;
536    rc = setsockopt(fd, IPPROTO_TCP, TCP_CORK, &flag, sizeof flag);
537    if (rc < 0) {
538        perror("setsockopt TCP_CORK");
539        exit(3);
540    }
541
542    exit(0);
543]])], [apr_cv_tcp_nodelay_with_cork=yes], [apr_cv_tcp_nodelay_with_cork=no])])
544
545if test "$apr_cv_tcp_nodelay_with_cork" = "yes"; then
546  AC_DEFINE([HAVE_TCP_NODELAY_WITH_CORK], 1,
547            [Define if TCP_NODELAY and TCP_CORK can be enabled at the same time])
548fi
549])
550
551
552dnl
553dnl see if O_NONBLOCK setting is inherited from listening sockets
554dnl
555AC_DEFUN([APR_CHECK_O_NONBLOCK_INHERITED], [
556  AC_CACHE_CHECK(if O_NONBLOCK setting is inherited from listening sockets, ac_cv_o_nonblock_inherited,[
557  AC_TRY_RUN( [
558#ifdef HAVE_STDLIB_H
559#include <stdlib.h>
560#endif
561#ifdef HAVE_STRING_H
562#include <string.h>
563#endif
564#ifdef HAVE_STDIO_H
565#include <stdio.h>
566#endif
567#ifdef HAVE_SYS_TYPES_H
568#include <sys/types.h>
569#endif
570#ifdef HAVE_SYS_SOCKET_H
571#include <sys/socket.h>
572#endif
573#ifdef HAVE_SYS_TIME_H
574#include <sys/time.h>
575#endif
576#ifdef HAVE_SYS_SELECT_H
577#include <sys/select.h>
578#endif
579#ifdef HAVE_NETINET_IN_H
580#include <netinet/in.h>
581#endif
582#ifdef HAVE_NETINET_TCP_H
583#include <netinet/tcp.h>
584#endif
585#ifndef HAVE_SOCKLEN_T
586typedef int socklen_t;
587#endif
588#ifdef HAVE_FCNTL_H
589#include <fcntl.h>
590#endif
591int main(void) {
592    int listen_s, connected_s, client_s;
593    int listen_port, rc;
594    struct sockaddr_in sa;
595    socklen_t sa_len;
596    fd_set fds;
597    struct timeval tv;
598
599    listen_s = socket(AF_INET, SOCK_STREAM, 0);
600    if (listen_s < 0) {
601        perror("socket");
602        exit(1);
603    }
604    memset(&sa, 0, sizeof sa);
605    sa.sin_family = AF_INET;
606#ifdef BEOS
607    sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
608#endif
609    /* leave port 0 to get ephemeral */
610    rc = bind(listen_s, (struct sockaddr *)&sa, sizeof sa);
611    if (rc < 0) {
612        perror("bind for ephemeral port");
613        exit(1);
614    }
615    /* find ephemeral port */
616    sa_len = sizeof(sa);
617    rc = getsockname(listen_s, (struct sockaddr *)&sa, &sa_len);
618    if (rc < 0) {
619        perror("getsockname");
620        exit(1);
621    }
622    listen_port = sa.sin_port;
623    rc = listen(listen_s, 5);
624    if (rc < 0) {
625        perror("listen");
626        exit(1);
627    }
628    rc = fcntl(listen_s, F_SETFL, O_NONBLOCK);
629    if (rc < 0) {
630        perror("fcntl(F_SETFL)");
631        exit(1);
632    }
633    client_s = socket(AF_INET, SOCK_STREAM, 0);
634    if (client_s < 0) {
635        perror("socket");
636        exit(1);
637    }
638    memset(&sa, 0, sizeof sa);
639    sa.sin_family = AF_INET;
640    sa.sin_port   = listen_port;
641#ifdef BEOS
642    sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
643#endif
644    /* leave sin_addr all zeros to use loopback */
645    rc = connect(client_s, (struct sockaddr *)&sa, sizeof sa);
646    if (rc < 0) {
647        perror("connect");
648        exit(1);
649    }
650    sa_len = sizeof sa;
651    /* 1 second select timeout */
652    tv.tv_sec = 1;
653    tv.tv_usec = 0;
654    /* Set up fd set */
655    FD_ZERO(&fds);
656    FD_SET(listen_s, &fds);
657    /* Wait for socket to become readable */
658    rc = select(listen_s + 1, &fds, NULL, NULL, &tv);
659    if (rc < 0) {
660        perror("select");
661        exit(1);
662    }
663    if (rc == 0) {
664        fprintf(stderr, "Socket failed to become readable (timeout)\n");
665        exit(1);
666    }
667    if (!FD_ISSET(listen_s, &fds)) {
668        fprintf(stderr, "Socket failed to become readable (selected another fd)\n");
669        exit(1);
670    }
671    connected_s = accept(listen_s, (struct sockaddr *)&sa, &sa_len);
672    if (connected_s < 0) {
673        perror("accept");
674        exit(1);
675    }
676    rc = fcntl(connected_s, F_GETFL, 0);
677    if (rc < 0) {
678        perror("fcntl(F_GETFL)");
679        exit(1);
680    }
681    if (!(rc & O_NONBLOCK)) {
682        fprintf(stderr, "O_NONBLOCK is not set in the child.\n");
683        exit(1);
684    }
685    return 0;
686}
687],[
688    ac_cv_o_nonblock_inherited="yes"
689],[
690    ac_cv_o_nonblock_inherited="no"
691],[
692    ac_cv_o_nonblock_inherited="yes"
693])])
694if test "$ac_cv_o_nonblock_inherited" = "yes"; then
695    o_nonblock_inherited=1
696else
697    o_nonblock_inherited=0
698fi
699])
700
701dnl
702dnl check for socklen_t, fall back to unsigned int
703dnl
704AC_DEFUN([APR_CHECK_SOCKLEN_T], [
705AC_CACHE_CHECK(for socklen_t, ac_cv_socklen_t,[
706AC_TRY_COMPILE([
707#ifdef HAVE_SYS_TYPES_H
708#include <sys/types.h>
709#endif
710#ifdef HAVE_SYS_SOCKET_H
711#include <sys/socket.h>
712#endif
713],[
714socklen_t foo = (socklen_t) 0;
715],[
716    ac_cv_socklen_t=yes
717],[
718    ac_cv_socklen_t=no
719])
720])
721
722if test "$ac_cv_socklen_t" = "yes"; then
723  AC_DEFINE(HAVE_SOCKLEN_T, 1, [Whether you have socklen_t])
724fi
725])
726
727
728AC_DEFUN([APR_CHECK_INET_ADDR], [
729AC_CACHE_CHECK(for inet_addr, ac_cv_func_inet_addr,[
730AC_TRY_COMPILE([
731#ifdef HAVE_SYS_TYPES_H
732#include <sys/types.h>
733#endif
734#ifdef HAVE_ARPA_INET_H
735#include <arpa/inet.h>
736#endif
737],[
738inet_addr("127.0.0.1");
739],[
740    ac_cv_func_inet_addr=yes
741],[
742    ac_cv_func_inet_addr=no
743])
744])
745
746if test "$ac_cv_func_inet_addr" = "yes"; then
747  have_inet_addr=1
748else
749  have_inet_addr=0
750fi
751])
752
753
754AC_DEFUN([APR_CHECK_INET_NETWORK], [
755AC_CACHE_CHECK(for inet_network, ac_cv_func_inet_network,[
756AC_TRY_COMPILE([
757#ifdef HAVE_SYS_TYPES_H
758#include <sys/types.h>
759#endif
760#ifdef HAVE_ARPA_INET_H
761#include <arpa/inet.h>
762#endif
763],[
764inet_network("127.0.0.1");
765],[
766    ac_cv_func_inet_network=yes
767],[
768    ac_cv_func_inet_network=no
769])
770])
771
772if test "$ac_cv_func_inet_network" = "yes"; then
773  have_inet_network=1
774else
775  have_inet_network=0
776fi
777])
778
779dnl Check for presence of struct sockaddr_storage.
780AC_DEFUN([APR_CHECK_SOCKADDR_STORAGE], [
781AC_CACHE_CHECK(for sockaddr_storage, apr_cv_define_sockaddr_storage,[
782AC_TRY_COMPILE([
783#ifdef HAVE_SYS_TYPES_H
784#include <sys/types.h>
785#endif
786#ifdef HAVE_NETINET_IN_H
787#include <netinet/in.h>
788#endif
789],[struct sockaddr_storage sa;],
790[apr_cv_define_sockaddr_storage=yes],
791[apr_cv_define_sockaddr_storage=no])])
792
793if test "$apr_cv_define_sockaddr_storage" = "yes"; then
794  have_sa_storage=1
795else
796  have_sa_storage=0
797fi
798AC_SUBST(have_sa_storage)
799])
800
801dnl Check for presence of struct sockaddr_in6.
802AC_DEFUN([APR_CHECK_SOCKADDR_IN6], [
803AC_CACHE_CHECK(for sockaddr_in6, ac_cv_define_sockaddr_in6,[
804AC_TRY_COMPILE([
805#ifdef HAVE_SYS_TYPES_H
806#include <sys/types.h>
807#endif
808#ifdef HAVE_NETINET_IN_H
809#include <netinet/in.h>
810#endif
811],[
812struct sockaddr_in6 sa;
813],[
814    ac_cv_define_sockaddr_in6=yes
815],[
816    ac_cv_define_sockaddr_in6=no
817])
818])
819
820if test "$ac_cv_define_sockaddr_in6" = "yes"; then
821  have_sockaddr_in6=1
822else
823  have_sockaddr_in6=0
824fi
825])
826
827dnl
828dnl APR_H_ERRNO_COMPILE_CHECK
829dnl
830AC_DEFUN([APR_H_ERRNO_COMPILE_CHECK], [
831  if test x$1 != x; then
832    CPPFLAGS="-D$1 $CPPFLAGS"
833  fi
834  AC_TRY_COMPILE([
835#ifdef HAVE_SYS_TYPES_H
836#include <sys/types.h>
837#endif
838#ifdef HAVE_NETDB_H
839#include <netdb.h>
840#endif
841],[
842int h_e = h_errno;
843],[
844  if test x$1 != x; then
845    ac_cv_h_errno_cppflags="$1"
846  else
847    ac_cv_h_errno_cppflags=yes
848  fi
849],[
850  ac_cv_h_errno_cppflags=no
851])])
852
853
854dnl
855dnl APR_CHECK_SCTP
856dnl
857dnl check for presence of SCTP protocol support
858dnl
859AC_DEFUN([APR_CHECK_SCTP],
860[
861  AC_CACHE_CHECK([whether SCTP is supported], [apr_cv_sctp], [
862  AC_TRY_RUN([
863#ifdef HAVE_SYS_TYPES_H
864#include <sys/types.h>
865#endif
866#ifdef HAVE_SYS_SOCKET_H
867#include <sys/socket.h>
868#endif
869#ifdef HAVE_NETINET_IN_H
870#include <netinet/in.h>
871#endif
872#ifdef HAVE_NETINET_SCTP_H
873#include <netinet/sctp.h>
874#endif
875#ifdef HAVE_NETINET_SCTP_UIO_H
876#include <netinet/sctp_uio.h>
877#endif
878#include <stdlib.h>
879int main(void) {
880    int s, opt = 1;
881    if ((s = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP)) < 0)
882       exit(1);
883    if (setsockopt(s, IPPROTO_SCTP, SCTP_NODELAY, &opt, sizeof(int)) < 0)
884       exit(2);
885    exit(0);
886}], [apr_cv_sctp=yes], [apr_cv_sctp=no], [apr_cv_sctp=no])])
887
888if test "$apr_cv_sctp" = "yes"; then
889    have_sctp=1
890else
891    have_sctp=0
892fi
893])
894
895dnl APR_CHECK_MCAST: check for multicast interfaces
896AC_DEFUN([APR_CHECK_MCAST], [
897AC_CACHE_CHECK([for struct ip_mreq], [apr_cv_struct_ipmreq], [
898AC_TRY_COMPILE([
899#include <sys/types.h>
900#include <netinet/in.h>
901], [
902    struct ip_mreq mip;
903    mip.imr_interface.s_addr = INADDR_ANY;
904], [apr_cv_struct_ipmreq=yes], [apr_cv_struct_ipmreq=no], [apr_cv_struct_ipmreq=yes])])
905
906if test $apr_cv_struct_ipmreq = yes; then
907   AC_DEFINE([HAVE_STRUCT_IPMREQ], 1, [Define if struct impreq was found])
908fi
909])
910
911dnl
912dnl APR_CHECK_H_ERRNO_FLAG
913dnl
914dnl checks which flags are necessary for <netdb.h> to define h_errno
915dnl
916AC_DEFUN([APR_CHECK_H_ERRNO_FLAG], [
917  AC_MSG_CHECKING([for h_errno in netdb.h])
918  AC_CACHE_VAL(ac_cv_h_errno_cppflags,[
919    APR_H_ERRNO_COMPILE_CHECK
920    if test "$ac_cv_h_errno_cppflags" = "no"; then
921      ac_save="$CPPFLAGS"
922      for flag in _XOPEN_SOURCE_EXTENDED; do
923        APR_H_ERRNO_COMPILE_CHECK($flag)
924        if test "$ac_cv_h_errno_cppflags" != "no"; then
925          break
926        fi
927      done
928      CPPFLAGS="$ac_save"
929    fi
930  ])
931  if test "$ac_cv_h_errno_cppflags" != "no"; then
932    if test "$ac_cv_h_errno_cppflags" != "yes"; then
933      CPPFLAGS="-D$ac_cv_h_errno_cppflags $CPPFLAGS"
934      AC_MSG_RESULT([yes, with -D$ac_cv_h_errno_cppflags])
935    else
936      AC_MSG_RESULT([$ac_cv_h_errno_cppflags])
937    fi
938  else
939    AC_MSG_RESULT([$ac_cv_h_errno_cppflags])
940  fi
941])
942
943
944AC_DEFUN([APR_EBCDIC], [
945  AC_CACHE_CHECK([whether system uses EBCDIC],ac_cv_ebcdic,[
946  AC_TRY_RUN( [
947int main(void) {
948  return (unsigned char)'A' != (unsigned char)0xC1;
949}
950],[
951  ac_cv_ebcdic="yes"
952],[
953  ac_cv_ebcdic="no"
954],[
955  ac_cv_ebcdic="no"
956])])
957  if test "$ac_cv_ebcdic" = "yes"; then
958    apr_charset_ebcdic=1
959  else
960    apr_charset_ebcdic=0
961  fi
962  AC_SUBST(apr_charset_ebcdic)
963])
964
965