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