apr_network.m4 22 KB

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