netaddr.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2007, 2009  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1998-2002  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: netaddr.h,v 1.37 2009/01/17 23:47:43 tbox Exp $ */
00019 
00020 #ifndef ISC_NETADDR_H
00021 #define ISC_NETADDR_H 1
00022 
00023 /*! \file isc/netaddr.h */
00024 
00025 #include <isc/lang.h>
00026 #include <isc/net.h>
00027 #include <isc/types.h>
00028 
00029 #ifdef ISC_PLATFORM_HAVESYSUNH
00030 #include <sys/types.h>
00031 #include <sys/un.h>
00032 #endif
00033 
00034 ISC_LANG_BEGINDECLS
00035 
00036 struct isc_netaddr {
00037         unsigned int family;
00038         union {
00039                 struct in_addr in;
00040                 struct in6_addr in6;
00041 #ifdef ISC_PLATFORM_HAVESYSUNH
00042                 char un[sizeof(((struct sockaddr_un *)0)->sun_path)];
00043 #endif
00044         } type;
00045         isc_uint32_t zone;
00046 };
00047 
00048 isc_boolean_t
00049 isc_netaddr_equal(const isc_netaddr_t *a, const isc_netaddr_t *b);
00050 
00051 /*%<
00052  * Compare network addresses 'a' and 'b'.  Return #ISC_TRUE if
00053  * they are equal, #ISC_FALSE if not.
00054  */
00055 
00056 isc_boolean_t
00057 isc_netaddr_eqprefix(const isc_netaddr_t *a, const isc_netaddr_t *b,
00058                      unsigned int prefixlen);
00059 /*%<
00060  * Compare the 'prefixlen' most significant bits of the network
00061  * addresses 'a' and 'b'.  If 'b''s scope is zero then 'a''s scope is
00062  * ignored.  Return #ISC_TRUE if they are equal, #ISC_FALSE if not.
00063  */
00064 
00065 isc_result_t
00066 isc_netaddr_masktoprefixlen(const isc_netaddr_t *s, unsigned int *lenp);
00067 /*%<
00068  * Convert a netmask in 's' into a prefix length in '*lenp'.
00069  * The mask should consist of zero or more '1' bits in the most
00070  * most significant part of the address, followed by '0' bits.
00071  * If this is not the case, #ISC_R_MASKNONCONTIG is returned.
00072  *
00073  * Returns:
00074  *\li   #ISC_R_SUCCESS
00075  *\li   #ISC_R_MASKNONCONTIG
00076  */
00077 
00078 isc_result_t
00079 isc_netaddr_totext(const isc_netaddr_t *netaddr, isc_buffer_t *target);
00080 /*%<
00081  * Append a text representation of 'sockaddr' to the buffer 'target'.
00082  * The text is NOT null terminated.  Handles IPv4 and IPv6 addresses.
00083  *
00084  * Returns:
00085  *\li   #ISC_R_SUCCESS
00086  *\li   #ISC_R_NOSPACE  The text or the null termination did not fit.
00087  *\li   #ISC_R_FAILURE  Unspecified failure
00088  */
00089 
00090 void
00091 isc_netaddr_format(const isc_netaddr_t *na, char *array, unsigned int size);
00092 /*%<
00093  * Format a human-readable representation of the network address '*na'
00094  * into the character array 'array', which is of size 'size'.
00095  * The resulting string is guaranteed to be null-terminated.
00096  */
00097 
00098 #define ISC_NETADDR_FORMATSIZE \
00099         sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX%SSSSSSSSSS")
00100 /*%<
00101  * Minimum size of array to pass to isc_netaddr_format().
00102  */
00103 
00104 void
00105 isc_netaddr_fromsockaddr(isc_netaddr_t *netaddr, const isc_sockaddr_t *source);
00106 
00107 void
00108 isc_netaddr_fromin(isc_netaddr_t *netaddr, const struct in_addr *ina);
00109 
00110 void
00111 isc_netaddr_fromin6(isc_netaddr_t *netaddr, const struct in6_addr *ina6);
00112 
00113 isc_result_t
00114 isc_netaddr_frompath(isc_netaddr_t *netaddr, const char *path);
00115 
00116 void
00117 isc_netaddr_setzone(isc_netaddr_t *netaddr, isc_uint32_t zone);
00118 
00119 isc_uint32_t
00120 isc_netaddr_getzone(const isc_netaddr_t *netaddr);
00121 
00122 void
00123 isc_netaddr_any(isc_netaddr_t *netaddr);
00124 /*%<
00125  * Return the IPv4 wildcard address.
00126  */
00127 
00128 void
00129 isc_netaddr_any6(isc_netaddr_t *netaddr);
00130 /*%<
00131  * Return the IPv6 wildcard address.
00132  */
00133 
00134 isc_boolean_t
00135 isc_netaddr_ismulticast(isc_netaddr_t *na);
00136 /*%<
00137  * Returns ISC_TRUE if the address is a multicast address.
00138  */
00139 
00140 isc_boolean_t
00141 isc_netaddr_isexperimental(isc_netaddr_t *na);
00142 /*%<
00143  * Returns ISC_TRUE if the address is a experimental (CLASS E) address.
00144  */
00145 
00146 isc_boolean_t
00147 isc_netaddr_islinklocal(isc_netaddr_t *na);
00148 /*%<
00149  * Returns #ISC_TRUE if the address is a link local address.
00150  */
00151 
00152 isc_boolean_t
00153 isc_netaddr_issitelocal(isc_netaddr_t *na);
00154 /*%<
00155  * Returns #ISC_TRUE if the address is a site local address.
00156  */
00157 
00158 void
00159 isc_netaddr_fromv4mapped(isc_netaddr_t *t, const isc_netaddr_t *s);
00160 /*%<
00161  * Convert an IPv6 v4mapped address into an IPv4 address.
00162  */
00163 
00164 isc_result_t
00165 isc_netaddr_prefixok(const isc_netaddr_t *na, unsigned int prefixlen);
00166 /*
00167  * Test whether the netaddr 'na' and 'prefixlen' are consistant.
00168  * e.g. prefixlen within range.
00169  *      na does not have bits set which are not covered by the prefixlen.
00170  *
00171  * Returns:
00172  *      ISC_R_SUCCESS
00173  *      ISC_R_RANGE             prefixlen out of range
00174  *      ISC_R_NOTIMPLEMENTED    unsupported family
00175  *      ISC_R_FAILURE           extra bits.
00176  */
00177 
00178 ISC_LANG_ENDDECLS
00179 
00180 #endif /* ISC_NETADDR_H */

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