sockaddr.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2007, 2009, 2012  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1998-2003  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: sockaddr.h,v 1.57 2009/01/18 23:48:14 tbox Exp $ */
00019 
00020 #ifndef ISC_SOCKADDR_H
00021 #define ISC_SOCKADDR_H 1
00022 
00023 /*! \file isc/sockaddr.h */
00024 
00025 #include <isc/lang.h>
00026 #include <isc/net.h>
00027 #include <isc/types.h>
00028 #ifdef ISC_PLATFORM_HAVESYSUNH
00029 #include <sys/un.h>
00030 #endif
00031 
00032 struct isc_sockaddr {
00033         union {
00034                 struct sockaddr         sa;
00035                 struct sockaddr_in      sin;
00036                 struct sockaddr_in6     sin6;
00037                 struct sockaddr_storage ss;
00038 #ifdef ISC_PLATFORM_HAVESYSUNH
00039                 struct sockaddr_un      sunix;
00040 #endif
00041         }                               type;
00042         unsigned int                    length;         /* XXXRTH beginning? */
00043         ISC_LINK(struct isc_sockaddr)   link;
00044 };
00045 
00046 typedef ISC_LIST(struct isc_sockaddr)   isc_sockaddrlist_t;
00047 
00048 #define ISC_SOCKADDR_CMPADDR      0x0001        /*%< compare the address
00049                                                  *   sin_addr/sin6_addr */
00050 #define ISC_SOCKADDR_CMPPORT      0x0002        /*%< compare the port
00051                                                  *   sin_port/sin6_port */
00052 #define ISC_SOCKADDR_CMPSCOPE     0x0004        /*%< compare the scope
00053                                                  *   sin6_scope */
00054 #define ISC_SOCKADDR_CMPSCOPEZERO 0x0008        /*%< when comparing scopes
00055                                                  *   zero scopes always match */
00056 
00057 ISC_LANG_BEGINDECLS
00058 
00059 isc_boolean_t
00060 isc_sockaddr_compare(const isc_sockaddr_t *a, const isc_sockaddr_t *b,
00061                      unsigned int flags);
00062 /*%<
00063  * Compare the elements of the two address ('a' and 'b') as specified
00064  * by 'flags' and report if they are equal or not.
00065  *
00066  * 'flags' is set from ISC_SOCKADDR_CMP*.
00067  */
00068 
00069 isc_boolean_t
00070 isc_sockaddr_equal(const isc_sockaddr_t *a, const isc_sockaddr_t *b);
00071 /*%<
00072  * Return ISC_TRUE iff the socket addresses 'a' and 'b' are equal.
00073  */
00074 
00075 isc_boolean_t
00076 isc_sockaddr_eqaddr(const isc_sockaddr_t *a, const isc_sockaddr_t *b);
00077 /*%<
00078  * Return ISC_TRUE iff the address parts of the socket addresses
00079  * 'a' and 'b' are equal, ignoring the ports.
00080  */
00081 
00082 isc_boolean_t
00083 isc_sockaddr_eqaddrprefix(const isc_sockaddr_t *a, const isc_sockaddr_t *b,
00084                           unsigned int prefixlen);
00085 /*%<
00086  * Return ISC_TRUE iff the most significant 'prefixlen' bits of the
00087  * socket addresses 'a' and 'b' are equal, ignoring the ports.
00088  * If 'b''s scope is zero then 'a''s scope will be ignored.
00089  */
00090 
00091 unsigned int
00092 isc_sockaddr_hash(const isc_sockaddr_t *sockaddr, isc_boolean_t address_only);
00093 /*%<
00094  * Return a hash value for the socket address 'sockaddr'.  If 'address_only'
00095  * is ISC_TRUE, the hash value will not depend on the port.
00096  *
00097  * IPv6 addresses containing mapped IPv4 addresses generate the same hash
00098  * value as the equivalent IPv4 address.
00099  */
00100 
00101 void
00102 isc_sockaddr_any(isc_sockaddr_t *sockaddr);
00103 /*%<
00104  * Return the IPv4 wildcard address.
00105  */
00106 
00107 void
00108 isc_sockaddr_any6(isc_sockaddr_t *sockaddr);
00109 /*%<
00110  * Return the IPv6 wildcard address.
00111  */
00112 
00113 void
00114 isc_sockaddr_anyofpf(isc_sockaddr_t *sockaddr, int family);
00115 /*%<
00116  * Set '*sockaddr' to the wildcard address of protocol family
00117  * 'family'.
00118  *
00119  * Requires:
00120  * \li  'family' is AF_INET or AF_INET6.
00121  */
00122 
00123 void
00124 isc_sockaddr_fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina,
00125                     in_port_t port);
00126 /*%<
00127  * Construct an isc_sockaddr_t from an IPv4 address and port.
00128  */
00129 
00130 void
00131 isc_sockaddr_fromin6(isc_sockaddr_t *sockaddr, const struct in6_addr *ina6,
00132                      in_port_t port);
00133 /*%<
00134  * Construct an isc_sockaddr_t from an IPv6 address and port.
00135  */
00136 
00137 void
00138 isc_sockaddr_v6fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina,
00139                       in_port_t port);
00140 /*%<
00141  * Construct an IPv6 isc_sockaddr_t representing a mapped IPv4 address.
00142  */
00143 
00144 void
00145 isc_sockaddr_fromnetaddr(isc_sockaddr_t *sockaddr, const isc_netaddr_t *na,
00146                          in_port_t port);
00147 /*%<
00148  * Construct an isc_sockaddr_t from an isc_netaddr_t and port.
00149  */
00150 
00151 int
00152 isc_sockaddr_pf(const isc_sockaddr_t *sockaddr);
00153 /*%<
00154  * Get the protocol family of 'sockaddr'.
00155  *
00156  * Requires:
00157  *
00158  *\li   'sockaddr' is a valid sockaddr with an address family of AF_INET
00159  *      or AF_INET6.
00160  *
00161  * Returns:
00162  *
00163  *\li   The protocol family of 'sockaddr', e.g. PF_INET or PF_INET6.
00164  */
00165 
00166 void
00167 isc_sockaddr_setport(isc_sockaddr_t *sockaddr, in_port_t port);
00168 /*%<
00169  * Set the port of 'sockaddr' to 'port'.
00170  */
00171 
00172 in_port_t
00173 isc_sockaddr_getport(const isc_sockaddr_t *sockaddr);
00174 /*%<
00175  * Get the port stored in 'sockaddr'.
00176  */
00177 
00178 isc_result_t
00179 isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target);
00180 /*%<
00181  * Append a text representation of 'sockaddr' to the buffer 'target'.
00182  * The text will include both the IP address (v4 or v6) and the port.
00183  * The text is null terminated, but the terminating null is not
00184  * part of the buffer's used region.
00185  *
00186  * Returns:
00187  * \li  ISC_R_SUCCESS
00188  * \li  ISC_R_NOSPACE   The text or the null termination did not fit.
00189  */
00190 
00191 void
00192 isc_sockaddr_format(const isc_sockaddr_t *sa, char *array, unsigned int size);
00193 /*%<
00194  * Format a human-readable representation of the socket address '*sa'
00195  * into the character array 'array', which is of size 'size'.
00196  * The resulting string is guaranteed to be null-terminated.
00197  */
00198 
00199 isc_boolean_t
00200 isc_sockaddr_ismulticast(const isc_sockaddr_t *sa);
00201 /*%<
00202  * Returns #ISC_TRUE if the address is a multicast address.
00203  */
00204 
00205 isc_boolean_t
00206 isc_sockaddr_isexperimental(const isc_sockaddr_t *sa);
00207 /*
00208  * Returns ISC_TRUE if the address is a experimental (CLASS E) address.
00209  */
00210 
00211 isc_boolean_t
00212 isc_sockaddr_islinklocal(const isc_sockaddr_t *sa);
00213 /*%<
00214  * Returns ISC_TRUE if the address is a link local address.
00215  */
00216 
00217 isc_boolean_t
00218 isc_sockaddr_issitelocal(const isc_sockaddr_t *sa);
00219 /*%<
00220  * Returns ISC_TRUE if the address is a sitelocal address.
00221  */
00222 
00223 isc_result_t
00224 isc_sockaddr_frompath(isc_sockaddr_t *sockaddr, const char *path);
00225 /*
00226  *  Create a UNIX domain sockaddr that refers to path.
00227  *
00228  * Returns:
00229  * \li  ISC_R_NOSPACE
00230  * \li  ISC_R_NOTIMPLEMENTED
00231  * \li  ISC_R_SUCCESS
00232  */
00233 
00234 #define ISC_SOCKADDR_FORMATSIZE \
00235         sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX%SSSSSSSSSS#YYYYY")
00236 /*%<
00237  * Minimum size of array to pass to isc_sockaddr_format().
00238  */
00239 
00240 ISC_LANG_ENDDECLS
00241 
00242 #endif /* ISC_SOCKADDR_H */

Generated on Tue Apr 28 17:41:04 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha