00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
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
00169 typedef enum {
00170 APR_LOCAL,
00171 APR_REMOTE
00172 } apr_interface_e;
00173
00179 #if APR_HAVE_INET_ADDR
00180 #define apr_inet_addr inet_addr
00181 #elif APR_HAVE_INET_NETWORK
00182
00186 #define apr_inet_addr inet_network
00187 #endif
00188
00190 typedef struct apr_socket_t apr_socket_t;
00194 typedef struct apr_hdtr_t apr_hdtr_t;
00196 typedef struct in_addr apr_in_addr_t;
00198 typedef struct apr_ipsubnet_t apr_ipsubnet_t;
00199
00201 typedef apr_uint16_t apr_port_t;
00202
00206 typedef struct apr_sockaddr_t apr_sockaddr_t;
00210 struct apr_sockaddr_t {
00212 apr_pool_t *pool;
00214 char *hostname;
00216 char *servname;
00218 apr_port_t port;
00220 apr_int32_t family;
00222 apr_socklen_t salen;
00224 int ipaddr_len;
00227 int addr_str_len;
00230 void *ipaddr_ptr;
00233 apr_sockaddr_t *next;
00235 union {
00237 struct sockaddr_in sin;
00238 #if APR_HAVE_IPV6
00239
00240 struct sockaddr_in6 sin6;
00241 #endif
00242 #if APR_HAVE_SA_STORAGE
00243
00245 struct sockaddr_storage sas;
00246 #endif
00247 } sa;
00248 };
00249
00250 #if APR_HAS_SENDFILE
00251
00256 #define APR_SENDFILE_DISCONNECT_SOCKET 1
00257 #endif
00258
00260 struct apr_hdtr_t {
00262 struct iovec* headers;
00264 int numheaders;
00266 struct iovec* trailers;
00268 int numtrailers;
00269 };
00270
00271
00272
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
00299 APR_DECLARE(apr_status_t) apr_socket_shutdown(apr_socket_t *thesocket,
00300 apr_shutdown_how_e how);
00301
00306 APR_DECLARE(apr_status_t) apr_socket_close(apr_socket_t *thesocket);
00307
00315 APR_DECLARE(apr_status_t) apr_socket_bind(apr_socket_t *sock,
00316 apr_sockaddr_t *sa);
00317
00325 APR_DECLARE(apr_status_t) apr_socket_listen(apr_socket_t *sock,
00326 apr_int32_t backlog);
00327
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
00346 APR_DECLARE(apr_status_t) apr_socket_connect(apr_socket_t *sock,
00347 apr_sockaddr_t *sa);
00348
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
00385 APR_DECLARE(apr_status_t) apr_getnameinfo(char **hostname,
00386 apr_sockaddr_t *sa,
00387 apr_int32_t flags);
00388
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
00433 APR_DECLARE(apr_status_t) apr_gethostname(char *buf, int len, apr_pool_t *cont);
00434
00441 APR_DECLARE(apr_status_t) apr_socket_data_get(void **data, const char *key,
00442 apr_socket_t *sock);
00443
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
00472 APR_DECLARE(apr_status_t) apr_socket_send(apr_socket_t *sock, const char *buf,
00473 apr_size_t *len);
00474
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
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
00517 APR_DECLARE(apr_status_t) apr_socket_recvfrom(apr_sockaddr_t *from,
00518 apr_socket_t *sock,
00519 apr_int32_t flags, char *buf,
00520 apr_size_t *len);
00521
00522 #if APR_HAS_SENDFILE || defined(DOXYGEN)
00523
00542 APR_DECLARE(apr_status_t) apr_socket_sendfile(apr_socket_t *sock,
00543 apr_file_t *file,
00544 apr_hdtr_t *hdtr,
00545 apr_off_t *offset,
00546 apr_size_t *len,
00547 apr_int32_t flags);
00548
00549 #endif
00550
00570 APR_DECLARE(apr_status_t) apr_socket_recv(apr_socket_t *sock,
00571 char *buf, apr_size_t *len);
00572
00595 APR_DECLARE(apr_status_t) apr_socket_opt_set(apr_socket_t *sock,
00596 apr_int32_t opt, apr_int32_t on);
00597
00609 APR_DECLARE(apr_status_t) apr_socket_timeout_set(apr_socket_t *sock,
00610 apr_interval_time_t t);
00611
00631 APR_DECLARE(apr_status_t) apr_socket_opt_get(apr_socket_t *sock,
00632 apr_int32_t opt, apr_int32_t *on);
00633
00639 APR_DECLARE(apr_status_t) apr_socket_timeout_get(apr_socket_t *sock,
00640 apr_interval_time_t *t);
00641
00648 APR_DECLARE(apr_status_t) apr_socket_atmark(apr_socket_t *sock,
00649 int *atmark);
00650
00657 APR_DECLARE(apr_status_t) apr_socket_addr_get(apr_sockaddr_t **sa,
00658 apr_interface_e which,
00659 apr_socket_t *sock);
00660
00668 APR_DECLARE(apr_status_t) apr_sockaddr_ip_get(char **addr,
00669 apr_sockaddr_t *sockaddr);
00670
00681 APR_DECLARE(int) apr_sockaddr_equal(const apr_sockaddr_t *addr1,
00682 const apr_sockaddr_t *addr2);
00683
00689 APR_DECLARE(apr_status_t) apr_socket_type_get(apr_socket_t *sock,
00690 int *type);
00691
00697 APR_DECLARE(apr_status_t) apr_getservbyname(apr_sockaddr_t *sockaddr,
00698 const char *servname);
00707 APR_DECLARE(apr_status_t) apr_ipsubnet_create(apr_ipsubnet_t **ipsub,
00708 const char *ipstr,
00709 const char *mask_or_numbits,
00710 apr_pool_t *p);
00711
00719 APR_DECLARE(int) apr_ipsubnet_test(apr_ipsubnet_t *ipsub, apr_sockaddr_t *sa);
00720
00721 #if APR_HAS_SO_ACCEPTFILTER || defined(DOXYGEN)
00722
00729 apr_status_t apr_socket_accept_filter(apr_socket_t *sock, char *name,
00730 char *args);
00731 #endif
00732
00738 APR_DECLARE(apr_status_t) apr_socket_protocol_get(apr_socket_t *sock,
00739 int *protocol);
00740
00744 APR_POOL_DECLARE_ACCESSOR(socket);
00745
00749 APR_DECLARE_INHERIT_SET(socket);
00750
00754 APR_DECLARE_INHERIT_UNSET(socket);
00755
00770 APR_DECLARE(apr_status_t) apr_mcast_join(apr_socket_t *sock,
00771 apr_sockaddr_t *join,
00772 apr_sockaddr_t *iface,
00773 apr_sockaddr_t *source);
00774
00785 APR_DECLARE(apr_status_t) apr_mcast_leave(apr_socket_t *sock,
00786 apr_sockaddr_t *addr,
00787 apr_sockaddr_t *iface,
00788 apr_sockaddr_t *source);
00789
00797 APR_DECLARE(apr_status_t) apr_mcast_hops(apr_socket_t *sock,
00798 apr_byte_t ttl);
00799
00805 APR_DECLARE(apr_status_t) apr_mcast_loopback(apr_socket_t *sock,
00806 apr_byte_t opt);
00807
00808
00814 APR_DECLARE(apr_status_t) apr_mcast_interface(apr_socket_t *sock,
00815 apr_sockaddr_t *iface);
00816
00821 #ifdef __cplusplus
00822 }
00823 #endif
00824
00825 #endif
00826