00001 /* Licensed to the Apache Software Foundation (ASF) under one or more 00002 * contributor license agreements. See the NOTICE file distributed with 00003 * this work for additional information regarding copyright ownership. 00004 * The ASF licenses this file to You under the Apache License, Version 2.0 00005 * (the "License"); you may not use this file except in compliance with 00006 * the License. You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef APR_NETWORK_IO_H 00018 #define APR_NETWORK_IO_H 00019 /** 00020 * @file apr_network_io.h 00021 * @brief APR Network library 00022 */ 00023 00024 #include "apr.h" 00025 #include "apr_pools.h" 00026 #include "apr_file_io.h" 00027 #include "apr_errno.h" 00028 #include "apr_inherit.h" 00029 #include "apr_perms_set.h" 00030 00031 #if APR_HAVE_NETINET_IN_H 00032 #include <netinet/in.h> 00033 #endif 00034 #if APR_HAVE_SYS_UN_H 00035 #include <sys/un.h> 00036 #endif 00037 00038 #ifdef __cplusplus 00039 extern "C" { 00040 #endif /* __cplusplus */ 00041 00042 /** 00043 * @defgroup apr_network_io Network Routines 00044 * @ingroup APR 00045 * @{ 00046 */ 00047 00048 #ifndef APR_MAX_SECS_TO_LINGER 00049 /** Maximum seconds to linger */ 00050 #define APR_MAX_SECS_TO_LINGER 30 00051 #endif 00052 00053 #ifndef APRMAXHOSTLEN 00054 /** Maximum hostname length */ 00055 #define APRMAXHOSTLEN 256 00056 #endif 00057 00058 #ifndef APR_ANYADDR 00059 /** Default 'any' address */ 00060 #define APR_ANYADDR "0.0.0.0" 00061 #endif 00062 00063 /** 00064 * @defgroup apr_sockopt Socket option definitions 00065 * @{ 00066 */ 00067 #define APR_SO_LINGER 1 /**< Linger */ 00068 #define APR_SO_KEEPALIVE 2 /**< Keepalive */ 00069 #define APR_SO_DEBUG 4 /**< Debug */ 00070 #define APR_SO_NONBLOCK 8 /**< Non-blocking IO */ 00071 #define APR_SO_REUSEADDR 16 /**< Reuse addresses */ 00072 #define APR_SO_SNDBUF 64 /**< Send buffer */ 00073 #define APR_SO_RCVBUF 128 /**< Receive buffer */ 00074 #define APR_SO_DISCONNECTED 256 /**< Disconnected */ 00075 #define APR_TCP_NODELAY 512 /**< For SCTP sockets, this is mapped 00076 * to STCP_NODELAY internally. 00077 */ 00078 #define APR_TCP_NOPUSH 1024 /**< No push */ 00079 #define APR_RESET_NODELAY 2048 /**< This flag is ONLY set internally 00080 * when we set APR_TCP_NOPUSH with 00081 * APR_TCP_NODELAY set to tell us that 00082 * APR_TCP_NODELAY should be turned on 00083 * again when NOPUSH is turned off 00084 */ 00085 #define APR_INCOMPLETE_READ 4096 /**< Set on non-blocking sockets 00086 * (timeout != 0) on which the 00087 * previous read() did not fill a buffer 00088 * completely. the next apr_socket_recv() 00089 * will first call select()/poll() rather than 00090 * going straight into read(). (Can also 00091 * be set by an application to force a 00092 * select()/poll() call before the next 00093 * read, in cases where the app expects 00094 * that an immediate read would fail.) 00095 */ 00096 #define APR_INCOMPLETE_WRITE 8192 /**< like APR_INCOMPLETE_READ, but for write 00097 * @see APR_INCOMPLETE_READ 00098 */ 00099 #define APR_IPV6_V6ONLY 16384 /**< Don't accept IPv4 connections on an 00100 * IPv6 listening socket. 00101 */ 00102 #define APR_TCP_DEFER_ACCEPT 32768 /**< Delay accepting of new connections 00103 * until data is available. 00104 * @see apr_socket_accept_filter 00105 */ 00106 00107 /** @} */ 00108 00109 /** Define what type of socket shutdown should occur. */ 00110 typedef enum { 00111 APR_SHUTDOWN_READ, /**< no longer allow read request */ 00112 APR_SHUTDOWN_WRITE, /**< no longer allow write requests */ 00113 APR_SHUTDOWN_READWRITE /**< no longer allow read or write requests */ 00114 } apr_shutdown_how_e; 00115 00116 #define APR_IPV4_ADDR_OK 0x01 /**< @see apr_sockaddr_info_get() */ 00117 #define APR_IPV6_ADDR_OK 0x02 /**< @see apr_sockaddr_info_get() */ 00118 00119 #if (!APR_HAVE_IN_ADDR) 00120 /** 00121 * We need to make sure we always have an in_addr type, so APR will just 00122 * define it ourselves, if the platform doesn't provide it. 00123 */ 00124 struct in_addr { 00125 apr_uint32_t s_addr; /**< storage to hold the IP# */ 00126 }; 00127 #endif 00128 00129 /** @def APR_INADDR_NONE 00130 * Not all platforms have a real INADDR_NONE. This macro replaces 00131 * INADDR_NONE on all platforms. 00132 */ 00133 #ifdef INADDR_NONE 00134 #define APR_INADDR_NONE INADDR_NONE 00135 #else 00136 #define APR_INADDR_NONE ((unsigned int) 0xffffffff) 00137 #endif 00138 00139 /** 00140 * @def APR_INET 00141 * Not all platforms have these defined, so we'll define them here 00142 * The default values come from FreeBSD 4.1.1 00143 */ 00144 #define APR_INET AF_INET 00145 /** @def APR_UNSPEC 00146 * Let the system decide which address family to use 00147 */ 00148 #ifdef AF_UNSPEC 00149 #define APR_UNSPEC AF_UNSPEC 00150 #else 00151 #define APR_UNSPEC 0 00152 #endif 00153 #if APR_HAVE_IPV6 00154 /** @def APR_INET6 00155 * IPv6 Address Family. Not all platforms may have this defined. 00156 */ 00157 00158 #define APR_INET6 AF_INET6 00159 #endif 00160 00161 #if APR_HAVE_SOCKADDR_UN 00162 #if defined (AF_UNIX) 00163 #define APR_UNIX AF_UNIX 00164 #elif defined(AF_LOCAL) 00165 #define APR_UNIX AF_LOCAL 00166 #else 00167 #error "Neither AF_UNIX nor AF_LOCAL is defined" 00168 #endif 00169 #else /* !APR_HAVE_SOCKADDR_UN */ 00170 #if defined (AF_UNIX) 00171 #define APR_UNIX AF_UNIX 00172 #elif defined(AF_LOCAL) 00173 #define APR_UNIX AF_LOCAL 00174 #else 00175 /* TODO: Use a smarter way to detect unique APR_UNIX value */ 00176 #define APR_UNIX 1234 00177 #endif 00178 #endif 00179 00180 /** 00181 * @defgroup IP_Proto IP Protocol Definitions for use when creating sockets 00182 * @{ 00183 */ 00184 #define APR_PROTO_TCP 6 /**< TCP */ 00185 #define APR_PROTO_UDP 17 /**< UDP */ 00186 #define APR_PROTO_SCTP 132 /**< SCTP */ 00187 /** @} */ 00188 00189 /** 00190 * Enum used to denote either the local and remote endpoint of a 00191 * connection. 00192 */ 00193 typedef enum { 00194 APR_LOCAL, /**< Socket information for local end of connection */ 00195 APR_REMOTE /**< Socket information for remote end of connection */ 00196 } apr_interface_e; 00197 00198 /** 00199 * The specific declaration of inet_addr's ... some platforms fall back 00200 * inet_network (this is not good, but necessary) 00201 */ 00202 00203 #if APR_HAVE_INET_ADDR 00204 #define apr_inet_addr inet_addr 00205 #elif APR_HAVE_INET_NETWORK /* only DGUX, as far as I know */ 00206 /** 00207 * @warning 00208 * not generally safe... inet_network() and inet_addr() perform 00209 * different functions */ 00210 #define apr_inet_addr inet_network 00211 #endif 00212 00213 /** A structure to represent sockets */ 00214 typedef struct apr_socket_t apr_socket_t; 00215 /** 00216 * A structure to encapsulate headers and trailers for apr_socket_sendfile 00217 */ 00218 typedef struct apr_hdtr_t apr_hdtr_t; 00219 /** A structure to represent in_addr */ 00220 typedef struct in_addr apr_in_addr_t; 00221 /** A structure to represent an IP subnet */ 00222 typedef struct apr_ipsubnet_t apr_ipsubnet_t; 00223 00224 /** @remark use apr_uint16_t just in case some system has a short that isn't 16 bits... */ 00225 typedef apr_uint16_t apr_port_t; 00226 00227 /** @remark It's defined here as I think it should all be platform safe... 00228 * @see apr_sockaddr_t 00229 */ 00230 typedef struct apr_sockaddr_t apr_sockaddr_t; 00231 /** 00232 * APRs socket address type, used to ensure protocol independence 00233 */ 00234 struct apr_sockaddr_t { 00235 /** The pool to use... */ 00236 apr_pool_t *pool; 00237 /** The hostname */ 00238 char *hostname; 00239 /** Either a string of the port number or the service name for the port */ 00240 char *servname; 00241 /** The numeric port */ 00242 apr_port_t port; 00243 /** The family */ 00244 apr_int32_t family; 00245 /** How big is the sockaddr we're using? */ 00246 apr_socklen_t salen; 00247 /** How big is the ip address structure we're using? */ 00248 int ipaddr_len; 00249 /** How big should the address buffer be? 16 for v4 or 46 for v6 00250 * used in inet_ntop... */ 00251 int addr_str_len; 00252 /** This points to the IP address structure within the appropriate 00253 * sockaddr structure. */ 00254 void *ipaddr_ptr; 00255 /** If multiple addresses were found by apr_sockaddr_info_get(), this 00256 * points to a representation of the next address. */ 00257 apr_sockaddr_t *next; 00258 /** Union of either IPv4 or IPv6 sockaddr. */ 00259 union { 00260 /** IPv4 sockaddr structure */ 00261 struct sockaddr_in sin; 00262 #if APR_HAVE_IPV6 00263 /** IPv6 sockaddr structure */ 00264 struct sockaddr_in6 sin6; 00265 #endif 00266 #if APR_HAVE_SA_STORAGE 00267 /** Placeholder to ensure that the size of this union is not 00268 * dependent on whether APR_HAVE_IPV6 is defined. */ 00269 struct sockaddr_storage sas; 00270 #endif 00271 #if APR_HAVE_SOCKADDR_UN 00272 /** Unix domain socket sockaddr structure */ 00273 struct sockaddr_un unx; 00274 #endif 00275 } sa; 00276 }; 00277 00278 #if APR_HAS_SENDFILE 00279 /** 00280 * Support reusing the socket on platforms which support it (from disconnect, 00281 * specifically Win32. 00282 * @remark Optional flag passed into apr_socket_sendfile() 00283 */ 00284 #define APR_SENDFILE_DISCONNECT_SOCKET 1 00285 #endif 00286 00287 /** A structure to encapsulate headers and trailers for apr_socket_sendfile */ 00288 struct apr_hdtr_t { 00289 /** An iovec to store the headers sent before the file. */ 00290 struct iovec* headers; 00291 /** number of headers in the iovec */ 00292 int numheaders; 00293 /** An iovec to store the trailers sent after the file. */ 00294 struct iovec* trailers; 00295 /** number of trailers in the iovec */ 00296 int numtrailers; 00297 }; 00298 00299 /* function definitions */ 00300 00301 /** 00302 * Create a socket. 00303 * @param new_sock The new socket that has been set up. 00304 * @param family The address family of the socket (e.g., APR_INET). 00305 * @param type The type of the socket (e.g., SOCK_STREAM). 00306 * @param protocol The protocol of the socket (e.g., APR_PROTO_TCP). 00307 * @param cont The pool for the apr_socket_t and associated storage. 00308 */ 00309 APR_DECLARE(apr_status_t) apr_socket_create(apr_socket_t **new_sock, 00310 int family, int type, 00311 int protocol, 00312 apr_pool_t *cont); 00313 00314 /** 00315 * Shutdown either reading, writing, or both sides of a socket. 00316 * @param thesocket The socket to close 00317 * @param how How to shutdown the socket. One of: 00318 * <PRE> 00319 * APR_SHUTDOWN_READ no longer allow read requests 00320 * APR_SHUTDOWN_WRITE no longer allow write requests 00321 * APR_SHUTDOWN_READWRITE no longer allow read or write requests 00322 * </PRE> 00323 * @see apr_shutdown_how_e 00324 * @remark This does not actually close the socket descriptor, it just 00325 * controls which calls are still valid on the socket. 00326 */ 00327 APR_DECLARE(apr_status_t) apr_socket_shutdown(apr_socket_t *thesocket, 00328 apr_shutdown_how_e how); 00329 00330 /** 00331 * Close a socket. 00332 * @param thesocket The socket to close 00333 */ 00334 APR_DECLARE(apr_status_t) apr_socket_close(apr_socket_t *thesocket); 00335 00336 /** 00337 * Bind the socket to its associated port 00338 * @param sock The socket to bind 00339 * @param sa The socket address to bind to 00340 * @remark This may be where we will find out if there is any other process 00341 * using the selected port. 00342 */ 00343 APR_DECLARE(apr_status_t) apr_socket_bind(apr_socket_t *sock, 00344 apr_sockaddr_t *sa); 00345 00346 /** 00347 * Listen to a bound socket for connections. 00348 * @param sock The socket to listen on 00349 * @param backlog The number of outstanding connections allowed in the sockets 00350 * listen queue. If this value is less than zero, the listen 00351 * queue size is set to zero. 00352 */ 00353 APR_DECLARE(apr_status_t) apr_socket_listen(apr_socket_t *sock, 00354 apr_int32_t backlog); 00355 00356 /** 00357 * Accept a new connection request 00358 * @param new_sock A copy of the socket that is connected to the socket that 00359 * made the connection request. This is the socket which should 00360 * be used for all future communication. 00361 * @param sock The socket we are listening on. 00362 * @param connection_pool The pool for the new socket. 00363 */ 00364 APR_DECLARE(apr_status_t) apr_socket_accept(apr_socket_t **new_sock, 00365 apr_socket_t *sock, 00366 apr_pool_t *connection_pool); 00367 00368 /** 00369 * Issue a connection request to a socket either on the same machine 00370 * or a different one. 00371 * @param sock The socket we wish to use for our side of the connection 00372 * @param sa The address of the machine we wish to connect to. 00373 */ 00374 APR_DECLARE(apr_status_t) apr_socket_connect(apr_socket_t *sock, 00375 apr_sockaddr_t *sa); 00376 00377 /** 00378 * Create apr_sockaddr_t from hostname, address family, and port. 00379 * @param sa The new apr_sockaddr_t. 00380 * @param hostname The hostname or numeric address string to resolve/parse, or 00381 * NULL to build an address that corresponds to 0.0.0.0 or :: 00382 * or in case of APR_UNIX family it is absolute socket filename. 00383 * @param family The address family to use, or APR_UNSPEC if the system should 00384 * decide. 00385 * @param port The port number. 00386 * @param flags Special processing flags: 00387 * <PRE> 00388 * APR_IPV4_ADDR_OK first query for IPv4 addresses; only look 00389 * for IPv6 addresses if the first query failed; 00390 * only valid if family is APR_UNSPEC and hostname 00391 * isn't NULL; mutually exclusive with 00392 * APR_IPV6_ADDR_OK 00393 * APR_IPV6_ADDR_OK first query for IPv6 addresses; only look 00394 * for IPv4 addresses if the first query failed; 00395 * only valid if family is APR_UNSPEC and hostname 00396 * isn't NULL and APR_HAVE_IPV6; mutually exclusive 00397 * with APR_IPV4_ADDR_OK 00398 * </PRE> 00399 * @param p The pool for the apr_sockaddr_t and associated storage. 00400 */ 00401 APR_DECLARE(apr_status_t) apr_sockaddr_info_get(apr_sockaddr_t **sa, 00402 const char *hostname, 00403 apr_int32_t family, 00404 apr_port_t port, 00405 apr_int32_t flags, 00406 apr_pool_t *p); 00407 00408 00409 /** 00410 * Look up the host name from an apr_sockaddr_t. 00411 * @param hostname The hostname. 00412 * @param sa The apr_sockaddr_t. 00413 * @param flags Special processing flags. 00414 */ 00415 APR_DECLARE(apr_status_t) apr_getnameinfo(char **hostname, 00416 apr_sockaddr_t *sa, 00417 apr_int32_t flags); 00418 00419 /** 00420 * Parse hostname/IP address with scope id and port. 00421 * 00422 * Any of the following strings are accepted: 00423 * 8080 (just the port number) 00424 * www.apache.org (just the hostname) 00425 * www.apache.org:8080 (hostname and port number) 00426 * [fe80::1]:80 (IPv6 numeric address string only) 00427 * [fe80::1%eth0] (IPv6 numeric address string and scope id) 00428 * 00429 * Invalid strings: 00430 * (empty string) 00431 * [abc] (not valid IPv6 numeric address string) 00432 * abc:65536 (invalid port number) 00433 * 00434 * @param addr The new buffer containing just the hostname. On output, *addr 00435 * will be NULL if no hostname/IP address was specfied. 00436 * @param scope_id The new buffer containing just the scope id. On output, 00437 * *scope_id will be NULL if no scope id was specified. 00438 * @param port The port number. On output, *port will be 0 if no port was 00439 * specified. 00440 * ### FIXME: 0 is a legal port (per RFC 1700). this should 00441 * ### return something besides zero if the port is missing. 00442 * @param str The input string to be parsed. 00443 * @param p The pool from which *addr and *scope_id are allocated. 00444 * @remark If scope id shouldn't be allowed, check for scope_id != NULL in 00445 * addition to checking the return code. If addr/hostname should be 00446 * required, check for addr == NULL in addition to checking the 00447 * return code. 00448 */ 00449 APR_DECLARE(apr_status_t) apr_parse_addr_port(char **addr, 00450 char **scope_id, 00451 apr_port_t *port, 00452 const char *str, 00453 apr_pool_t *p); 00454 00455 /** 00456 * Get name of the current machine 00457 * @param buf A buffer to store the hostname in. 00458 * @param len The maximum length of the hostname that can be stored in the 00459 * buffer provided. The suggested length is APRMAXHOSTLEN + 1. 00460 * @param cont The pool to use. 00461 * @remark If the buffer was not large enough, an error will be returned. 00462 */ 00463 APR_DECLARE(apr_status_t) apr_gethostname(char *buf, int len, apr_pool_t *cont); 00464 00465 /** 00466 * Return the data associated with the current socket 00467 * @param data The user data associated with the socket. 00468 * @param key The key to associate with the user data. 00469 * @param sock The currently open socket. 00470 */ 00471 APR_DECLARE(apr_status_t) apr_socket_data_get(void **data, const char *key, 00472 apr_socket_t *sock); 00473 00474 /** 00475 * Set the data associated with the current socket. 00476 * @param sock The currently open socket. 00477 * @param data The user data to associate with the socket. 00478 * @param key The key to associate with the data. 00479 * @param cleanup The cleanup to call when the socket is destroyed. 00480 */ 00481 APR_DECLARE(apr_status_t) apr_socket_data_set(apr_socket_t *sock, void *data, 00482 const char *key, 00483 apr_status_t (*cleanup)(void*)); 00484 00485 /** 00486 * Send data over a network. 00487 * @param sock The socket to send the data over. 00488 * @param buf The buffer which contains the data to be sent. 00489 * @param len On entry, the number of bytes to send; on exit, the number 00490 * of bytes sent. 00491 * @remark 00492 * <PRE> 00493 * This functions acts like a blocking write by default. To change 00494 * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK 00495 * socket option. 00496 * 00497 * It is possible for both bytes to be sent and an error to be returned. 00498 * 00499 * APR_EINTR is never returned. 00500 * </PRE> 00501 */ 00502 APR_DECLARE(apr_status_t) apr_socket_send(apr_socket_t *sock, const char *buf, 00503 apr_size_t *len); 00504 00505 /** 00506 * Send multiple packets of data over a network. 00507 * @param sock The socket to send the data over. 00508 * @param vec The array of iovec structs containing the data to send 00509 * @param nvec The number of iovec structs in the array 00510 * @param len Receives the number of bytes actually written 00511 * @remark 00512 * <PRE> 00513 * This functions acts like a blocking write by default. To change 00514 * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK 00515 * socket option. 00516 * The number of bytes actually sent is stored in argument 3. 00517 * 00518 * It is possible for both bytes to be sent and an error to be returned. 00519 * 00520 * APR_EINTR is never returned. 00521 * </PRE> 00522 */ 00523 APR_DECLARE(apr_status_t) apr_socket_sendv(apr_socket_t *sock, 00524 const struct iovec *vec, 00525 apr_int32_t nvec, apr_size_t *len); 00526 00527 /** 00528 * @param sock The socket to send from 00529 * @param where The apr_sockaddr_t describing where to send the data 00530 * @param flags The flags to use 00531 * @param buf The data to send 00532 * @param len The length of the data to send 00533 */ 00534 APR_DECLARE(apr_status_t) apr_socket_sendto(apr_socket_t *sock, 00535 apr_sockaddr_t *where, 00536 apr_int32_t flags, const char *buf, 00537 apr_size_t *len); 00538 00539 /** 00540 * Read data from a socket. On success, the address of the peer from 00541 * which the data was sent is copied into the @param from parameter, 00542 * and the @param len parameter is updated to give the number of bytes 00543 * written to @param buf. 00544 * @param from Updated with the address from which the data was received 00545 * @param sock The socket to use 00546 * @param flags The flags to use 00547 * @param buf The buffer to use 00548 * @param len The length of the available buffer 00549 */ 00550 00551 APR_DECLARE(apr_status_t) apr_socket_recvfrom(apr_sockaddr_t *from, 00552 apr_socket_t *sock, 00553 apr_int32_t flags, char *buf, 00554 apr_size_t *len); 00555 00556 #if APR_HAS_SENDFILE || defined(DOXYGEN) 00557 00558 /** 00559 * Send a file from an open file descriptor to a socket, along with 00560 * optional headers and trailers 00561 * @param sock The socket to which we're writing 00562 * @param file The open file from which to read 00563 * @param hdtr A structure containing the headers and trailers to send 00564 * @param offset Offset into the file where we should begin writing 00565 * @param len (input) - Number of bytes to send from the file 00566 * (output) - Number of bytes actually sent, 00567 * including headers, file, and trailers 00568 * @param flags APR flags that are mapped to OS specific flags 00569 * @remark This functions acts like a blocking write by default. To change 00570 * this behavior, use apr_socket_timeout_set() or the 00571 * APR_SO_NONBLOCK socket option. 00572 * The number of bytes actually sent is stored in the len parameter. 00573 * The offset parameter is passed by reference for no reason; its 00574 * value will never be modified by the apr_socket_sendfile() function. 00575 */ 00576 APR_DECLARE(apr_status_t) apr_socket_sendfile(apr_socket_t *sock, 00577 apr_file_t *file, 00578 apr_hdtr_t *hdtr, 00579 apr_off_t *offset, 00580 apr_size_t *len, 00581 apr_int32_t flags); 00582 00583 #endif /* APR_HAS_SENDFILE */ 00584 00585 /** 00586 * Read data from a network. 00587 * @param sock The socket to read the data from. 00588 * @param buf The buffer to store the data in. 00589 * @param len On entry, the number of bytes to receive; on exit, the number 00590 * of bytes received. 00591 * @remark 00592 * <PRE> 00593 * This functions acts like a blocking read by default. To change 00594 * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK 00595 * socket option. 00596 * The number of bytes actually received is stored in argument 3. 00597 * 00598 * It is possible for both bytes to be received and an APR_EOF or 00599 * other error to be returned. 00600 * 00601 * APR_EINTR is never returned. 00602 * </PRE> 00603 */ 00604 APR_DECLARE(apr_status_t) apr_socket_recv(apr_socket_t *sock, 00605 char *buf, apr_size_t *len); 00606 00607 /** 00608 * Setup socket options for the specified socket 00609 * @param sock The socket to set up. 00610 * @param opt The option we would like to configure. One of: 00611 * <PRE> 00612 * APR_SO_DEBUG -- turn on debugging information 00613 * APR_SO_KEEPALIVE -- keep connections active 00614 * APR_SO_LINGER -- lingers on close if data is present 00615 * APR_SO_NONBLOCK -- Turns blocking on/off for socket 00616 * When this option is enabled, use 00617 * the APR_STATUS_IS_EAGAIN() macro to 00618 * see if a send or receive function 00619 * could not transfer data without 00620 * blocking. 00621 * APR_SO_REUSEADDR -- The rules used in validating addresses 00622 * supplied to bind should allow reuse 00623 * of local addresses. 00624 * APR_SO_SNDBUF -- Set the SendBufferSize 00625 * APR_SO_RCVBUF -- Set the ReceiveBufferSize 00626 * </PRE> 00627 * @param on Value for the option. 00628 */ 00629 APR_DECLARE(apr_status_t) apr_socket_opt_set(apr_socket_t *sock, 00630 apr_int32_t opt, apr_int32_t on); 00631 00632 /** 00633 * Setup socket timeout for the specified socket 00634 * @param sock The socket to set up. 00635 * @param t Value for the timeout. 00636 * <PRE> 00637 * t > 0 -- read and write calls return APR_TIMEUP if specified time 00638 * elapsess with no data read or written 00639 * t == 0 -- read and write calls never block 00640 * t < 0 -- read and write calls block 00641 * </PRE> 00642 */ 00643 APR_DECLARE(apr_status_t) apr_socket_timeout_set(apr_socket_t *sock, 00644 apr_interval_time_t t); 00645 00646 /** 00647 * Query socket options for the specified socket 00648 * @param sock The socket to query 00649 * @param opt The option we would like to query. One of: 00650 * <PRE> 00651 * APR_SO_DEBUG -- turn on debugging information 00652 * APR_SO_KEEPALIVE -- keep connections active 00653 * APR_SO_LINGER -- lingers on close if data is present 00654 * APR_SO_NONBLOCK -- Turns blocking on/off for socket 00655 * APR_SO_REUSEADDR -- The rules used in validating addresses 00656 * supplied to bind should allow reuse 00657 * of local addresses. 00658 * APR_SO_SNDBUF -- Set the SendBufferSize 00659 * APR_SO_RCVBUF -- Set the ReceiveBufferSize 00660 * APR_SO_DISCONNECTED -- Query the disconnected state of the socket. 00661 * (Currently only used on Windows) 00662 * </PRE> 00663 * @param on Socket option returned on the call. 00664 */ 00665 APR_DECLARE(apr_status_t) apr_socket_opt_get(apr_socket_t *sock, 00666 apr_int32_t opt, apr_int32_t *on); 00667 00668 /** 00669 * Query socket timeout for the specified socket 00670 * @param sock The socket to query 00671 * @param t Socket timeout returned from the query. 00672 */ 00673 APR_DECLARE(apr_status_t) apr_socket_timeout_get(apr_socket_t *sock, 00674 apr_interval_time_t *t); 00675 00676 /** 00677 * Query the specified socket if at the OOB/Urgent data mark 00678 * @param sock The socket to query 00679 * @param atmark Is set to true if socket is at the OOB/urgent mark, 00680 * otherwise is set to false. 00681 */ 00682 APR_DECLARE(apr_status_t) apr_socket_atmark(apr_socket_t *sock, 00683 int *atmark); 00684 00685 /** 00686 * Return an address associated with a socket; either the address to 00687 * which the socket is bound locally or the the address of the peer 00688 * to which the socket is connected. 00689 * @param sa The returned apr_sockaddr_t. 00690 * @param which Whether to retrieve the local or remote address 00691 * @param sock The socket to use 00692 */ 00693 APR_DECLARE(apr_status_t) apr_socket_addr_get(apr_sockaddr_t **sa, 00694 apr_interface_e which, 00695 apr_socket_t *sock); 00696 00697 /** 00698 * Return the IP address (in numeric address string format) in 00699 * an APR socket address. APR will allocate storage for the IP address 00700 * string from the pool of the apr_sockaddr_t. 00701 * @param addr The IP address. 00702 * @param sockaddr The socket address to reference. 00703 */ 00704 APR_DECLARE(apr_status_t) apr_sockaddr_ip_get(char **addr, 00705 apr_sockaddr_t *sockaddr); 00706 00707 /** 00708 * Write the IP address (in numeric address string format) of the APR 00709 * socket address @a sockaddr into the buffer @a buf (of size @a buflen). 00710 * @param sockaddr The socket address to reference. 00711 */ 00712 APR_DECLARE(apr_status_t) apr_sockaddr_ip_getbuf(char *buf, apr_size_t buflen, 00713 apr_sockaddr_t *sockaddr); 00714 00715 /** 00716 * See if the IP addresses in two APR socket addresses are 00717 * equivalent. Appropriate logic is present for comparing 00718 * IPv4-mapped IPv6 addresses with IPv4 addresses. 00719 * 00720 * @param addr1 One of the APR socket addresses. 00721 * @param addr2 The other APR socket address. 00722 * @remark The return value will be non-zero if the addresses 00723 * are equivalent. 00724 */ 00725 APR_DECLARE(int) apr_sockaddr_equal(const apr_sockaddr_t *addr1, 00726 const apr_sockaddr_t *addr2); 00727 00728 /** 00729 * Return the type of the socket. 00730 * @param sock The socket to query. 00731 * @param type The returned type (e.g., SOCK_STREAM). 00732 */ 00733 APR_DECLARE(apr_status_t) apr_socket_type_get(apr_socket_t *sock, 00734 int *type); 00735 00736 /** 00737 * Given an apr_sockaddr_t and a service name, set the port for the service 00738 * @param sockaddr The apr_sockaddr_t that will have its port set 00739 * @param servname The name of the service you wish to use 00740 */ 00741 APR_DECLARE(apr_status_t) apr_getservbyname(apr_sockaddr_t *sockaddr, 00742 const char *servname); 00743 /** 00744 * Build an ip-subnet representation from an IP address and optional netmask or 00745 * number-of-bits. 00746 * @param ipsub The new ip-subnet representation 00747 * @param ipstr The input IP address string 00748 * @param mask_or_numbits The input netmask or number-of-bits string, or NULL 00749 * @param p The pool to allocate from 00750 */ 00751 APR_DECLARE(apr_status_t) apr_ipsubnet_create(apr_ipsubnet_t **ipsub, 00752 const char *ipstr, 00753 const char *mask_or_numbits, 00754 apr_pool_t *p); 00755 00756 /** 00757 * Test the IP address in an apr_sockaddr_t against a pre-built ip-subnet 00758 * representation. 00759 * @param ipsub The ip-subnet representation 00760 * @param sa The socket address to test 00761 * @return non-zero if the socket address is within the subnet, 0 otherwise 00762 */ 00763 APR_DECLARE(int) apr_ipsubnet_test(apr_ipsubnet_t *ipsub, apr_sockaddr_t *sa); 00764 00765 #if APR_HAS_SO_ACCEPTFILTER || defined(DOXYGEN) 00766 /** 00767 * Set an OS level accept filter. 00768 * @param sock The socket to put the accept filter on. 00769 * @param name The accept filter 00770 * @param args Any extra args to the accept filter. Passing NULL here removes 00771 * the accept filter. 00772 */ 00773 apr_status_t apr_socket_accept_filter(apr_socket_t *sock, char *name, 00774 char *args); 00775 #endif 00776 00777 /** 00778 * Return the protocol of the socket. 00779 * @param sock The socket to query. 00780 * @param protocol The returned protocol (e.g., APR_PROTO_TCP). 00781 */ 00782 APR_DECLARE(apr_status_t) apr_socket_protocol_get(apr_socket_t *sock, 00783 int *protocol); 00784 00785 /** 00786 * Get the pool used by the socket. 00787 */ 00788 APR_POOL_DECLARE_ACCESSOR(socket); 00789 00790 /** 00791 * Set a socket to be inherited by child processes. 00792 */ 00793 APR_DECLARE_INHERIT_SET(socket); 00794 00795 /** 00796 * Unset a socket from being inherited by child processes. 00797 */ 00798 APR_DECLARE_INHERIT_UNSET(socket); 00799 00800 /** 00801 * Set socket permissions. 00802 */ 00803 APR_PERMS_SET_IMPLEMENT(socket); 00804 00805 /** 00806 * @defgroup apr_mcast IP Multicast 00807 * @{ 00808 */ 00809 00810 /** 00811 * Join a Multicast Group 00812 * @param sock The socket to join a multicast group 00813 * @param join The address of the multicast group to join 00814 * @param iface Address of the interface to use. If NULL is passed, the 00815 * default multicast interface will be used. (OS Dependent) 00816 * @param source Source Address to accept transmissions from (non-NULL 00817 * implies Source-Specific Multicast) 00818 */ 00819 APR_DECLARE(apr_status_t) apr_mcast_join(apr_socket_t *sock, 00820 apr_sockaddr_t *join, 00821 apr_sockaddr_t *iface, 00822 apr_sockaddr_t *source); 00823 00824 /** 00825 * Leave a Multicast Group. All arguments must be the same as 00826 * apr_mcast_join. 00827 * @param sock The socket to leave a multicast group 00828 * @param addr The address of the multicast group to leave 00829 * @param iface Address of the interface to use. If NULL is passed, the 00830 * default multicast interface will be used. (OS Dependent) 00831 * @param source Source Address to accept transmissions from (non-NULL 00832 * implies Source-Specific Multicast) 00833 */ 00834 APR_DECLARE(apr_status_t) apr_mcast_leave(apr_socket_t *sock, 00835 apr_sockaddr_t *addr, 00836 apr_sockaddr_t *iface, 00837 apr_sockaddr_t *source); 00838 00839 /** 00840 * Set the Multicast Time to Live (ttl) for a multicast transmission. 00841 * @param sock The socket to set the multicast ttl 00842 * @param ttl Time to live to Assign. 0-255, default=1 00843 * @remark If the TTL is 0, packets will only be seen by sockets on 00844 * the local machine, and only when multicast loopback is enabled. 00845 */ 00846 APR_DECLARE(apr_status_t) apr_mcast_hops(apr_socket_t *sock, 00847 apr_byte_t ttl); 00848 00849 /** 00850 * Toggle IP Multicast Loopback 00851 * @param sock The socket to set multicast loopback 00852 * @param opt 0=disable, 1=enable 00853 */ 00854 APR_DECLARE(apr_status_t) apr_mcast_loopback(apr_socket_t *sock, 00855 apr_byte_t opt); 00856 00857 00858 /** 00859 * Set the Interface to be used for outgoing Multicast Transmissions. 00860 * @param sock The socket to set the multicast interface on 00861 * @param iface Address of the interface to use for Multicast 00862 */ 00863 APR_DECLARE(apr_status_t) apr_mcast_interface(apr_socket_t *sock, 00864 apr_sockaddr_t *iface); 00865 00866 /** @} */ 00867 00868 /** @} */ 00869 00870 #ifdef __cplusplus 00871 } 00872 #endif 00873 00874 #endif /* ! APR_NETWORK_IO_H */ 00875
1.5.8