Apache2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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
19 
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
49 
50 #define APR_MAX_SECS_TO_LINGER 30
51 #endif
52 
53 #ifndef APRMAXHOSTLEN
54 
55 #define APRMAXHOSTLEN 256
56 #endif
57 
58 #ifndef APR_ANYADDR
59 
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)
125 
129 struct in_addr {
130  apr_uint32_t s_addr;
131 };
132 #endif
138 #ifdef INADDR_NONE
139 #define APR_INADDR_NONE INADDR_NONE
140 #else
141 #define APR_INADDR_NONE ((unsigned int) 0xffffffff)
142 #endif
149 #define APR_INET AF_INET
150 
153 #ifdef AF_UNSPEC
154 #define APR_UNSPEC AF_UNSPEC
155 #else
156 #define APR_UNSPEC 0
157 #endif
158 #if APR_HAVE_IPV6
159 
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 {
199  APR_LOCAL,
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 */
211 
215 #define apr_inet_addr inet_network
216 #endif
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;
228 
230 typedef apr_uint16_t apr_port_t;
231 
235 typedef struct apr_sockaddr_t apr_sockaddr_t;
239 struct apr_sockaddr_t {
241  apr_pool_t *pool;
243  char *hostname;
245  char *servname;
253  int ipaddr_len;
256  int addr_str_len;
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
277 
278  struct sockaddr_un unx;
279 #endif
280  } sa;
281 };
282 
283 #if APR_HAS_SENDFILE
284 
289 #define APR_SENDFILE_DISCONNECT_SOCKET 1
290 #endif
291 
293 struct apr_hdtr_t {
295  struct iovec* headers;
297  int numheaders;
299  struct iovec* trailers;
302 };
303 
304 /* function definitions */
318  int family, int type,
319  int protocol,
320  apr_pool_t *cont);
321 
336  apr_shutdown_how_e how);
337 
343 
352  apr_sockaddr_t *sa);
353 
362  apr_int32_t backlog);
363 
376  apr_socket_t *sock,
377  apr_pool_t *connection_pool);
378 
386  apr_sockaddr_t *sa);
387 
401  int *atreadeof);
402 
428  const char *hostname,
429  apr_int32_t family,
430  apr_port_t port,
432  apr_pool_t *p);
433 
441  const apr_sockaddr_t *src,
442  apr_pool_t *p);
443 
444 /* Set the zone of an IPv6 link-local address object.
445  * @param sa Socket address object
446  * @param zone_id Zone ID (textual "eth0" or numeric "3").
447  * @return Returns APR_EBADIP for non-IPv6 socket or an IPv6 address
448  * which isn't link-local.
449  */
451  const char *zone_id);
452 
453 
454 /* Retrieve the zone of an IPv6 link-local address object.
455  * @param sa Socket address object
456  * @param name If non-NULL, set to the textual representation of the zone id
457  * @param id If non-NULL, set to the integer zone id
458  * @param p Pool from which *name is allocated if used.
459  * @return Returns APR_EBADIP for non-IPv6 socket or socket without any zone id
460  * set, or other error if the interface could not be mapped to a name.
461  * @remark Both name and id may be NULL, neither are modified if
462  * non-NULL in error cases.
463  */
465  const char **name,
466  apr_uint32_t *id,
467  apr_pool_t *p);
468 
477 APR_DECLARE(apr_status_t) apr_getnameinfo(char **hostname,
478  apr_sockaddr_t *sa,
479  apr_int32_t flags);
480 
512  char **scope_id,
513  apr_port_t *port,
514  const char *str,
515  apr_pool_t *p);
516 
525 APR_DECLARE(apr_status_t) apr_gethostname(char *buf, int len, apr_pool_t *cont);
526 
533 APR_DECLARE(apr_status_t) apr_socket_data_get(void **data, const char *key,
534  apr_socket_t *sock);
535 
544  const char *key,
545  apr_status_t (*cleanup)(void*));
546 
564 APR_DECLARE(apr_status_t) apr_socket_send(apr_socket_t *sock, const char *buf,
565  apr_size_t *len);
566 
586  const struct iovec *vec,
587  apr_int32_t nvec, apr_size_t *len);
588 
597  apr_sockaddr_t *where,
598  apr_int32_t flags, const char *buf,
599  apr_size_t *len);
600 
615  apr_socket_t *sock,
616  apr_int32_t flags, char *buf,
617  apr_size_t *len);
618 
619 #if APR_HAS_SENDFILE || defined(DOXYGEN)
620 
641  apr_file_t *file,
642  apr_hdtr_t *hdtr,
643  apr_off_t *offset,
644  apr_size_t *len,
645  apr_int32_t flags);
646 
647 #endif /* APR_HAS_SENDFILE */
648 
669  char *buf, apr_size_t *len);
670 
679  apr_wait_type_t direction);
680 
705  apr_int32_t opt, apr_int32_t on);
706 
720 
741  apr_int32_t opt, apr_int32_t *on);
742 
750 
758  int *atmark);
759 
769  apr_interface_e which,
770  apr_socket_t *sock);
771 
780  apr_sockaddr_t *sockaddr);
781 
788  apr_sockaddr_t *sockaddr);
789 
801  const apr_sockaddr_t *addr2);
802 
812 
819  int *type);
820 
827  const char *servname);
837  const char *ipstr,
838  const char *mask_or_numbits,
839  apr_pool_t *p);
840 
849 
850 #if APR_HAS_SO_ACCEPTFILTER || defined(DOXYGEN)
851 
858 apr_status_t apr_socket_accept_filter(apr_socket_t *sock, const char *name,
859  const char *args);
860 #endif
861 
868  int *protocol);
869 
874 
879 
884 
889 
905  apr_sockaddr_t *join,
906  apr_sockaddr_t *iface,
907  apr_sockaddr_t *source);
908 
920  apr_sockaddr_t *addr,
921  apr_sockaddr_t *iface,
922  apr_sockaddr_t *source);
923 
932  apr_byte_t ttl);
933 
940  apr_byte_t opt);
941 
942 
949  apr_sockaddr_t *iface);
950 
955 #ifdef __cplusplus
956 }
957 #endif
958 
959 #endif /* ! APR_NETWORK_IO_H */
960 
#define socket
Definition: apr_arch_os2calls.h:41
apr_status_t apr_mcast_hops(apr_socket_t *sock, apr_byte_t ttl)
apr_status_t apr_socket_close(apr_socket_t *thesocket)
size_t apr_size_t
Definition: apr.h:375
struct sockaddr_storage sas
Definition: apr_network_io.h:301
apr_status_t apr_socket_timeout_get(apr_socket_t *sock, apr_interval_time_t *t)
int apr_sockaddr_is_wildcard(const apr_sockaddr_t *addr)
apr_status_t apr_sockaddr_ip_get(char **addr, apr_sockaddr_t *sockaddr)
APR Process Locking Routines.
Definition: apr_arch_file_io.h:107
apr_status_t apr_sockaddr_zone_set(apr_sockaddr_t *sa, const char *zone_id)
struct sockaddr_in sin
Definition: apr_network_io.h:293
apr_status_t apr_socket_opt_get(apr_socket_t *sock, apr_int32_t opt, apr_int32_t *on)
apr_status_t apr_socket_opt_set(apr_socket_t *sock, apr_int32_t opt, apr_int32_t on)
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_sendv(apr_socket_t *sock, const struct iovec *vec, apr_int32_t nvec, apr_size_t *len)
apr_status_t apr_socket_listen(apr_socket_t *sock, apr_int32_t backlog)
struct apr_ipsubnet_t apr_ipsubnet_t
Definition: apr_network_io.h:254
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 File Handle Inheritance Helpers.
apr_shutdown_how_e
Definition: apr_network_io.h:142
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_socket_addr_get(apr_sockaddr_t **sa, apr_interface_e which, apr_socket_t *sock)
apr_status_t apr_socket_atreadeof(apr_socket_t *sock, int *atreadeof)
unsigned char apr_byte_t
Definition: apr.h:328
apr_status_t apr_socket_protocol_get(apr_socket_t *sock, int *protocol)
int apr_ipsubnet_test(apr_ipsubnet_t *ipsub, apr_sockaddr_t *sa)
apr_status_t apr_socket_data_get(void **data, const char *key, apr_socket_t *sock)
Definition: apr_network_io.h:144
APR File I/O Handling.
APR_PERMS_SET_IMPLEMENT(socket)
apr_int64_t apr_interval_time_t
Definition: apr_time.h:55
apr_status_t apr_socket_send(apr_socket_t *sock, const char *buf, apr_size_t *len)
apr_status_t apr_gethostname(char *buf, int len, apr_pool_t *cont)
char * servname
Definition: apr_network_io.h:272
apr_status_t apr_parse_addr_port(char **addr, char **scope_id, apr_port_t *port, const char *str, apr_pool_t *p)
unsigned short apr_uint16_t
Definition: apr.h:331
APR_POOL_DECLARE_ACCESSOR(socket)
apr_status_t apr_socket_bind(apr_socket_t *sock, apr_sockaddr_t *sa)
apr_int32_t family
Definition: apr_network_io.h:276
APR memory allocation.
apr_status_t apr_socket_recv(apr_socket_t *sock, char *buf, apr_size_t *len)
Definition: apr_network_io.h:143
int apr_sockaddr_equal(const apr_sockaddr_t *addr1, const apr_sockaddr_t *addr2)
apr_sockaddr_t * next
Definition: apr_network_io.h:289
apr_status_t apr_socket_accept(apr_socket_t **new_sock, apr_socket_t *sock, apr_pool_t *connection_pool)
struct sockaddr_in6 sin6
Definition: apr_network_io.h:296
Definition: apr_arch_networkio.h:37
dav_error * src
Definition: mod_dav.h:186
apr_status_t apr_socket_timeout_set(apr_socket_t *sock, apr_interval_time_t t)
APR_DECLARE_INHERIT_UNSET(socket)
int numtrailers
Definition: apr_network_io.h:328
apr_status_t apr_sockaddr_zone_get(const apr_sockaddr_t *sa, const char **name, apr_uint32_t *id, apr_pool_t *p)
APR Error Codes.
int addr_str_len
Definition: apr_network_io.h:283
apr_status_t apr_mcast_leave(apr_socket_t *sock, apr_sockaddr_t *addr, apr_sockaddr_t *iface, apr_sockaddr_t *source)
union apr_sockaddr_t::@18 sa
unsigned int apr_uint32_t
Definition: apr.h:334
apr_status_t apr_sockaddr_info_copy(apr_sockaddr_t **dst, const apr_sockaddr_t *src, apr_pool_t *p)
APR Platform Definitions.
apr_wait_type_t
Definition: apr_general.h:71
apr_interface_e
Definition: apr_network_io.h:225
apr_pool_t * p
apr_status_t apr_socket_data_set(apr_socket_t *sock, void *data, const char *key, apr_status_t(*cleanup)(void *))
apr_status_t apr_sockaddr_ip_getbuf(char *buf, apr_size_t buflen, apr_sockaddr_t *sockaddr)
apr_status_t apr_ipsubnet_create(apr_ipsubnet_t **ipsub, const char *ipstr, const char *mask_or_numbits, apr_pool_t *p)
char * hostname
Definition: apr_network_io.h:270
socklen_t apr_socklen_t
Definition: apr.h:378
#define APR_DECLARE(x)
Definition: macros.h:6
apr_status_t apr_mcast_loopback(apr_socket_t *sock, apr_byte_t opt)
apr_status_t apr_socket_accept_filter(apr_socket_t *sock, const char *name, const char *args)
apr_status_t apr_socket_recvfrom(apr_sockaddr_t *from, apr_socket_t *sock, apr_int32_t flags, char *buf, apr_size_t *len)
dav_buffer const char * str
Definition: mod_dav.h:461
void * ipaddr_ptr
Definition: apr_network_io.h:286
struct sockaddr_un unx
Definition: apr_network_io.h:305
const char * name
Definition: mod_dav.h:726
apr_status_t apr_socket_type_get(apr_socket_t *sock, int *type)
apr_status_t apr_getservbyname(apr_sockaddr_t *sockaddr, const char *servname)
struct iovec * trailers
Definition: apr_network_io.h:326
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
int apr_status_t
Definition: apr_errno.h:44
struct iovec * headers
Definition: apr_network_io.h:322
int ipaddr_len
Definition: apr_network_io.h:280
apr_uint16_t apr_port_t
Definition: apr_network_io.h:257
apr_status_t apr_socket_atmark(apr_socket_t *sock, int *atmark)
apr_pool_t * pool
Definition: apr_network_io.h:268
apr_status_t apr_socket_connect(apr_socket_t *sock, apr_sockaddr_t *sa)
apr_status_t apr_socket_wait(apr_socket_t *sock, apr_wait_type_t direction)
Definition: apr_network_io.h:227
struct in_addr apr_in_addr_t
Definition: apr_network_io.h:252
apr_port_t port
Definition: apr_network_io.h:274
apr_status_t apr_mcast_interface(apr_socket_t *sock, apr_sockaddr_t *iface)
Definition: apr_network_io.h:145
dav_resource int dav_locktoken dav_response int flags
Definition: mod_dav.h:1346
Definition: apr_network_io.h:320
apr_status_t apr_getnameinfo(char **hostname, apr_sockaddr_t *sa, apr_int32_t flags)
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)
int numheaders
Definition: apr_network_io.h:324
APR_DECLARE_INHERIT_SET(socket)
off_t apr_off_t
Definition: apr.h:377
Definition: apr_network_io.h:266
apr_socklen_t salen
Definition: apr_network_io.h:278
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_socket_shutdown(apr_socket_t *thesocket, apr_shutdown_how_e how)
int apr_int32_t
Definition: apr.h:333
Definition: apr_network_io.h:226