Apache Portable Runtime
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 /**
20  * @file apr_network_io.h
21  * @brief APR Network library
22  */
23 
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 
42 /**
43  * @defgroup apr_network_io Network Routines
44  * @ingroup APR
45  * @{
46  */
47 
48 #ifndef APR_MAX_SECS_TO_LINGER
49 /** Maximum seconds to linger */
50 #define APR_MAX_SECS_TO_LINGER 30
51 #endif
52 
53 #ifndef APRMAXHOSTLEN
54 /** Maximum hostname length */
55 #define APRMAXHOSTLEN 256
56 #endif
57 
58 #ifndef APR_ANYADDR
59 /** Default 'any' address */
60 #define APR_ANYADDR "0.0.0.0"
61 #endif
62 
63 /**
64  * @defgroup apr_sockopt Socket option definitions
65  * @{
66  */
67 #define APR_SO_LINGER 1 /**< Linger */
68 #define APR_SO_KEEPALIVE 2 /**< Keepalive */
69 #define APR_SO_DEBUG 4 /**< Debug */
70 #define APR_SO_NONBLOCK 8 /**< Non-blocking IO */
71 #define APR_SO_REUSEADDR 16 /**< Reuse addresses */
72 #define APR_SO_SNDBUF 64 /**< Send buffer */
73 #define APR_SO_RCVBUF 128 /**< Receive buffer */
74 #define APR_SO_DISCONNECTED 256 /**< Disconnected */
75 #define APR_TCP_NODELAY 512 /**< For SCTP sockets, this is mapped
76  * to STCP_NODELAY internally.
77  */
78 #define APR_TCP_NOPUSH 1024 /**< No push */
79 #define APR_RESET_NODELAY 2048 /**< This flag is ONLY set internally
80  * when we set APR_TCP_NOPUSH with
81  * APR_TCP_NODELAY set to tell us that
82  * APR_TCP_NODELAY should be turned on
83  * again when NOPUSH is turned off
84  */
85 #define APR_INCOMPLETE_READ 4096 /**< Set on non-blocking sockets
86  * (timeout != 0) on which the
87  * previous read() did not fill a buffer
88  * completely. the next apr_socket_recv()
89  * will first call select()/poll() rather than
90  * going straight into read(). (Can also
91  * be set by an application to force a
92  * select()/poll() call before the next
93  * read, in cases where the app expects
94  * that an immediate read would fail.)
95  */
96 #define APR_INCOMPLETE_WRITE 8192 /**< like APR_INCOMPLETE_READ, but for write
97  * @see APR_INCOMPLETE_READ
98  */
99 #define APR_IPV6_V6ONLY 16384 /**< Don't accept IPv4 connections on an
100  * IPv6 listening socket.
101  */
102 #define APR_TCP_DEFER_ACCEPT 32768 /**< Delay accepting of new connections
103  * until data is available.
104  * @see apr_socket_accept_filter
105  */
106 #define APR_SO_BROADCAST 65536 /**< Allow broadcast
107  */
108 #define APR_SO_FREEBIND 131072 /**< Allow binding to addresses not owned
109  * by any interface
110  */
111 
112 /** @} */
113 
114 /** Define what type of socket shutdown should occur. */
115 typedef enum {
116  APR_SHUTDOWN_READ, /**< no longer allow read request */
117  APR_SHUTDOWN_WRITE, /**< no longer allow write requests */
118  APR_SHUTDOWN_READWRITE /**< no longer allow read or write requests */
120 
121 #define APR_IPV4_ADDR_OK 0x01 /**< @see apr_sockaddr_info_get() */
122 #define APR_IPV6_ADDR_OK 0x02 /**< @see apr_sockaddr_info_get() */
123 
124 #if (!APR_HAVE_IN_ADDR)
125 /**
126  * We need to make sure we always have an in_addr type, so APR will just
127  * define it ourselves, if the platform doesn't provide it.
128  */
129 struct in_addr {
130  apr_uint32_t s_addr; /**< storage to hold the IP# */
131 };
132 #endif
133 
134 /** @def APR_INADDR_NONE
135  * Not all platforms have a real INADDR_NONE. This macro replaces
136  * INADDR_NONE on all platforms.
137  */
138 #ifdef INADDR_NONE
139 #define APR_INADDR_NONE INADDR_NONE
140 #else
141 #define APR_INADDR_NONE ((unsigned int) 0xffffffff)
142 #endif
143 
144 /**
145  * @def APR_INET
146  * Not all platforms have these defined, so we'll define them here
147  * The default values come from FreeBSD 4.1.1
148  */
149 #define APR_INET AF_INET
150 /** @def APR_UNSPEC
151  * Let the system decide which address family to use
152  */
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 /** @def APR_INET6
160 * IPv6 Address Family. Not all platforms may have this defined.
161 */
162 
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 
185 /**
186  * @defgroup IP_Proto IP Protocol Definitions for use when creating sockets
187  * @{
188  */
189 #define APR_PROTO_TCP 6 /**< TCP */
190 #define APR_PROTO_UDP 17 /**< UDP */
191 #define APR_PROTO_SCTP 132 /**< SCTP */
192 /** @} */
193 
194 /**
195  * Enum used to denote either the local and remote endpoint of a
196  * connection.
197  */
198 typedef enum {
199  APR_LOCAL, /**< Socket information for local end of connection */
200  APR_REMOTE /**< Socket information for remote end of connection */
202 
203 /**
204  * The specific declaration of inet_addr's ... some platforms fall back
205  * inet_network (this is not good, but necessary)
206  */
207 
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 /**
212  * @warning
213  * not generally safe... inet_network() and inet_addr() perform
214  * different functions */
215 #define apr_inet_addr inet_network
216 #endif
217 
218 /** A structure to represent sockets */
219 typedef struct apr_socket_t apr_socket_t;
220 /**
221  * A structure to encapsulate headers and trailers for apr_socket_sendfile
222  */
223 typedef struct apr_hdtr_t apr_hdtr_t;
224 /** A structure to represent in_addr */
225 typedef struct in_addr apr_in_addr_t;
226 /** A structure to represent an IP subnet */
227 typedef struct apr_ipsubnet_t apr_ipsubnet_t;
228 
229 /** @remark use apr_uint16_t just in case some system has a short that isn't 16 bits... */
230 typedef apr_uint16_t apr_port_t;
231 
232 /** @remark It's defined here as I think it should all be platform safe...
233  * @see apr_sockaddr_t
234  */
235 typedef struct apr_sockaddr_t apr_sockaddr_t;
236 /**
237  * APRs socket address type, used to ensure protocol independence
238  */
240  /** The pool to use... */
242  /** The hostname */
243  char *hostname;
244  /** Either a string of the port number or the service name for the port */
245  char *servname;
246  /** The numeric port */
248  /** The family */
249  apr_int32_t family;
250  /** How big is the sockaddr we're using? */
251  apr_socklen_t salen;
252  /** How big is the ip address structure we're using? */
254  /** How big should the address buffer be? 16 for v4 or 46 for v6
255  * used in inet_ntop... */
257  /** This points to the IP address structure within the appropriate
258  * sockaddr structure. */
259  void *ipaddr_ptr;
260  /** If multiple addresses were found by apr_sockaddr_info_get(), this
261  * points to a representation of the next address. */
263  /** Union of either IPv4 or IPv6 sockaddr. */
264  union {
265  /** IPv4 sockaddr structure */
266  struct sockaddr_in sin;
267 #if APR_HAVE_IPV6
268  /** IPv6 sockaddr structure */
269  struct sockaddr_in6 sin6;
270 #endif
271 #if APR_HAVE_SA_STORAGE
272  /** Placeholder to ensure that the size of this union is not
273  * dependent on whether APR_HAVE_IPV6 is defined. */
274  struct sockaddr_storage sas;
275 #endif
276 #if APR_HAVE_SOCKADDR_UN
277  /** Unix domain socket sockaddr structure */
278  struct sockaddr_un unx;
279 #endif
280  } sa;
281 };
282 
283 #if APR_HAS_SENDFILE
284 /**
285  * Support reusing the socket on platforms which support it (from disconnect,
286  * specifically Win32.
287  * @remark Optional flag passed into apr_socket_sendfile()
288  */
289 #define APR_SENDFILE_DISCONNECT_SOCKET 1
290 #endif
291 
292 /** A structure to encapsulate headers and trailers for apr_socket_sendfile */
293 struct apr_hdtr_t {
294  /** An iovec to store the headers sent before the file. */
295  struct iovec* headers;
296  /** number of headers in the iovec */
298  /** An iovec to store the trailers sent after the file. */
299  struct iovec* trailers;
300  /** number of trailers in the iovec */
302 };
303 
304 /* function definitions */
305 
306 /**
307  * Create a socket.
308  * @param new_sock The new socket that has been set up.
309  * @param family The address family of the socket (e.g., APR_INET).
310  * @param type The type of the socket (e.g., SOCK_STREAM).
311  * @param protocol The protocol of the socket (e.g., APR_PROTO_TCP).
312  * @param cont The pool for the apr_socket_t and associated storage.
313  * @note The pool will be used by various functions that operate on the
314  * socket. The caller must ensure that it is not used by other threads
315  * at the same time.
316  */
318  int family, int type,
319  int protocol,
320  apr_pool_t *cont);
321 
322 /**
323  * Shutdown either reading, writing, or both sides of a socket.
324  * @param thesocket The socket to close
325  * @param how How to shutdown the socket. One of:
326  * <PRE>
327  * APR_SHUTDOWN_READ no longer allow read requests
328  * APR_SHUTDOWN_WRITE no longer allow write requests
329  * APR_SHUTDOWN_READWRITE no longer allow read or write requests
330  * </PRE>
331  * @see apr_shutdown_how_e
332  * @remark This does not actually close the socket descriptor, it just
333  * controls which calls are still valid on the socket.
334  */
336  apr_shutdown_how_e how);
337 
338 /**
339  * Close a socket.
340  * @param thesocket The socket to close
341  */
343 
344 /**
345  * Bind the socket to its associated port
346  * @param sock The socket to bind
347  * @param sa The socket address to bind to
348  * @remark This may be where we will find out if there is any other process
349  * using the selected port.
350  */
352  apr_sockaddr_t *sa);
353 
354 /**
355  * Listen to a bound socket for connections.
356  * @param sock The socket to listen on
357  * @param backlog The number of outstanding connections allowed in the sockets
358  * listen queue. If this value is less than zero, the listen
359  * queue size is set to zero.
360  */
362  apr_int32_t backlog);
363 
364 /**
365  * Accept a new connection request
366  * @param new_sock A copy of the socket that is connected to the socket that
367  * made the connection request. This is the socket which should
368  * be used for all future communication.
369  * @param sock The socket we are listening on.
370  * @param connection_pool The pool for the new socket.
371  * @note The pool will be used by various functions that operate on the
372  * socket. The caller must ensure that it is not used by other threads
373  * at the same time.
374  */
376  apr_socket_t *sock,
377  apr_pool_t *connection_pool);
378 
379 /**
380  * Issue a connection request to a socket either on the same machine
381  * or a different one.
382  * @param sock The socket we wish to use for our side of the connection
383  * @param sa The address of the machine we wish to connect to.
384  */
386  apr_sockaddr_t *sa);
387 
388 /**
389  * Determine whether the receive part of the socket has been closed by
390  * the peer (such that a subsequent call to apr_socket_read would
391  * return APR_EOF), if the socket's receive buffer is empty. This
392  * function does not block waiting for I/O.
393  *
394  * @param sock The socket to check
395  * @param atreadeof If APR_SUCCESS is returned, *atreadeof is set to
396  * non-zero if a subsequent read would return APR_EOF
397  * @return an error is returned if it was not possible to determine the
398  * status, in which case *atreadeof is not changed.
399  */
401  int *atreadeof);
402 
403 /**
404  * Create apr_sockaddr_t from hostname, address family, and port.
405  * @param sa The new apr_sockaddr_t.
406  * @param hostname The hostname or numeric address string to resolve/parse, or
407  * NULL to build an address that corresponds to 0.0.0.0 or ::
408  * or in case of APR_UNIX family it is absolute socket filename.
409  * @param family The address family to use, or APR_UNSPEC if the system should
410  * decide.
411  * @param port The port number.
412  * @param flags Special processing flags:
413  * <PRE>
414  * APR_IPV4_ADDR_OK first query for IPv4 addresses; only look
415  * for IPv6 addresses if the first query failed;
416  * only valid if family is APR_UNSPEC and hostname
417  * isn't NULL; mutually exclusive with
418  * APR_IPV6_ADDR_OK
419  * APR_IPV6_ADDR_OK first query for IPv6 addresses; only look
420  * for IPv4 addresses if the first query failed;
421  * only valid if family is APR_UNSPEC and hostname
422  * isn't NULL and APR_HAVE_IPV6; mutually exclusive
423  * with APR_IPV4_ADDR_OK
424  * </PRE>
425  * @param p The pool for the apr_sockaddr_t and associated storage.
426  */
428  const char *hostname,
429  apr_int32_t family,
430  apr_port_t port,
431  apr_int32_t flags,
432  apr_pool_t *p);
433 
434 /**
435  * Copy apr_sockaddr_t src to dst on pool p.
436  * @param dst The destination apr_sockaddr_t.
437  * @param src The source apr_sockaddr_t.
438  * @param p The pool for the apr_sockaddr_t and associated storage.
439  */
441  const apr_sockaddr_t *src,
442  apr_pool_t *p);
443 
444 /**
445  * Set the zone of an IPv6 link-local address object.
446  * @param sa Socket address object
447  * @param zone_id Zone ID (textual "eth0" or numeric "3").
448  * @return Returns APR_EBADIP for non-IPv6 socket or an IPv6 address
449  * which isn't link-local.
450  */
452  const char *zone_id);
453 
454 
455 /**
456  * Retrieve the zone of an IPv6 link-local address object.
457  * @param sa Socket address object
458  * @param name If non-NULL, set to the textual representation of the zone id
459  * @param id If non-NULL, set to the integer zone id
460  * @param p Pool from which *name is allocated if used.
461  * @return Returns APR_EBADIP for non-IPv6 socket or socket without any zone id
462  * set, or other error if the interface could not be mapped to a name.
463  * @remark Both name and id may be NULL, neither are modified if
464  * non-NULL in error cases.
465  */
467  const char **name,
468  apr_uint32_t *id,
469  apr_pool_t *p);
470 
471 /**
472  * Look up the host name from an apr_sockaddr_t.
473  * @param hostname The hostname.
474  * @param sa The apr_sockaddr_t.
475  * @param flags Special processing flags.
476  * @remark Results can vary significantly between platforms
477  * when processing wildcard socket addresses.
478  */
480  apr_sockaddr_t *sa,
481  apr_int32_t flags);
482 
483 /**
484  * Parse hostname/IP address with scope id and port.
485  *
486  * Any of the following strings are accepted:
487  * 8080 (just the port number)
488  * www.apache.org (just the hostname)
489  * www.apache.org:8080 (hostname and port number)
490  * [fe80::1]:80 (IPv6 numeric address string only)
491  * [fe80::1%eth0] (IPv6 numeric address string and scope id)
492  *
493  * Invalid strings:
494  * (empty string)
495  * [abc] (not valid IPv6 numeric address string)
496  * abc:65536 (invalid port number)
497  *
498  * @param addr The new buffer containing just the hostname. On output, *addr
499  * will be NULL if no hostname/IP address was specfied.
500  * @param scope_id The new buffer containing just the scope id. On output,
501  * *scope_id will be NULL if no scope id was specified.
502  * @param port The port number. On output, *port will be 0 if no port was
503  * specified.
504  * ### FIXME: 0 is a legal port (per RFC 1700). this should
505  * ### return something besides zero if the port is missing.
506  * @param str The input string to be parsed.
507  * @param p The pool from which *addr and *scope_id are allocated.
508  * @remark If scope id shouldn't be allowed, check for scope_id != NULL in
509  * addition to checking the return code. If addr/hostname should be
510  * required, check for addr == NULL in addition to checking the
511  * return code.
512  */
514  char **scope_id,
515  apr_port_t *port,
516  const char *str,
517  apr_pool_t *p);
518 
519 /**
520  * Get name of the current machine
521  * @param buf A buffer to store the hostname in.
522  * @param len The maximum length of the hostname that can be stored in the
523  * buffer provided. The suggested length is APRMAXHOSTLEN + 1.
524  * @param cont The pool to use.
525  * @remark If the buffer was not large enough, an error will be returned.
526  */
528 
529 /**
530  * Return the data associated with the current socket
531  * @param data The user data associated with the socket.
532  * @param key The key to associate with the user data.
533  * @param sock The currently open socket.
534  */
535 APR_DECLARE(apr_status_t) apr_socket_data_get(void **data, const char *key,
536  apr_socket_t *sock);
537 
538 /**
539  * Set the data associated with the current socket.
540  * @param sock The currently open socket.
541  * @param data The user data to associate with the socket.
542  * @param key The key to associate with the data.
543  * @param cleanup The cleanup to call when the socket is destroyed.
544  */
546  const char *key,
547  apr_status_t (*cleanup)(void*));
548 
549 /**
550  * Send data over a network.
551  * @param sock The socket to send the data over.
552  * @param buf The buffer which contains the data to be sent.
553  * @param len On entry, the number of bytes to send; on exit, the number
554  * of bytes sent.
555  * @remark
556  * <PRE>
557  * This functions acts like a blocking write by default. To change
558  * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK
559  * socket option.
560  *
561  * It is possible for both bytes to be sent and an error to be returned.
562  *
563  * APR_EINTR is never returned.
564  * </PRE>
565  */
567  apr_size_t *len);
568 
569 /**
570  * Send multiple buffers over a network.
571  * @param sock The socket to send the data over.
572  * @param vec The array of iovec structs containing the data to send
573  * @param nvec The number of iovec structs in the array
574  * @param len Receives the number of bytes actually written
575  * @remark
576  * <PRE>
577  * This functions acts like a blocking write by default. To change
578  * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK
579  * socket option.
580  * The number of bytes actually sent is stored in argument 4.
581  *
582  * It is possible for both bytes to be sent and an error to be returned.
583  *
584  * APR_EINTR is never returned.
585  * </PRE>
586  */
588  const struct iovec *vec,
589  apr_int32_t nvec, apr_size_t *len);
590 
591 /**
592  * @param sock The socket to send from
593  * @param where The apr_sockaddr_t describing where to send the data
594  * @param flags The flags to use
595  * @param buf The data to send
596  * @param len The length of the data to send
597  */
599  apr_sockaddr_t *where,
600  apr_int32_t flags, const char *buf,
601  apr_size_t *len);
602 
603 /**
604  * Read data from a socket. On success, the address of the peer from
605  * which the data was sent is copied into the @a from parameter, and the
606  * @a len parameter is updated to give the number of bytes written to
607  * @a buf.
608  *
609  * @param from Updated with the address from which the data was received
610  * @param sock The socket to use
611  * @param flags The flags to use
612  * @param buf The buffer to use
613  * @param len The length of the available buffer
614  */
615 
617  apr_socket_t *sock,
618  apr_int32_t flags, char *buf,
619  apr_size_t *len);
620 
621 #if APR_HAS_SENDFILE || defined(DOXYGEN)
622 
623 /**
624  * Send a file from an open file descriptor to a socket, along with
625  * optional headers and trailers
626  * @param sock The socket to which we're writing
627  * @param file The open file from which to read
628  * @param hdtr A structure containing the headers and trailers to send
629  * @param offset Offset into the file where we should begin writing
630  * @param len (input) - Number of bytes to send from the file
631  * (output) - Number of bytes actually sent,
632  * including headers, file, and trailers
633  * @param flags APR flags that are mapped to OS specific flags
634  * @remark This functions acts like a blocking write by default. To change
635  * this behavior, use apr_socket_timeout_set() or the
636  * APR_SO_NONBLOCK socket option.
637  * The number of bytes actually sent is stored in the len parameter.
638  * The offset parameter is passed by reference for no reason; its
639  * value will never be modified by the apr_socket_sendfile() function.
640  */
642  apr_file_t *file,
643  apr_hdtr_t *hdtr,
644  apr_off_t *offset,
645  apr_size_t *len,
646  apr_int32_t flags);
647 
648 #endif /* APR_HAS_SENDFILE */
649 
650 /**
651  * Read data from a network.
652  * @param sock The socket to read the data from.
653  * @param buf The buffer to store the data in.
654  * @param len On entry, the number of bytes to receive; on exit, the number
655  * of bytes received.
656  * @remark
657  * <PRE>
658  * This functions acts like a blocking read by default. To change
659  * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK
660  * socket option.
661  * The number of bytes actually received is stored in argument 3.
662  *
663  * It is possible for both bytes to be received and an APR_EOF or
664  * other error to be returned.
665  *
666  * APR_EINTR is never returned.
667  * </PRE>
668  */
670  char *buf, apr_size_t *len);
671 
672 /**
673  * Setup socket options for the specified socket
674  * @param sock The socket to set up.
675  * @param opt The option we would like to configure. One of:
676  * <PRE>
677  * APR_SO_DEBUG -- turn on debugging information
678  * APR_SO_KEEPALIVE -- keep connections active
679  * APR_SO_LINGER -- lingers on close if data is present
680  * APR_SO_NONBLOCK -- Turns blocking on/off for socket
681  * When this option is enabled, use
682  * the APR_STATUS_IS_EAGAIN() macro to
683  * see if a send or receive function
684  * could not transfer data without
685  * blocking.
686  * APR_SO_REUSEADDR -- The rules used in validating addresses
687  * supplied to bind should allow reuse
688  * of local addresses.
689  * APR_SO_SNDBUF -- Set the SendBufferSize
690  * APR_SO_RCVBUF -- Set the ReceiveBufferSize
691  * APR_SO_FREEBIND -- Allow binding to non-local IP address.
692  * </PRE>
693  * @param on Value for the option.
694  */
696  apr_int32_t opt, apr_int32_t on);
697 
698 /**
699  * Setup socket timeout for the specified socket
700  * @param sock The socket to set up.
701  * @param t Value for the timeout.
702  * <PRE>
703  * t > 0 -- read and write calls return APR_TIMEUP if specified time
704  * elapsess with no data read or written
705  * t == 0 -- read and write calls never block
706  * t < 0 -- read and write calls block
707  * </PRE>
708  */
711 
712 /**
713  * Query socket options for the specified socket
714  * @param sock The socket to query
715  * @param opt The option we would like to query. One of:
716  * <PRE>
717  * APR_SO_DEBUG -- turn on debugging information
718  * APR_SO_KEEPALIVE -- keep connections active
719  * APR_SO_LINGER -- lingers on close if data is present
720  * APR_SO_NONBLOCK -- Turns blocking on/off for socket
721  * APR_SO_REUSEADDR -- The rules used in validating addresses
722  * supplied to bind should allow reuse
723  * of local addresses.
724  * APR_SO_SNDBUF -- Set the SendBufferSize
725  * APR_SO_RCVBUF -- Set the ReceiveBufferSize
726  * APR_SO_DISCONNECTED -- Query the disconnected state of the socket.
727  * (Currently only used on Windows)
728  * </PRE>
729  * @param on Socket option returned on the call.
730  */
732  apr_int32_t opt, apr_int32_t *on);
733 
734 /**
735  * Query socket timeout for the specified socket
736  * @param sock The socket to query
737  * @param t Socket timeout returned from the query.
738  */
741 
742 /**
743  * Query the specified socket if at the OOB/Urgent data mark
744  * @param sock The socket to query
745  * @param atmark Is set to true if socket is at the OOB/urgent mark,
746  * otherwise is set to false.
747  */
749  int *atmark);
750 
751 /**
752  * Return an address associated with a socket; either the address to
753  * which the socket is bound locally or the address of the peer
754  * to which the socket is connected.
755  * @param sa The returned apr_sockaddr_t.
756  * @param which Whether to retrieve the local or remote address
757  * @param sock The socket to use
758  */
760  apr_interface_e which,
761  apr_socket_t *sock);
762 
763 /**
764  * Return the IP address (in numeric address string format) in
765  * an APR socket address. APR will allocate storage for the IP address
766  * string from the pool of the apr_sockaddr_t.
767  * @param addr The IP address.
768  * @param sockaddr The socket address to reference.
769  */
771  apr_sockaddr_t *sockaddr);
772 
773 /**
774  * Write the IP address (in numeric address string format) of the APR
775  * socket address @a sockaddr into the buffer @a buf (of size @a buflen).
776  * @param sockaddr The socket address to reference.
777  */
778 APR_DECLARE(apr_status_t) apr_sockaddr_ip_getbuf(char *buf, apr_size_t buflen,
779  apr_sockaddr_t *sockaddr);
780 
781 /**
782  * See if the IP addresses in two APR socket addresses are
783  * equivalent. Appropriate logic is present for comparing
784  * IPv4-mapped IPv6 addresses with IPv4 addresses.
785  *
786  * @param addr1 One of the APR socket addresses.
787  * @param addr2 The other APR socket address.
788  * @remark The return value will be non-zero if the addresses
789  * are equivalent.
790  */
792  const apr_sockaddr_t *addr2);
793 
794 /**
795  * See if the IP address in an APR socket address refers to the wildcard
796  * address for the protocol family (e.g., INADDR_ANY for IPv4).
797  *
798  * @param addr The APR socket address to examine.
799  * @remark The return value will be non-zero if the address is
800  * initialized and is the wildcard address.
801  */
803 
804 /**
805 * Return the type of the socket.
806 * @param sock The socket to query.
807 * @param type The returned type (e.g., SOCK_STREAM).
808 */
810  int *type);
811 
812 /**
813  * Given an apr_sockaddr_t and a service name, set the port for the service
814  * @param sockaddr The apr_sockaddr_t that will have its port set
815  * @param servname The name of the service you wish to use
816  */
818  const char *servname);
819 /**
820  * Build an ip-subnet representation from an IP address and optional netmask or
821  * number-of-bits.
822  * @param ipsub The new ip-subnet representation
823  * @param ipstr The input IP address string
824  * @param mask_or_numbits The input netmask or number-of-bits string, or NULL
825  * @param p The pool to allocate from
826  */
828  const char *ipstr,
829  const char *mask_or_numbits,
830  apr_pool_t *p);
831 
832 /**
833  * Test the IP address in an apr_sockaddr_t against a pre-built ip-subnet
834  * representation.
835  * @param ipsub The ip-subnet representation
836  * @param sa The socket address to test
837  * @return non-zero if the socket address is within the subnet, 0 otherwise
838  */
840 
841 #if APR_HAS_SO_ACCEPTFILTER || defined(DOXYGEN)
842 /**
843  * Set an OS level accept filter.
844  * @param sock The socket to put the accept filter on.
845  * @param name The accept filter
846  * @param args Any extra args to the accept filter. Passing NULL here removes
847  * the accept filter.
848  * @bug name and args should have been declared as const char *, as they are in
849  * APR 2.0
850  */
852  char *args);
853 #endif
854 
855 /**
856  * Return the protocol of the socket.
857  * @param sock The socket to query.
858  * @param protocol The returned protocol (e.g., APR_PROTO_TCP).
859  */
861  int *protocol);
862 
863 /**
864  * Get the pool used by the socket.
865  */
867 
868 /**
869  * Set a socket to be inherited by child processes.
870  */
872 
873 /**
874  * Unset a socket from being inherited by child processes.
875  */
877 
878 /**
879  * Set socket permissions.
880  */
882 
883 /**
884  * @defgroup apr_mcast IP Multicast
885  * @{
886  */
887 
888 /**
889  * Join a Multicast Group
890  * @param sock The socket to join a multicast group
891  * @param join The address of the multicast group to join
892  * @param iface Address of the interface to use. If NULL is passed, the
893  * default multicast interface will be used. (OS Dependent)
894  * @param source Source Address to accept transmissions from (non-NULL
895  * implies Source-Specific Multicast)
896  */
898  apr_sockaddr_t *join,
899  apr_sockaddr_t *iface,
900  apr_sockaddr_t *source);
901 
902 /**
903  * Leave a Multicast Group. All arguments must be the same as
904  * apr_mcast_join.
905  * @param sock The socket to leave a multicast group
906  * @param addr The address of the multicast group to leave
907  * @param iface Address of the interface to use. If NULL is passed, the
908  * default multicast interface will be used. (OS Dependent)
909  * @param source Source Address to accept transmissions from (non-NULL
910  * implies Source-Specific Multicast)
911  */
913  apr_sockaddr_t *addr,
914  apr_sockaddr_t *iface,
915  apr_sockaddr_t *source);
916 
917 /**
918  * Set the Multicast Time to Live (ttl) for a multicast transmission.
919  * @param sock The socket to set the multicast ttl
920  * @param ttl Time to live to Assign. 0-255, default=1
921  * @remark If the TTL is 0, packets will only be seen by sockets on
922  * the local machine, and only when multicast loopback is enabled.
923  */
925  apr_byte_t ttl);
926 
927 /**
928  * Toggle IP Multicast Loopback
929  * @param sock The socket to set multicast loopback
930  * @param opt 0=disable, 1=enable
931  */
933  apr_byte_t opt);
934 
935 
936 /**
937  * Set the Interface to be used for outgoing Multicast Transmissions.
938  * @param sock The socket to set the multicast interface on
939  * @param iface Address of the interface to use for Multicast
940  */
942  apr_sockaddr_t *iface);
943 
944 /** @} */
945 
946 /** @} */
947 
948 #ifdef __cplusplus
949 }
950 #endif
951 
952 #endif /* ! APR_NETWORK_IO_H */
953 
APR Platform Definitions.
APR Error Codes.
APR File I/O Handling.
APR File Handle Inheritance Helpers.
#define APR_DECLARE_INHERIT_SET(type)
Definition: apr_inherit.h:35
#define APR_DECLARE_INHERIT_UNSET(type)
Definition: apr_inherit.h:47
APR Process Locking Routines.
APR memory allocation.
int apr_status_t
Definition: apr_errno.h:44
struct apr_file_t apr_file_t
Definition: apr_file_io.h:188
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_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(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_accept_filter(apr_socket_t *sock, char *name, char *args)
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)
struct apr_socket_t apr_socket_t
Definition: apr_network_io.h:219
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)
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)
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_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
#define APR_DECLARE(type)
Definition: apr.h:498
#define APR_POOL_DECLARE_ACCESSOR(type)
Definition: apr_pools.h:81
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
apr_int64_t apr_interval_time_t
Definition: apr_time.h:55
Definition: apr_network_io.h:293
struct iovec * trailers
Definition: apr_network_io.h:299
int numheaders
Definition: apr_network_io.h:297
int numtrailers
Definition: apr_network_io.h:301
struct iovec * headers
Definition: apr_network_io.h:295
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
union apr_sockaddr_t::@0 sa
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
apr_int32_t family
Definition: apr_network_io.h:249
apr_socklen_t salen
Definition: apr_network_io.h:251
Definition: apr_network_io.h:129
apr_uint32_t s_addr
Definition: apr_network_io.h:130