"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.17.5/lib/isc/include/isc/netaddr.h" (4 Sep 2020, 4721 Bytes) of package /linux/misc/dns/bind9/9.17.5/bind-9.17.5.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "netaddr.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 #ifndef ISC_NETADDR_H
   13 #define ISC_NETADDR_H 1
   14 
   15 /*! \file isc/netaddr.h */
   16 
   17 #include <inttypes.h>
   18 #include <stdbool.h>
   19 
   20 #include <isc/lang.h>
   21 #include <isc/net.h>
   22 #include <isc/types.h>
   23 
   24 #ifndef _WIN32
   25 #include <sys/types.h>
   26 #include <sys/un.h>
   27 #endif /* ifndef _WIN32 */
   28 
   29 ISC_LANG_BEGINDECLS
   30 
   31 struct isc_netaddr {
   32     unsigned int family;
   33     union {
   34         struct in_addr  in;
   35         struct in6_addr in6;
   36 #ifndef _WIN32
   37         char un[sizeof(((struct sockaddr_un *)0)->sun_path)];
   38 #endif /* ifndef _WIN32 */
   39     } type;
   40     uint32_t zone;
   41 };
   42 
   43 bool
   44 isc_netaddr_equal(const isc_netaddr_t *a, const isc_netaddr_t *b);
   45 
   46 /*%<
   47  * Compare network addresses 'a' and 'b'.  Return #true if
   48  * they are equal, #false if not.
   49  */
   50 
   51 bool
   52 isc_netaddr_eqprefix(const isc_netaddr_t *a, const isc_netaddr_t *b,
   53              unsigned int prefixlen);
   54 /*%<
   55  * Compare the 'prefixlen' most significant bits of the network
   56  * addresses 'a' and 'b'.  If 'b''s scope is zero then 'a''s scope is
   57  * ignored.  Return #true if they are equal, #false if not.
   58  */
   59 
   60 isc_result_t
   61 isc_netaddr_masktoprefixlen(const isc_netaddr_t *s, unsigned int *lenp);
   62 /*%<
   63  * Convert a netmask in 's' into a prefix length in '*lenp'.
   64  * The mask should consist of zero or more '1' bits in the
   65  * most significant part of the address, followed by '0' bits.
   66  * If this is not the case, #ISC_R_MASKNONCONTIG is returned.
   67  *
   68  * Returns:
   69  *\li   #ISC_R_SUCCESS
   70  *\li   #ISC_R_MASKNONCONTIG
   71  */
   72 
   73 isc_result_t
   74 isc_netaddr_totext(const isc_netaddr_t *netaddr, isc_buffer_t *target);
   75 /*%<
   76  * Append a text representation of 'sockaddr' to the buffer 'target'.
   77  * The text is NOT null terminated.  Handles IPv4 and IPv6 addresses.
   78  *
   79  * Returns:
   80  *\li   #ISC_R_SUCCESS
   81  *\li   #ISC_R_NOSPACE  The text or the null termination did not fit.
   82  *\li   #ISC_R_FAILURE  Unspecified failure
   83  */
   84 
   85 void
   86 isc_netaddr_format(const isc_netaddr_t *na, char *array, unsigned int size);
   87 /*%<
   88  * Format a human-readable representation of the network address '*na'
   89  * into the character array 'array', which is of size 'size'.
   90  * The resulting string is guaranteed to be null-terminated.
   91  */
   92 
   93 #define ISC_NETADDR_FORMATSIZE \
   94     sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX%SSSSSSSSSS")
   95 /*%<
   96  * Minimum size of array to pass to isc_netaddr_format().
   97  */
   98 
   99 void
  100 isc_netaddr_fromsockaddr(isc_netaddr_t *netaddr, const isc_sockaddr_t *source);
  101 
  102 void
  103 isc_netaddr_fromin(isc_netaddr_t *netaddr, const struct in_addr *ina);
  104 
  105 void
  106 isc_netaddr_fromin6(isc_netaddr_t *netaddr, const struct in6_addr *ina6);
  107 
  108 isc_result_t
  109 isc_netaddr_frompath(isc_netaddr_t *netaddr, const char *path);
  110 
  111 void
  112 isc_netaddr_setzone(isc_netaddr_t *netaddr, uint32_t zone);
  113 
  114 uint32_t
  115 isc_netaddr_getzone(const isc_netaddr_t *netaddr);
  116 
  117 void
  118 isc_netaddr_any(isc_netaddr_t *netaddr);
  119 /*%<
  120  * Return the IPv4 wildcard address.
  121  */
  122 
  123 void
  124 isc_netaddr_any6(isc_netaddr_t *netaddr);
  125 /*%<
  126  * Return the IPv6 wildcard address.
  127  */
  128 
  129 void
  130 isc_netaddr_unspec(isc_netaddr_t *netaddr);
  131 /*%<
  132  * Initialize as AF_UNSPEC address.
  133  */
  134 
  135 bool
  136 isc_netaddr_ismulticast(const isc_netaddr_t *na);
  137 /*%<
  138  * Returns true if the address is a multicast address.
  139  */
  140 
  141 bool
  142 isc_netaddr_isexperimental(const isc_netaddr_t *na);
  143 /*%<
  144  * Returns true if the address is a experimental (CLASS E) address.
  145  */
  146 
  147 bool
  148 isc_netaddr_islinklocal(const isc_netaddr_t *na);
  149 /*%<
  150  * Returns #true if the address is a link local address.
  151  */
  152 
  153 bool
  154 isc_netaddr_issitelocal(const isc_netaddr_t *na);
  155 /*%<
  156  * Returns #true if the address is a site local address.
  157  */
  158 
  159 bool
  160 isc_netaddr_isnetzero(const isc_netaddr_t *na);
  161 /*%<
  162  * Returns #true if the address is in net zero.
  163  */
  164 
  165 void
  166 isc_netaddr_fromv4mapped(isc_netaddr_t *t, const isc_netaddr_t *s);
  167 /*%<
  168  * Convert an IPv6 v4mapped address into an IPv4 address.
  169  */
  170 
  171 isc_result_t
  172 isc_netaddr_prefixok(const isc_netaddr_t *na, unsigned int prefixlen);
  173 /*
  174  * Test whether the netaddr 'na' and 'prefixlen' are consistent.
  175  * e.g. prefixlen within range.
  176  *      na does not have bits set which are not covered by the prefixlen.
  177  *
  178  * Returns:
  179  *  ISC_R_SUCCESS
  180  *  ISC_R_RANGE     prefixlen out of range
  181  *  ISC_R_NOTIMPLEMENTED    unsupported family
  182  *  ISC_R_FAILURE       extra bits.
  183  */
  184 
  185 bool
  186 isc_netaddr_isloopback(const isc_netaddr_t *na);
  187 /*
  188  * Test whether the netaddr 'na' is a loopback IPv4 or IPv6 address (in
  189  * 127.0.0.0/8 or ::1).
  190  */
  191 ISC_LANG_ENDDECLS
  192 
  193 #endif /* ISC_NETADDR_H */