apr_network.m4 19 KB

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