Apache2
apr_network_io.h
Go to the documentation of this file.
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements. See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef APR_NETWORK_IO_H
18 #define APR_NETWORK_IO_H
24 #include "apr.h"
25 #include "apr_pools.h"
26 #include "apr_file_io.h"
27 #include "apr_errno.h"
28 #include "apr_inherit.h"
29 #include "apr_perms_set.h"
30 
31 #if APR_HAVE_NETINET_IN_H
32 #include <netinet/in.h>
33 #endif
34 #if APR_HAVE_SYS_UN_H
35 #include <sys/un.h>
36 #endif
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif /* __cplusplus */
41 
48 #ifndef APR_MAX_SECS_TO_LINGER
50 #define APR_MAX_SECS_TO_LINGER 30
51 #endif
52 
53 #ifndef APRMAXHOSTLEN
55 #define APRMAXHOSTLEN 256
56 #endif
57 
58 #ifndef APR_ANYADDR
60 #define APR_ANYADDR "0.0.0.0"
61 #endif
62 
67 #define APR_SO_LINGER 1
68 #define APR_SO_KEEPALIVE 2
69 #define APR_SO_DEBUG 4
70 #define APR_SO_NONBLOCK 8
71 #define APR_SO_REUSEADDR 16
72 #define APR_SO_SNDBUF 64
73 #define APR_SO_RCVBUF 128
74 #define APR_SO_DISCONNECTED 256
75 #define APR_TCP_NODELAY 512
78 #define APR_TCP_NOPUSH 1024
79 #define APR_RESET_NODELAY 2048
85 #define APR_INCOMPLETE_READ 4096
96 #define APR_INCOMPLETE_WRITE 8192
99 #define APR_IPV6_V6ONLY 16384
102 #define APR_TCP_DEFER_ACCEPT 32768
106 #define APR_SO_BROADCAST 65536
108 #define APR_SO_FREEBIND 131072
115 typedef enum {
120 
121 #define APR_IPV4_ADDR_OK 0x01
122 #define APR_IPV6_ADDR_OK 0x02
124 #if (!APR_HAVE_IN_ADDR)
129 struct in_addr {
130  apr_uint32_t s_addr;
131 };
132 #endif
133 
138 #ifdef INADDR_NONE
139 #define APR_INADDR_NONE INADDR_NONE
140 #else
141 #define APR_INADDR_NONE ((unsigned int) 0xffffffff)
142 #endif
143 
149 #define APR_INET AF_INET
153 #ifdef AF_UNSPEC
154 #define APR_UNSPEC AF_UNSPEC
155 #else
156 #define APR_UNSPEC 0
157 #endif
158 #if APR_HAVE_IPV6
163 #define APR_INET6 AF_INET6
164 #endif
165 
166 #if APR_HAVE_SOCKADDR_UN
167 #if defined (AF_UNIX)
168 #define APR_UNIX AF_UNIX
169 #elif defined(AF_LOCAL)
170 #define APR_UNIX AF_LOCAL
171 #else
172 #error "Neither AF_UNIX nor AF_LOCAL is defined"
173 #endif
174 #else /* !APR_HAVE_SOCKADDR_UN */
175 #if defined (AF_UNIX)
176 #define APR_UNIX AF_UNIX
177 #elif defined(AF_LOCAL)
178 #define APR_UNIX AF_LOCAL
179 #else
180 /* TODO: Use a smarter way to detect unique APR_UNIX value */
181 #define APR_UNIX 1234
182 #endif
183 #endif
184 
189 #define APR_PROTO_TCP 6
190 #define APR_PROTO_UDP 17
191 #define APR_PROTO_SCTP 132
198 typedef enum {
200  APR_REMOTE
202 
208 #if APR_HAVE_INET_ADDR
209 #define apr_inet_addr inet_addr
210 #elif APR_HAVE_INET_NETWORK /* only DGUX, as far as I know */
215 #define apr_inet_addr inet_network
216 #endif
217 
219 typedef struct apr_socket_t apr_socket_t;
223 typedef struct apr_hdtr_t apr_hdtr_t;
225 typedef struct in_addr apr_in_addr_t;
227 typedef struct apr_ipsubnet_t apr_ipsubnet_t;
228 
231 
235 typedef struct apr_sockaddr_t apr_sockaddr_t;
243  char *hostname;
245  char *servname;
259  void *ipaddr_ptr;
264  union {
266  struct sockaddr_in sin;
267 #if APR_HAVE_IPV6
269  struct sockaddr_in6 sin6;
270 #endif
271 #if APR_HAVE_SA_STORAGE
274  struct sockaddr_storage sas;
275 #endif
276 #if APR_HAVE_SOCKADDR_UN
278  struct sockaddr_un unx;
279 #endif
280  } sa;
281 };
282 
283 #if APR_HAS_SENDFILE
284 /* APR_SENDFILE_DISCONNECT_SOCKET has been removed in APR 2.0. */
285 #endif
286 
288 struct apr_hdtr_t {
290  struct iovec* headers;
294  struct iovec* trailers;
297 };
298 
299 /* function definitions */
300 
313  int family, int type,
314  int protocol,
315  apr_pool_t *cont);
316 
331  apr_shutdown_how_e how);
332 
338 
347  apr_sockaddr_t *sa);
348 
357  apr_int32_t backlog);
358 
371  apr_socket_t *sock,
372  apr_pool_t *connection_pool);
373 
381  apr_sockaddr_t *sa);
382 
396  int *atreadeof);
397 
423  const char *hostname,
424  apr_int32_t family,
425  apr_port_t port,
427  apr_pool_t *p);
428 
436  const apr_sockaddr_t *src,
437  apr_pool_t *p);
438 
447  const char *zone_id);
448 
449 
462  const char **name,
463  apr_uint32_t *id,
464  apr_pool_t *p);
465 
475  apr_sockaddr_t *sa,
477 
509  char **scope_id,
510  apr_port_t *port,
511  const char *str,
512  apr_pool_t *p);
513 
523 
530 APR_DECLARE(apr_status_t) apr_socket_data_get(void **data, const char *key,
531  apr_socket_t *sock);
532 
541  const char *key,
542  apr_status_t (*cleanup)(void*));
543 
562  apr_size_t *len);
563 
583  const struct iovec *vec,
584  apr_int32_t nvec, apr_size_t *len);
585 
594  apr_sockaddr_t *where,
595  apr_int32_t flags, const char *buf,
596  apr_size_t *len);
597 
612  apr_socket_t *sock,
613  apr_int32_t flags, char *buf,
614  apr_size_t *len);
615 
616 #if APR_HAS_SENDFILE || defined(DOXYGEN)
617 
638  apr_file_t *file,
639  apr_hdtr_t *hdtr,
640  apr_off_t *offset,
641  apr_size_t *len,
643 
644 #endif /* APR_HAS_SENDFILE */
645 
666  char *buf, apr_size_t *len);
667 
676  apr_wait_type_t direction);
677 
702  apr_int32_t opt, apr_int32_t on);
703 
717 
738  apr_int32_t opt, apr_int32_t *on);
739 
747 
755  int *atmark);
756 
766  apr_interface_e which,
767  apr_socket_t *sock);
768 
777  apr_sockaddr_t *sockaddr);
778 
785  apr_sockaddr_t *sockaddr);
786 
798  const apr_sockaddr_t *addr2);
799 
809 
816  int *type);
817 
824  const char *servname);
834  const char *ipstr,
835  const char *mask_or_numbits,
836  apr_pool_t *p);
837 
846 
847 #if APR_HAS_SO_ACCEPTFILTER || defined(DOXYGEN)
856  const char *args);
857 #endif
858 
865  int *protocol);
866 
871 
876 
881 
886 
902  apr_sockaddr_t *join,
903  apr_sockaddr_t *iface,
904  apr_sockaddr_t *source);
905 
917  apr_sockaddr_t *addr,
918  apr_sockaddr_t *iface,
919  apr_sockaddr_t *source);
920 
929  apr_byte_t ttl);
930 
937  apr_byte_t opt);
938 
939 
946  apr_sockaddr_t *iface);
947 
952 #ifdef __cplusplus
953 }
954 #endif
955 
956 #endif /* ! APR_NETWORK_IO_H */
957 
APR Platform Definitions.
#define socket
Definition: apr_arch_os2calls.h:41
APR Error Codes.
APR File I/O Handling.
APR File Handle Inheritance Helpers.
APR Process Locking Routines.
APR memory allocation.
dav_resource int dav_locktoken dav_response int flags
Definition: mod_dav.h:1458
dav_buffer const char * str
Definition: mod_dav.h:465
dav_error * src
Definition: mod_dav.h:186
const char * name
Definition: mod_dav.h:805
int apr_status_t
Definition: apr_errno.h:44
apr_wait_type_t
Definition: apr_general.h:71
apr_status_t apr_mcast_hops(apr_socket_t *sock, apr_byte_t ttl)
apr_status_t apr_mcast_join(apr_socket_t *sock, apr_sockaddr_t *join, apr_sockaddr_t *iface, apr_sockaddr_t *source)
apr_status_t apr_mcast_loopback(apr_socket_t *sock, apr_byte_t opt)
apr_status_t apr_mcast_interface(apr_socket_t *sock, apr_sockaddr_t *iface)
apr_status_t apr_mcast_leave(apr_socket_t *sock, apr_sockaddr_t *addr, apr_sockaddr_t *iface, apr_sockaddr_t *source)
apr_status_t apr_socket_sendto(apr_socket_t *sock, apr_sockaddr_t *where, apr_int32_t flags, const char *buf, apr_size_t *len)
apr_status_t apr_socket_opt_set(apr_socket_t *sock, apr_int32_t opt, apr_int32_t on)
apr_status_t apr_sockaddr_zone_set(apr_sockaddr_t *sa, const char *zone_id)
APR_DECLARE_INHERIT_UNSET(socket)
apr_status_t apr_socket_listen(apr_socket_t *sock, apr_int32_t backlog)
apr_status_t apr_socket_opt_get(apr_socket_t *sock, apr_int32_t opt, apr_int32_t *on)
apr_interface_e
Definition: apr_network_io.h:198
int apr_sockaddr_equal(const apr_sockaddr_t *addr1, const apr_sockaddr_t *addr2)
apr_status_t apr_socket_accept_filter(apr_socket_t *sock, const char *name, const char *args)
apr_status_t apr_socket_accept(apr_socket_t **new_sock, apr_socket_t *sock, apr_pool_t *connection_pool)
apr_status_t apr_socket_atmark(apr_socket_t *sock, int *atmark)
apr_status_t apr_socket_wait(apr_socket_t *sock, apr_wait_type_t direction)
apr_status_t apr_ipsubnet_create(apr_ipsubnet_t **ipsub, const char *ipstr, const char *mask_or_numbits, apr_pool_t *p)
apr_status_t apr_socket_sendfile(apr_socket_t *sock, apr_file_t *file, apr_hdtr_t *hdtr, apr_off_t *offset, apr_size_t *len, apr_int32_t flags)
apr_status_t apr_sockaddr_info_copy(apr_sockaddr_t **dst, const apr_sockaddr_t *src, apr_pool_t *p)
apr_status_t apr_socket_create(apr_socket_t **new_sock, int family, int type, int protocol, apr_pool_t *cont)
apr_status_t apr_socket_bind(apr_socket_t *sock, apr_sockaddr_t *sa)
apr_status_t apr_gethostname(char *buf, int len, apr_pool_t *cont)
apr_status_t apr_getnameinfo(char **hostname, apr_sockaddr_t *sa, apr_int32_t flags)
apr_status_t apr_socket_recvfrom(apr_sockaddr_t *from, apr_socket_t *sock, apr_int32_t flags, char *buf, apr_size_t *len)
apr_status_t apr_socket_close(apr_socket_t *thesocket)
apr_status_t apr_sockaddr_ip_getbuf(char *buf, apr_size_t buflen, apr_sockaddr_t *sockaddr)
apr_status_t apr_socket_type_get(apr_socket_t *sock, int *type)
apr_status_t apr_socket_connect(apr_socket_t *sock, apr_sockaddr_t *sa)
apr_status_t apr_parse_addr_port(char **addr, char **scope_id, apr_port_t *port, const char *str, apr_pool_t *p)
apr_status_t apr_socket_send(apr_socket_t *sock, const char *buf, apr_size_t *len)
apr_status_t apr_socket_timeout_set(apr_socket_t *sock, apr_interval_time_t t)
apr_status_t apr_socket_sendv(apr_socket_t *sock, const struct iovec *vec, apr_int32_t nvec, apr_size_t *len)
APR_PERMS_SET_IMPLEMENT(socket)
apr_status_t apr_sockaddr_info_get(apr_sockaddr_t **sa, const char *hostname, apr_int32_t family, apr_port_t port, apr_int32_t flags, apr_pool_t *p)
apr_status_t apr_socket_timeout_get(apr_socket_t *sock, apr_interval_time_t *t)
apr_status_t apr_sockaddr_zone_get(const apr_sockaddr_t *sa, const char **name, apr_uint32_t *id, apr_pool_t *p)
apr_uint16_t apr_port_t
Definition: apr_network_io.h:230
apr_status_t apr_socket_recv(apr_socket_t *sock, char *buf, apr_size_t *len)
APR_POOL_DECLARE_ACCESSOR(socket)
int apr_ipsubnet_test(apr_ipsubnet_t *ipsub, apr_sockaddr_t *sa)
apr_status_t apr_sockaddr_ip_get(char **addr, apr_sockaddr_t *sockaddr)
int apr_sockaddr_is_wildcard(const apr_sockaddr_t *addr)
apr_status_t apr_socket_atreadeof(apr_socket_t *sock, int *atreadeof)
apr_status_t apr_socket_protocol_get(apr_socket_t *sock, int *protocol)
apr_status_t apr_socket_shutdown(apr_socket_t *thesocket, apr_shutdown_how_e how)
struct apr_ipsubnet_t apr_ipsubnet_t
Definition: apr_network_io.h:227
apr_status_t apr_socket_addr_get(apr_sockaddr_t **sa, apr_interface_e which, apr_socket_t *sock)
struct in_addr apr_in_addr_t
Definition: apr_network_io.h:225
apr_status_t apr_getservbyname(apr_sockaddr_t *sockaddr, const char *servname)
apr_shutdown_how_e
Definition: apr_network_io.h:115
apr_status_t apr_socket_data_get(void **data, const char *key, apr_socket_t *sock)
APR_DECLARE_INHERIT_SET(socket)
apr_status_t apr_socket_data_set(apr_socket_t *sock, void *data, const char *key, apr_status_t(*cleanup)(void *))
@ APR_LOCAL
Definition: apr_network_io.h:199
@ APR_REMOTE
Definition: apr_network_io.h:200
@ APR_SHUTDOWN_WRITE
Definition: apr_network_io.h:117
@ APR_SHUTDOWN_READ
Definition: apr_network_io.h:116
@ APR_SHUTDOWN_READWRITE
Definition: apr_network_io.h:118
int apr_int32_t
Definition: apr.h:347
unsigned short apr_uint16_t
Definition: apr.h:345
unsigned int apr_uint32_t
Definition: apr.h:348
off_t apr_off_t
Definition: apr.h:396
size_t apr_size_t
Definition: apr.h:394
socklen_t apr_socklen_t
Definition: apr.h:397
unsigned char apr_byte_t
Definition: apr.h:342
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
apr_int64_t apr_interval_time_t
Definition: apr_time.h:55
#define APR_DECLARE(x)
Definition: macros.h:6
Definition: apr_arch_file_io.h:107
Definition: apr_network_io.h:288
struct iovec * trailers
Definition: apr_network_io.h:294
int numheaders
Definition: apr_network_io.h:292
int numtrailers
Definition: apr_network_io.h:296
struct iovec * headers
Definition: apr_network_io.h:290
Definition: apr_network_io.h:239
apr_port_t port
Definition: apr_network_io.h:247
apr_pool_t * pool
Definition: apr_network_io.h:241
char * servname
Definition: apr_network_io.h:245
void * ipaddr_ptr
Definition: apr_network_io.h:259
apr_sockaddr_t * next
Definition: apr_network_io.h:262
struct sockaddr_in sin
Definition: apr_network_io.h:266
int ipaddr_len
Definition: apr_network_io.h:253
char * hostname
Definition: apr_network_io.h:243
int addr_str_len
Definition: apr_network_io.h:256
union apr_sockaddr_t::@18 sa
struct sockaddr_in6 sin6
Definition: apr_network_io.h:269
struct sockaddr_un unx
Definition: apr_network_io.h:278
apr_int32_t family
Definition: apr_network_io.h:249
struct sockaddr_storage sas
Definition: apr_network_io.h:274
apr_socklen_t salen
Definition: apr_network_io.h:251
Definition: apr_arch_networkio.h:37
apr_pool_t * p