apr_network_io.h

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

Generated on Mon Nov 26 11:23:52 2007 for Apache Portable Runtime by  doxygen 1.5.2