PageRenderTime 63ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/srclib/apr/include/apr_network_io.h

https://bitbucket.org/gencer/apache2nginx
C Header | 857 lines | 227 code | 78 blank | 552 comment | 2 complexity | b1456d2d034b7bec7b41a00a717f4eeb MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef APR_NETWORK_IO_H
  17. #define APR_NETWORK_IO_H
  18. /**
  19. * @file apr_network_io.h
  20. * @brief APR Network library
  21. */
  22. #include "apr.h"
  23. #include "apr_pools.h"
  24. #include "apr_file_io.h"
  25. #include "apr_errno.h"
  26. #include "apr_inherit.h"
  27. #if APR_HAVE_NETINET_IN_H
  28. #include <netinet/in.h>
  29. #endif
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif /* __cplusplus */
  33. /**
  34. * @defgroup apr_network_io Network Routines
  35. * @ingroup APR
  36. * @{
  37. */
  38. #ifndef APR_MAX_SECS_TO_LINGER
  39. /** Maximum seconds to linger */
  40. #define APR_MAX_SECS_TO_LINGER 30
  41. #endif
  42. #ifndef APRMAXHOSTLEN
  43. /** Maximum hostname length */
  44. #define APRMAXHOSTLEN 256
  45. #endif
  46. #ifndef APR_ANYADDR
  47. /** Default 'any' address */
  48. #define APR_ANYADDR "0.0.0.0"
  49. #endif
  50. /**
  51. * @defgroup apr_sockopt Socket option definitions
  52. * @{
  53. */
  54. #define APR_SO_LINGER 1 /**< Linger */
  55. #define APR_SO_KEEPALIVE 2 /**< Keepalive */
  56. #define APR_SO_DEBUG 4 /**< Debug */
  57. #define APR_SO_NONBLOCK 8 /**< Non-blocking IO */
  58. #define APR_SO_REUSEADDR 16 /**< Reuse addresses */
  59. #define APR_SO_SNDBUF 64 /**< Send buffer */
  60. #define APR_SO_RCVBUF 128 /**< Receive buffer */
  61. #define APR_SO_DISCONNECTED 256 /**< Disconnected */
  62. #define APR_TCP_NODELAY 512 /**< For SCTP sockets, this is mapped
  63. * to STCP_NODELAY internally.
  64. */
  65. #define APR_TCP_NOPUSH 1024 /**< No push */
  66. #define APR_RESET_NODELAY 2048 /**< This flag is ONLY set internally
  67. * when we set APR_TCP_NOPUSH with
  68. * APR_TCP_NODELAY set to tell us that
  69. * APR_TCP_NODELAY should be turned on
  70. * again when NOPUSH is turned off
  71. */
  72. #define APR_INCOMPLETE_READ 4096 /**< Set on non-blocking sockets
  73. * (timeout != 0) on which the
  74. * previous read() did not fill a buffer
  75. * completely. the next apr_socket_recv()
  76. * will first call select()/poll() rather than
  77. * going straight into read(). (Can also
  78. * be set by an application to force a
  79. * select()/poll() call before the next
  80. * read, in cases where the app expects
  81. * that an immediate read would fail.)
  82. */
  83. #define APR_INCOMPLETE_WRITE 8192 /**< like APR_INCOMPLETE_READ, but for write
  84. * @see APR_INCOMPLETE_READ
  85. */
  86. #define APR_IPV6_V6ONLY 16384 /**< Don't accept IPv4 connections on an
  87. * IPv6 listening socket.
  88. */
  89. #define APR_TCP_DEFER_ACCEPT 32768 /**< Delay accepting of new connections
  90. * until data is available.
  91. * @see apr_socket_accept_filter
  92. */
  93. /** @} */
  94. /** Define what type of socket shutdown should occur. */
  95. typedef enum {
  96. APR_SHUTDOWN_READ, /**< no longer allow read request */
  97. APR_SHUTDOWN_WRITE, /**< no longer allow write requests */
  98. APR_SHUTDOWN_READWRITE /**< no longer allow read or write requests */
  99. } apr_shutdown_how_e;
  100. #define APR_IPV4_ADDR_OK 0x01 /**< @see apr_sockaddr_info_get() */
  101. #define APR_IPV6_ADDR_OK 0x02 /**< @see apr_sockaddr_info_get() */
  102. #if (!APR_HAVE_IN_ADDR)
  103. /**
  104. * We need to make sure we always have an in_addr type, so APR will just
  105. * define it ourselves, if the platform doesn't provide it.
  106. */
  107. struct in_addr {
  108. apr_uint32_t s_addr; /**< storage to hold the IP# */
  109. };
  110. #endif
  111. /** @def APR_INADDR_NONE
  112. * Not all platforms have a real INADDR_NONE. This macro replaces
  113. * INADDR_NONE on all platforms.
  114. */
  115. #ifdef INADDR_NONE
  116. #define APR_INADDR_NONE INADDR_NONE
  117. #else
  118. #define APR_INADDR_NONE ((unsigned int) 0xffffffff)
  119. #endif
  120. /**
  121. * @def APR_INET
  122. * Not all platforms have these defined, so we'll define them here
  123. * The default values come from FreeBSD 4.1.1
  124. */
  125. #define APR_INET AF_INET
  126. /** @def APR_UNSPEC
  127. * Let the system decide which address family to use
  128. */
  129. #ifdef AF_UNSPEC
  130. #define APR_UNSPEC AF_UNSPEC
  131. #else
  132. #define APR_UNSPEC 0
  133. #endif
  134. #if APR_HAVE_IPV6
  135. /** @def APR_INET6
  136. * IPv6 Address Family. Not all platforms may have this defined.
  137. */
  138. #define APR_INET6 AF_INET6
  139. #endif
  140. /**
  141. * @defgroup IP_Proto IP Protocol Definitions for use when creating sockets
  142. * @{
  143. */
  144. #define APR_PROTO_TCP 6 /**< TCP */
  145. #define APR_PROTO_UDP 17 /**< UDP */
  146. #define APR_PROTO_SCTP 132 /**< SCTP */
  147. /** @} */
  148. /**
  149. * Enum used to denote either the local and remote endpoint of a
  150. * connection.
  151. */
  152. typedef enum {
  153. APR_LOCAL, /**< Socket information for local end of connection */
  154. APR_REMOTE /**< Socket information for remote end of connection */
  155. } apr_interface_e;
  156. /**
  157. * The specific declaration of inet_addr's ... some platforms fall back
  158. * inet_network (this is not good, but necessary)
  159. */
  160. #if APR_HAVE_INET_ADDR
  161. #define apr_inet_addr inet_addr
  162. #elif APR_HAVE_INET_NETWORK /* only DGUX, as far as I know */
  163. /**
  164. * @warning
  165. * not generally safe... inet_network() and inet_addr() perform
  166. * different functions */
  167. #define apr_inet_addr inet_network
  168. #endif
  169. /** A structure to represent sockets */
  170. typedef struct apr_socket_t apr_socket_t;
  171. /**
  172. * A structure to encapsulate headers and trailers for apr_socket_sendfile
  173. */
  174. typedef struct apr_hdtr_t apr_hdtr_t;
  175. /** A structure to represent in_addr */
  176. typedef struct in_addr apr_in_addr_t;
  177. /** A structure to represent an IP subnet */
  178. typedef struct apr_ipsubnet_t apr_ipsubnet_t;
  179. /** @remark use apr_uint16_t just in case some system has a short that isn't 16 bits... */
  180. typedef apr_uint16_t apr_port_t;
  181. /** @remark It's defined here as I think it should all be platform safe...
  182. * @see apr_sockaddr_t
  183. */
  184. typedef struct apr_sockaddr_t apr_sockaddr_t;
  185. /**
  186. * APRs socket address type, used to ensure protocol independence
  187. */
  188. struct apr_sockaddr_t {
  189. /** The pool to use... */
  190. apr_pool_t *pool;
  191. /** The hostname */
  192. char *hostname;
  193. /** Either a string of the port number or the service name for the port */
  194. char *servname;
  195. /** The numeric port */
  196. apr_port_t port;
  197. /** The family */
  198. apr_int32_t family;
  199. /** How big is the sockaddr we're using? */
  200. apr_socklen_t salen;
  201. /** How big is the ip address structure we're using? */
  202. int ipaddr_len;
  203. /** How big should the address buffer be? 16 for v4 or 46 for v6
  204. * used in inet_ntop... */
  205. int addr_str_len;
  206. /** This points to the IP address structure within the appropriate
  207. * sockaddr structure. */
  208. void *ipaddr_ptr;
  209. /** If multiple addresses were found by apr_sockaddr_info_get(), this
  210. * points to a representation of the next address. */
  211. apr_sockaddr_t *next;
  212. /** Union of either IPv4 or IPv6 sockaddr. */
  213. union {
  214. /** IPv4 sockaddr structure */
  215. struct sockaddr_in sin;
  216. #if APR_HAVE_IPV6
  217. /** IPv6 sockaddr structure */
  218. struct sockaddr_in6 sin6;
  219. #endif
  220. #if APR_HAVE_SA_STORAGE
  221. /** Placeholder to ensure that the size of this union is not
  222. * dependent on whether APR_HAVE_IPV6 is defined. */
  223. struct sockaddr_storage sas;
  224. #endif
  225. } sa;
  226. };
  227. #if APR_HAS_SENDFILE
  228. /**
  229. * Support reusing the socket on platforms which support it (from disconnect,
  230. * specifically Win32.
  231. * @remark Optional flag passed into apr_socket_sendfile()
  232. */
  233. #define APR_SENDFILE_DISCONNECT_SOCKET 1
  234. #endif
  235. /** A structure to encapsulate headers and trailers for apr_socket_sendfile */
  236. struct apr_hdtr_t {
  237. /** An iovec to store the headers sent before the file. */
  238. struct iovec* headers;
  239. /** number of headers in the iovec */
  240. int numheaders;
  241. /** An iovec to store the trailers sent after the file. */
  242. struct iovec* trailers;
  243. /** number of trailers in the iovec */
  244. int numtrailers;
  245. };
  246. /* function definitions */
  247. /**
  248. * Create a socket.
  249. * @param new_sock The new socket that has been set up.
  250. * @param family The address family of the socket (e.g., APR_INET).
  251. * @param type The type of the socket (e.g., SOCK_STREAM).
  252. * @param protocol The protocol of the socket (e.g., APR_PROTO_TCP).
  253. * @param cont The pool for the apr_socket_t and associated storage.
  254. */
  255. APR_DECLARE(apr_status_t) apr_socket_create(apr_socket_t **new_sock,
  256. int family, int type,
  257. int protocol,
  258. apr_pool_t *cont);
  259. /**
  260. * Shutdown either reading, writing, or both sides of a socket.
  261. * @param thesocket The socket to close
  262. * @param how How to shutdown the socket. One of:
  263. * <PRE>
  264. * APR_SHUTDOWN_READ no longer allow read requests
  265. * APR_SHUTDOWN_WRITE no longer allow write requests
  266. * APR_SHUTDOWN_READWRITE no longer allow read or write requests
  267. * </PRE>
  268. * @see apr_shutdown_how_e
  269. * @remark This does not actually close the socket descriptor, it just
  270. * controls which calls are still valid on the socket.
  271. */
  272. APR_DECLARE(apr_status_t) apr_socket_shutdown(apr_socket_t *thesocket,
  273. apr_shutdown_how_e how);
  274. /**
  275. * Close a socket.
  276. * @param thesocket The socket to close
  277. */
  278. APR_DECLARE(apr_status_t) apr_socket_close(apr_socket_t *thesocket);
  279. /**
  280. * Bind the socket to its associated port
  281. * @param sock The socket to bind
  282. * @param sa The socket address to bind to
  283. * @remark This may be where we will find out if there is any other process
  284. * using the selected port.
  285. */
  286. APR_DECLARE(apr_status_t) apr_socket_bind(apr_socket_t *sock,
  287. apr_sockaddr_t *sa);
  288. /**
  289. * Listen to a bound socket for connections.
  290. * @param sock The socket to listen on
  291. * @param backlog The number of outstanding connections allowed in the sockets
  292. * listen queue. If this value is less than zero, the listen
  293. * queue size is set to zero.
  294. */
  295. APR_DECLARE(apr_status_t) apr_socket_listen(apr_socket_t *sock,
  296. apr_int32_t backlog);
  297. /**
  298. * Accept a new connection request
  299. * @param new_sock A copy of the socket that is connected to the socket that
  300. * made the connection request. This is the socket which should
  301. * be used for all future communication.
  302. * @param sock The socket we are listening on.
  303. * @param connection_pool The pool for the new socket.
  304. */
  305. APR_DECLARE(apr_status_t) apr_socket_accept(apr_socket_t **new_sock,
  306. apr_socket_t *sock,
  307. apr_pool_t *connection_pool);
  308. /**
  309. * Issue a connection request to a socket either on the same machine
  310. * or a different one.
  311. * @param sock The socket we wish to use for our side of the connection
  312. * @param sa The address of the machine we wish to connect to.
  313. */
  314. APR_DECLARE(apr_status_t) apr_socket_connect(apr_socket_t *sock,
  315. apr_sockaddr_t *sa);
  316. /**
  317. * Determine whether the receive part of the socket has been closed by
  318. * the peer (such that a subsequent call to apr_socket_read would
  319. * return APR_EOF), if the socket's receive buffer is empty. This
  320. * function does not block waiting for I/O.
  321. *
  322. * @param sock The socket to check
  323. * @param atreadeof If APR_SUCCESS is returned, *atreadeof is set to
  324. * non-zero if a subsequent read would return APR_EOF
  325. * @return an error is returned if it was not possible to determine the
  326. * status, in which case *atreadeof is not changed.
  327. */
  328. APR_DECLARE(apr_status_t) apr_socket_atreadeof(apr_socket_t *sock,
  329. int *atreadeof);
  330. /**
  331. * Create apr_sockaddr_t from hostname, address family, and port.
  332. * @param sa The new apr_sockaddr_t.
  333. * @param hostname The hostname or numeric address string to resolve/parse, or
  334. * NULL to build an address that corresponds to 0.0.0.0 or ::
  335. * @param family The address family to use, or APR_UNSPEC if the system should
  336. * decide.
  337. * @param port The port number.
  338. * @param flags Special processing flags:
  339. * <PRE>
  340. * APR_IPV4_ADDR_OK first query for IPv4 addresses; only look
  341. * for IPv6 addresses if the first query failed;
  342. * only valid if family is APR_UNSPEC and hostname
  343. * isn't NULL; mutually exclusive with
  344. * APR_IPV6_ADDR_OK
  345. * APR_IPV6_ADDR_OK first query for IPv6 addresses; only look
  346. * for IPv4 addresses if the first query failed;
  347. * only valid if family is APR_UNSPEC and hostname
  348. * isn't NULL and APR_HAVE_IPV6; mutually exclusive
  349. * with APR_IPV4_ADDR_OK
  350. * </PRE>
  351. * @param p The pool for the apr_sockaddr_t and associated storage.
  352. */
  353. APR_DECLARE(apr_status_t) apr_sockaddr_info_get(apr_sockaddr_t **sa,
  354. const char *hostname,
  355. apr_int32_t family,
  356. apr_port_t port,
  357. apr_int32_t flags,
  358. apr_pool_t *p);
  359. /**
  360. * Look up the host name from an apr_sockaddr_t.
  361. * @param hostname The hostname.
  362. * @param sa The apr_sockaddr_t.
  363. * @param flags Special processing flags.
  364. */
  365. APR_DECLARE(apr_status_t) apr_getnameinfo(char **hostname,
  366. apr_sockaddr_t *sa,
  367. apr_int32_t flags);
  368. /**
  369. * Parse hostname/IP address with scope id and port.
  370. *
  371. * Any of the following strings are accepted:
  372. * 8080 (just the port number)
  373. * www.apache.org (just the hostname)
  374. * www.apache.org:8080 (hostname and port number)
  375. * [fe80::1]:80 (IPv6 numeric address string only)
  376. * [fe80::1%eth0] (IPv6 numeric address string and scope id)
  377. *
  378. * Invalid strings:
  379. * (empty string)
  380. * [abc] (not valid IPv6 numeric address string)
  381. * abc:65536 (invalid port number)
  382. *
  383. * @param addr The new buffer containing just the hostname. On output, *addr
  384. * will be NULL if no hostname/IP address was specfied.
  385. * @param scope_id The new buffer containing just the scope id. On output,
  386. * *scope_id will be NULL if no scope id was specified.
  387. * @param port The port number. On output, *port will be 0 if no port was
  388. * specified.
  389. * ### FIXME: 0 is a legal port (per RFC 1700). this should
  390. * ### return something besides zero if the port is missing.
  391. * @param str The input string to be parsed.
  392. * @param p The pool from which *addr and *scope_id are allocated.
  393. * @remark If scope id shouldn't be allowed, check for scope_id != NULL in
  394. * addition to checking the return code. If addr/hostname should be
  395. * required, check for addr == NULL in addition to checking the
  396. * return code.
  397. */
  398. APR_DECLARE(apr_status_t) apr_parse_addr_port(char **addr,
  399. char **scope_id,
  400. apr_port_t *port,
  401. const char *str,
  402. apr_pool_t *p);
  403. /**
  404. * Get name of the current machine
  405. * @param buf A buffer to store the hostname in.
  406. * @param len The maximum length of the hostname that can be stored in the
  407. * buffer provided. The suggested length is APRMAXHOSTLEN + 1.
  408. * @param cont The pool to use.
  409. * @remark If the buffer was not large enough, an error will be returned.
  410. */
  411. APR_DECLARE(apr_status_t) apr_gethostname(char *buf, int len, apr_pool_t *cont);
  412. /**
  413. * Return the data associated with the current socket
  414. * @param data The user data associated with the socket.
  415. * @param key The key to associate with the user data.
  416. * @param sock The currently open socket.
  417. */
  418. APR_DECLARE(apr_status_t) apr_socket_data_get(void **data, const char *key,
  419. apr_socket_t *sock);
  420. /**
  421. * Set the data associated with the current socket.
  422. * @param sock The currently open socket.
  423. * @param data The user data to associate with the socket.
  424. * @param key The key to associate with the data.
  425. * @param cleanup The cleanup to call when the socket is destroyed.
  426. */
  427. APR_DECLARE(apr_status_t) apr_socket_data_set(apr_socket_t *sock, void *data,
  428. const char *key,
  429. apr_status_t (*cleanup)(void*));
  430. /**
  431. * Send data over a network.
  432. * @param sock The socket to send the data over.
  433. * @param buf The buffer which contains the data to be sent.
  434. * @param len On entry, the number of bytes to send; on exit, the number
  435. * of bytes sent.
  436. * @remark
  437. * <PRE>
  438. * This functions acts like a blocking write by default. To change
  439. * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK
  440. * socket option.
  441. *
  442. * It is possible for both bytes to be sent and an error to be returned.
  443. *
  444. * APR_EINTR is never returned.
  445. * </PRE>
  446. */
  447. APR_DECLARE(apr_status_t) apr_socket_send(apr_socket_t *sock, const char *buf,
  448. apr_size_t *len);
  449. /**
  450. * Send multiple packets of data over a network.
  451. * @param sock The socket to send the data over.
  452. * @param vec The array of iovec structs containing the data to send
  453. * @param nvec The number of iovec structs in the array
  454. * @param len Receives the number of bytes actually written
  455. * @remark
  456. * <PRE>
  457. * This functions acts like a blocking write by default. To change
  458. * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK
  459. * socket option.
  460. * The number of bytes actually sent is stored in argument 3.
  461. *
  462. * It is possible for both bytes to be sent and an error to be returned.
  463. *
  464. * APR_EINTR is never returned.
  465. * </PRE>
  466. */
  467. APR_DECLARE(apr_status_t) apr_socket_sendv(apr_socket_t *sock,
  468. const struct iovec *vec,
  469. apr_int32_t nvec, apr_size_t *len);
  470. /**
  471. * @param sock The socket to send from
  472. * @param where The apr_sockaddr_t describing where to send the data
  473. * @param flags The flags to use
  474. * @param buf The data to send
  475. * @param len The length of the data to send
  476. */
  477. APR_DECLARE(apr_status_t) apr_socket_sendto(apr_socket_t *sock,
  478. apr_sockaddr_t *where,
  479. apr_int32_t flags, const char *buf,
  480. apr_size_t *len);
  481. /**
  482. * Read data from a socket. On success, the address of the peer from
  483. * which the data was sent is copied into the @a from parameter, and the
  484. * @a len parameter is updated to give the number of bytes written to
  485. * @a buf.
  486. *
  487. * @param from Updated with the address from which the data was received
  488. * @param sock The socket to use
  489. * @param flags The flags to use
  490. * @param buf The buffer to use
  491. * @param len The length of the available buffer
  492. */
  493. APR_DECLARE(apr_status_t) apr_socket_recvfrom(apr_sockaddr_t *from,
  494. apr_socket_t *sock,
  495. apr_int32_t flags, char *buf,
  496. apr_size_t *len);
  497. #if APR_HAS_SENDFILE || defined(DOXYGEN)
  498. /**
  499. * Send a file from an open file descriptor to a socket, along with
  500. * optional headers and trailers
  501. * @param sock The socket to which we're writing
  502. * @param file The open file from which to read
  503. * @param hdtr A structure containing the headers and trailers to send
  504. * @param offset Offset into the file where we should begin writing
  505. * @param len (input) - Number of bytes to send from the file
  506. * (output) - Number of bytes actually sent,
  507. * including headers, file, and trailers
  508. * @param flags APR flags that are mapped to OS specific flags
  509. * @remark This functions acts like a blocking write by default. To change
  510. * this behavior, use apr_socket_timeout_set() or the
  511. * APR_SO_NONBLOCK socket option.
  512. * The number of bytes actually sent is stored in the len parameter.
  513. * The offset parameter is passed by reference for no reason; its
  514. * value will never be modified by the apr_socket_sendfile() function.
  515. */
  516. APR_DECLARE(apr_status_t) apr_socket_sendfile(apr_socket_t *sock,
  517. apr_file_t *file,
  518. apr_hdtr_t *hdtr,
  519. apr_off_t *offset,
  520. apr_size_t *len,
  521. apr_int32_t flags);
  522. #endif /* APR_HAS_SENDFILE */
  523. /**
  524. * Read data from a network.
  525. * @param sock The socket to read the data from.
  526. * @param buf The buffer to store the data in.
  527. * @param len On entry, the number of bytes to receive; on exit, the number
  528. * of bytes received.
  529. * @remark
  530. * <PRE>
  531. * This functions acts like a blocking read by default. To change
  532. * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK
  533. * socket option.
  534. * The number of bytes actually received is stored in argument 3.
  535. *
  536. * It is possible for both bytes to be received and an APR_EOF or
  537. * other error to be returned.
  538. *
  539. * APR_EINTR is never returned.
  540. * </PRE>
  541. */
  542. APR_DECLARE(apr_status_t) apr_socket_recv(apr_socket_t *sock,
  543. char *buf, apr_size_t *len);
  544. /**
  545. * Setup socket options for the specified socket
  546. * @param sock The socket to set up.
  547. * @param opt The option we would like to configure. One of:
  548. * <PRE>
  549. * APR_SO_DEBUG -- turn on debugging information
  550. * APR_SO_KEEPALIVE -- keep connections active
  551. * APR_SO_LINGER -- lingers on close if data is present
  552. * APR_SO_NONBLOCK -- Turns blocking on/off for socket
  553. * When this option is enabled, use
  554. * the APR_STATUS_IS_EAGAIN() macro to
  555. * see if a send or receive function
  556. * could not transfer data without
  557. * blocking.
  558. * APR_SO_REUSEADDR -- The rules used in validating addresses
  559. * supplied to bind should allow reuse
  560. * of local addresses.
  561. * APR_SO_SNDBUF -- Set the SendBufferSize
  562. * APR_SO_RCVBUF -- Set the ReceiveBufferSize
  563. * </PRE>
  564. * @param on Value for the option.
  565. */
  566. APR_DECLARE(apr_status_t) apr_socket_opt_set(apr_socket_t *sock,
  567. apr_int32_t opt, apr_int32_t on);
  568. /**
  569. * Setup socket timeout for the specified socket
  570. * @param sock The socket to set up.
  571. * @param t Value for the timeout.
  572. * <PRE>
  573. * t > 0 -- read and write calls return APR_TIMEUP if specified time
  574. * elapsess with no data read or written
  575. * t == 0 -- read and write calls never block
  576. * t < 0 -- read and write calls block
  577. * </PRE>
  578. */
  579. APR_DECLARE(apr_status_t) apr_socket_timeout_set(apr_socket_t *sock,
  580. apr_interval_time_t t);
  581. /**
  582. * Query socket options for the specified socket
  583. * @param sock The socket to query
  584. * @param opt The option we would like to query. One of:
  585. * <PRE>
  586. * APR_SO_DEBUG -- turn on debugging information
  587. * APR_SO_KEEPALIVE -- keep connections active
  588. * APR_SO_LINGER -- lingers on close if data is present
  589. * APR_SO_NONBLOCK -- Turns blocking on/off for socket
  590. * APR_SO_REUSEADDR -- The rules used in validating addresses
  591. * supplied to bind should allow reuse
  592. * of local addresses.
  593. * APR_SO_SNDBUF -- Set the SendBufferSize
  594. * APR_SO_RCVBUF -- Set the ReceiveBufferSize
  595. * APR_SO_DISCONNECTED -- Query the disconnected state of the socket.
  596. * (Currently only used on Windows)
  597. * </PRE>
  598. * @param on Socket option returned on the call.
  599. */
  600. APR_DECLARE(apr_status_t) apr_socket_opt_get(apr_socket_t *sock,
  601. apr_int32_t opt, apr_int32_t *on);
  602. /**
  603. * Query socket timeout for the specified socket
  604. * @param sock The socket to query
  605. * @param t Socket timeout returned from the query.
  606. */
  607. APR_DECLARE(apr_status_t) apr_socket_timeout_get(apr_socket_t *sock,
  608. apr_interval_time_t *t);
  609. /**
  610. * Query the specified socket if at the OOB/Urgent data mark
  611. * @param sock The socket to query
  612. * @param atmark Is set to true if socket is at the OOB/urgent mark,
  613. * otherwise is set to false.
  614. */
  615. APR_DECLARE(apr_status_t) apr_socket_atmark(apr_socket_t *sock,
  616. int *atmark);
  617. /**
  618. * Return an address associated with a socket; either the address to
  619. * which the socket is bound locally or the the address of the peer
  620. * to which the socket is connected.
  621. * @param sa The returned apr_sockaddr_t.
  622. * @param which Whether to retrieve the local or remote address
  623. * @param sock The socket to use
  624. */
  625. APR_DECLARE(apr_status_t) apr_socket_addr_get(apr_sockaddr_t **sa,
  626. apr_interface_e which,
  627. apr_socket_t *sock);
  628. /**
  629. * Return the IP address (in numeric address string format) in
  630. * an APR socket address. APR will allocate storage for the IP address
  631. * string from the pool of the apr_sockaddr_t.
  632. * @param addr The IP address.
  633. * @param sockaddr The socket address to reference.
  634. */
  635. APR_DECLARE(apr_status_t) apr_sockaddr_ip_get(char **addr,
  636. apr_sockaddr_t *sockaddr);
  637. /**
  638. * Write the IP address (in numeric address string format) of the APR
  639. * socket address @a sockaddr into the buffer @a buf (of size @a buflen).
  640. * @param sockaddr The socket address to reference.
  641. */
  642. APR_DECLARE(apr_status_t) apr_sockaddr_ip_getbuf(char *buf, apr_size_t buflen,
  643. apr_sockaddr_t *sockaddr);
  644. /**
  645. * See if the IP addresses in two APR socket addresses are
  646. * equivalent. Appropriate logic is present for comparing
  647. * IPv4-mapped IPv6 addresses with IPv4 addresses.
  648. *
  649. * @param addr1 One of the APR socket addresses.
  650. * @param addr2 The other APR socket address.
  651. * @remark The return value will be non-zero if the addresses
  652. * are equivalent.
  653. */
  654. APR_DECLARE(int) apr_sockaddr_equal(const apr_sockaddr_t *addr1,
  655. const apr_sockaddr_t *addr2);
  656. /**
  657. * Return the type of the socket.
  658. * @param sock The socket to query.
  659. * @param type The returned type (e.g., SOCK_STREAM).
  660. */
  661. APR_DECLARE(apr_status_t) apr_socket_type_get(apr_socket_t *sock,
  662. int *type);
  663. /**
  664. * Given an apr_sockaddr_t and a service name, set the port for the service
  665. * @param sockaddr The apr_sockaddr_t that will have its port set
  666. * @param servname The name of the service you wish to use
  667. */
  668. APR_DECLARE(apr_status_t) apr_getservbyname(apr_sockaddr_t *sockaddr,
  669. const char *servname);
  670. /**
  671. * Build an ip-subnet representation from an IP address and optional netmask or
  672. * number-of-bits.
  673. * @param ipsub The new ip-subnet representation
  674. * @param ipstr The input IP address string
  675. * @param mask_or_numbits The input netmask or number-of-bits string, or NULL
  676. * @param p The pool to allocate from
  677. */
  678. APR_DECLARE(apr_status_t) apr_ipsubnet_create(apr_ipsubnet_t **ipsub,
  679. const char *ipstr,
  680. const char *mask_or_numbits,
  681. apr_pool_t *p);
  682. /**
  683. * Test the IP address in an apr_sockaddr_t against a pre-built ip-subnet
  684. * representation.
  685. * @param ipsub The ip-subnet representation
  686. * @param sa The socket address to test
  687. * @return non-zero if the socket address is within the subnet, 0 otherwise
  688. */
  689. APR_DECLARE(int) apr_ipsubnet_test(apr_ipsubnet_t *ipsub, apr_sockaddr_t *sa);
  690. #if APR_HAS_SO_ACCEPTFILTER || defined(DOXYGEN)
  691. /**
  692. * Set an OS level accept filter.
  693. * @param sock The socket to put the accept filter on.
  694. * @param name The accept filter
  695. * @param args Any extra args to the accept filter. Passing NULL here removes
  696. * the accept filter.
  697. */
  698. apr_status_t apr_socket_accept_filter(apr_socket_t *sock, char *name,
  699. char *args);
  700. #endif
  701. /**
  702. * Return the protocol of the socket.
  703. * @param sock The socket to query.
  704. * @param protocol The returned protocol (e.g., APR_PROTO_TCP).
  705. */
  706. APR_DECLARE(apr_status_t) apr_socket_protocol_get(apr_socket_t *sock,
  707. int *protocol);
  708. /**
  709. * Get the pool used by the socket.
  710. */
  711. APR_POOL_DECLARE_ACCESSOR(socket);
  712. /**
  713. * Set a socket to be inherited by child processes.
  714. */
  715. APR_DECLARE_INHERIT_SET(socket);
  716. /**
  717. * Unset a socket from being inherited by child processes.
  718. */
  719. APR_DECLARE_INHERIT_UNSET(socket);
  720. /**
  721. * @defgroup apr_mcast IP Multicast
  722. * @{
  723. */
  724. /**
  725. * Join a Multicast Group
  726. * @param sock The socket to join a multicast group
  727. * @param join The address of the multicast group to join
  728. * @param iface Address of the interface to use. If NULL is passed, the
  729. * default multicast interface will be used. (OS Dependent)
  730. * @param source Source Address to accept transmissions from (non-NULL
  731. * implies Source-Specific Multicast)
  732. */
  733. APR_DECLARE(apr_status_t) apr_mcast_join(apr_socket_t *sock,
  734. apr_sockaddr_t *join,
  735. apr_sockaddr_t *iface,
  736. apr_sockaddr_t *source);
  737. /**
  738. * Leave a Multicast Group. All arguments must be the same as
  739. * apr_mcast_join.
  740. * @param sock The socket to leave a multicast group
  741. * @param addr The address of the multicast group to leave
  742. * @param iface Address of the interface to use. If NULL is passed, the
  743. * default multicast interface will be used. (OS Dependent)
  744. * @param source Source Address to accept transmissions from (non-NULL
  745. * implies Source-Specific Multicast)
  746. */
  747. APR_DECLARE(apr_status_t) apr_mcast_leave(apr_socket_t *sock,
  748. apr_sockaddr_t *addr,
  749. apr_sockaddr_t *iface,
  750. apr_sockaddr_t *source);
  751. /**
  752. * Set the Multicast Time to Live (ttl) for a multicast transmission.
  753. * @param sock The socket to set the multicast ttl
  754. * @param ttl Time to live to Assign. 0-255, default=1
  755. * @remark If the TTL is 0, packets will only be seen by sockets on
  756. * the local machine, and only when multicast loopback is enabled.
  757. */
  758. APR_DECLARE(apr_status_t) apr_mcast_hops(apr_socket_t *sock,
  759. apr_byte_t ttl);
  760. /**
  761. * Toggle IP Multicast Loopback
  762. * @param sock The socket to set multicast loopback
  763. * @param opt 0=disable, 1=enable
  764. */
  765. APR_DECLARE(apr_status_t) apr_mcast_loopback(apr_socket_t *sock,
  766. apr_byte_t opt);
  767. /**
  768. * Set the Interface to be used for outgoing Multicast Transmissions.
  769. * @param sock The socket to set the multicast interface on
  770. * @param iface Address of the interface to use for Multicast
  771. */
  772. APR_DECLARE(apr_status_t) apr_mcast_interface(apr_socket_t *sock,
  773. apr_sockaddr_t *iface);
  774. /** @} */
  775. /** @} */
  776. #ifdef __cplusplus
  777. }
  778. #endif
  779. #endif /* ! APR_NETWORK_IO_H */