GME  13
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 
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 
00044 #ifndef APR_MAX_SECS_TO_LINGER
00045 
00046 #define APR_MAX_SECS_TO_LINGER 30
00047 #endif
00048 
00049 #ifndef APRMAXHOSTLEN
00050 
00051 #define APRMAXHOSTLEN 256
00052 #endif
00053 
00054 #ifndef APR_ANYADDR
00055 
00056 #define APR_ANYADDR "0.0.0.0"
00057 #endif
00058 
00063 #define APR_SO_LINGER        1    
00064 #define APR_SO_KEEPALIVE     2    
00065 #define APR_SO_DEBUG         4    
00066 #define APR_SO_NONBLOCK      8    
00067 #define APR_SO_REUSEADDR     16   
00068 #define APR_SO_SNDBUF        64   
00069 #define APR_SO_RCVBUF        128  
00070 #define APR_SO_DISCONNECTED  256  
00071 #define APR_TCP_NODELAY      512  
00074 #define APR_TCP_NOPUSH       1024 
00075 #define APR_RESET_NODELAY    2048 
00081 #define APR_INCOMPLETE_READ 4096  
00092 #define APR_INCOMPLETE_WRITE 8192 
00095 #define APR_IPV6_V6ONLY     16384 
00098 #define APR_TCP_DEFER_ACCEPT 32768 
00106 typedef enum {
00107     APR_SHUTDOWN_READ,          
00108     APR_SHUTDOWN_WRITE,         
00109     APR_SHUTDOWN_READWRITE      
00110 } apr_shutdown_how_e;
00111 
00112 #define APR_IPV4_ADDR_OK  0x01  
00113 #define APR_IPV6_ADDR_OK  0x02  
00115 #if (!APR_HAVE_IN_ADDR)
00116 
00120 struct in_addr {
00121     apr_uint32_t  s_addr; 
00122 };
00123 #endif
00124 
00129 #ifdef INADDR_NONE
00130 #define APR_INADDR_NONE INADDR_NONE
00131 #else
00132 #define APR_INADDR_NONE ((unsigned int) 0xffffffff)
00133 #endif
00134 
00140 #define APR_INET     AF_INET
00141 
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 
00154 #define APR_INET6    AF_INET6
00155 #endif
00156 
00161 #define APR_PROTO_TCP       6   
00162 #define APR_PROTO_UDP      17   
00163 #define APR_PROTO_SCTP    132   
00170 typedef enum {
00171     APR_LOCAL,   
00172     APR_REMOTE   
00173 } apr_interface_e;
00174 
00180 #if APR_HAVE_INET_ADDR
00181 #define apr_inet_addr    inet_addr
00182 #elif APR_HAVE_INET_NETWORK        /* only DGUX, as far as I know */
00183 
00187 #define apr_inet_addr    inet_network
00188 #endif
00189 
00191 typedef struct apr_socket_t     apr_socket_t;
00195 typedef struct apr_hdtr_t       apr_hdtr_t;
00197 typedef struct in_addr          apr_in_addr_t;
00199 typedef struct apr_ipsubnet_t apr_ipsubnet_t;
00200 
00202 typedef apr_uint16_t            apr_port_t;
00203 
00207 typedef struct apr_sockaddr_t apr_sockaddr_t;
00211 struct apr_sockaddr_t {
00213     apr_pool_t *pool;
00215     char *hostname;
00217     char *servname;
00219     apr_port_t port;
00221     apr_int32_t family;
00223     apr_socklen_t salen;
00225     int ipaddr_len;
00228     int addr_str_len;
00231     void *ipaddr_ptr;
00234     apr_sockaddr_t *next;
00236     union {
00238         struct sockaddr_in sin;
00239 #if APR_HAVE_IPV6
00240 
00241         struct sockaddr_in6 sin6;
00242 #endif
00243 #if APR_HAVE_SA_STORAGE
00244 
00246         struct sockaddr_storage sas;
00247 #endif
00248     } sa;
00249 };
00250 
00251 #if APR_HAS_SENDFILE
00252 
00257 #define APR_SENDFILE_DISCONNECT_SOCKET      1
00258 #endif
00259 
00261 struct apr_hdtr_t {
00263     struct iovec* headers;
00265     int numheaders;
00267     struct iovec* trailers;
00269     int numtrailers;
00270 };
00271 
00272 /* function definitions */
00273 
00282 APR_DECLARE(apr_status_t) apr_socket_create(apr_socket_t **new_sock, 
00283                                             int family, int type,
00284                                             int protocol,
00285                                             apr_pool_t *cont);
00286 
00300 APR_DECLARE(apr_status_t) apr_socket_shutdown(apr_socket_t *thesocket,
00301                                               apr_shutdown_how_e how);
00302 
00307 APR_DECLARE(apr_status_t) apr_socket_close(apr_socket_t *thesocket);
00308 
00316 APR_DECLARE(apr_status_t) apr_socket_bind(apr_socket_t *sock, 
00317                                           apr_sockaddr_t *sa);
00318 
00326 APR_DECLARE(apr_status_t) apr_socket_listen(apr_socket_t *sock, 
00327                                             apr_int32_t backlog);
00328 
00337 APR_DECLARE(apr_status_t) apr_socket_accept(apr_socket_t **new_sock, 
00338                                             apr_socket_t *sock,
00339                                             apr_pool_t *connection_pool);
00340 
00347 APR_DECLARE(apr_status_t) apr_socket_connect(apr_socket_t *sock,
00348                                              apr_sockaddr_t *sa);
00349 
00362 APR_DECLARE(apr_status_t) apr_socket_atreadeof(apr_socket_t *sock,
00363                                                int *atreadeof);
00364 
00388 APR_DECLARE(apr_status_t) apr_sockaddr_info_get(apr_sockaddr_t **sa,
00389                                           const char *hostname,
00390                                           apr_int32_t family,
00391                                           apr_port_t port,
00392                                           apr_int32_t flags,
00393                                           apr_pool_t *p);
00394 
00401 APR_DECLARE(apr_status_t) apr_getnameinfo(char **hostname,
00402                                           apr_sockaddr_t *sa,
00403                                           apr_int32_t flags);
00404 
00435 APR_DECLARE(apr_status_t) apr_parse_addr_port(char **addr,
00436                                               char **scope_id,
00437                                               apr_port_t *port,
00438                                               const char *str,
00439                                               apr_pool_t *p);
00440 
00449 APR_DECLARE(apr_status_t) apr_gethostname(char *buf, int len, apr_pool_t *cont);
00450 
00457 APR_DECLARE(apr_status_t) apr_socket_data_get(void **data, const char *key,
00458                                               apr_socket_t *sock);
00459 
00467 APR_DECLARE(apr_status_t) apr_socket_data_set(apr_socket_t *sock, void *data,
00468                                               const char *key,
00469                                               apr_status_t (*cleanup)(void*));
00470 
00488 APR_DECLARE(apr_status_t) apr_socket_send(apr_socket_t *sock, const char *buf, 
00489                                           apr_size_t *len);
00490 
00509 APR_DECLARE(apr_status_t) apr_socket_sendv(apr_socket_t *sock, 
00510                                            const struct iovec *vec,
00511                                            apr_int32_t nvec, apr_size_t *len);
00512 
00520 APR_DECLARE(apr_status_t) apr_socket_sendto(apr_socket_t *sock, 
00521                                             apr_sockaddr_t *where,
00522                                             apr_int32_t flags, const char *buf, 
00523                                             apr_size_t *len);
00524 
00538 APR_DECLARE(apr_status_t) apr_socket_recvfrom(apr_sockaddr_t *from, 
00539                                               apr_socket_t *sock,
00540                                               apr_int32_t flags, char *buf, 
00541                                               apr_size_t *len);
00542  
00543 #if APR_HAS_SENDFILE || defined(DOXYGEN)
00544 
00563 APR_DECLARE(apr_status_t) apr_socket_sendfile(apr_socket_t *sock, 
00564                                               apr_file_t *file,
00565                                               apr_hdtr_t *hdtr,
00566                                               apr_off_t *offset,
00567                                               apr_size_t *len,
00568                                               apr_int32_t flags);
00569 
00570 #endif /* APR_HAS_SENDFILE */
00571 
00591 APR_DECLARE(apr_status_t) apr_socket_recv(apr_socket_t *sock, 
00592                                    char *buf, apr_size_t *len);
00593 
00616 APR_DECLARE(apr_status_t) apr_socket_opt_set(apr_socket_t *sock,
00617                                              apr_int32_t opt, apr_int32_t on);
00618 
00630 APR_DECLARE(apr_status_t) apr_socket_timeout_set(apr_socket_t *sock,
00631                                                  apr_interval_time_t t);
00632 
00652 APR_DECLARE(apr_status_t) apr_socket_opt_get(apr_socket_t *sock, 
00653                                              apr_int32_t opt, apr_int32_t *on);
00654 
00660 APR_DECLARE(apr_status_t) apr_socket_timeout_get(apr_socket_t *sock, 
00661                                                  apr_interval_time_t *t);
00662 
00669 APR_DECLARE(apr_status_t) apr_socket_atmark(apr_socket_t *sock, 
00670                                             int *atmark);
00671 
00680 APR_DECLARE(apr_status_t) apr_socket_addr_get(apr_sockaddr_t **sa,
00681                                               apr_interface_e which,
00682                                               apr_socket_t *sock);
00683  
00691 APR_DECLARE(apr_status_t) apr_sockaddr_ip_get(char **addr, 
00692                                               apr_sockaddr_t *sockaddr);
00693 
00699 APR_DECLARE(apr_status_t) apr_sockaddr_ip_getbuf(char *buf, apr_size_t buflen,
00700                                                  apr_sockaddr_t *sockaddr);
00701 
00712 APR_DECLARE(int) apr_sockaddr_equal(const apr_sockaddr_t *addr1,
00713                                     const apr_sockaddr_t *addr2);
00714 
00720 APR_DECLARE(apr_status_t) apr_socket_type_get(apr_socket_t *sock,
00721                                               int *type);
00722  
00728 APR_DECLARE(apr_status_t) apr_getservbyname(apr_sockaddr_t *sockaddr, 
00729                                             const char *servname);
00738 APR_DECLARE(apr_status_t) apr_ipsubnet_create(apr_ipsubnet_t **ipsub, 
00739                                               const char *ipstr, 
00740                                               const char *mask_or_numbits, 
00741                                               apr_pool_t *p);
00742 
00750 APR_DECLARE(int) apr_ipsubnet_test(apr_ipsubnet_t *ipsub, apr_sockaddr_t *sa);
00751 
00752 #if APR_HAS_SO_ACCEPTFILTER || defined(DOXYGEN)
00753 
00762 apr_status_t apr_socket_accept_filter(apr_socket_t *sock, char *name,
00763                                       char *args);
00764 #endif
00765 
00771 APR_DECLARE(apr_status_t) apr_socket_protocol_get(apr_socket_t *sock,
00772                                                   int *protocol);
00773 
00777 APR_POOL_DECLARE_ACCESSOR(socket);
00778 
00782 APR_DECLARE_INHERIT_SET(socket);
00783 
00787 APR_DECLARE_INHERIT_UNSET(socket);
00788 
00803 APR_DECLARE(apr_status_t) apr_mcast_join(apr_socket_t *sock,
00804                                          apr_sockaddr_t *join,
00805                                          apr_sockaddr_t *iface,
00806                                          apr_sockaddr_t *source);
00807 
00818 APR_DECLARE(apr_status_t) apr_mcast_leave(apr_socket_t *sock,
00819                                           apr_sockaddr_t *addr,
00820                                           apr_sockaddr_t *iface,
00821                                           apr_sockaddr_t *source);
00822 
00830 APR_DECLARE(apr_status_t) apr_mcast_hops(apr_socket_t *sock,
00831                                          apr_byte_t ttl);
00832 
00838 APR_DECLARE(apr_status_t) apr_mcast_loopback(apr_socket_t *sock,
00839                                              apr_byte_t opt);
00840 
00841 
00847 APR_DECLARE(apr_status_t) apr_mcast_interface(apr_socket_t *sock,
00848                                               apr_sockaddr_t *iface);
00849 
00854 #ifdef __cplusplus
00855 }
00856 #endif
00857 
00858 #endif  /* ! APR_NETWORK_IO_H */
00859