"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.17.5/lib/isc/include/isc/sockaddr.h" (4 Sep 2020, 6210 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 "sockaddr.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_SOCKADDR_H
   13 #define ISC_SOCKADDR_H 1
   14 
   15 /*! \file isc/sockaddr.h */
   16 
   17 #include <stdbool.h>
   18 
   19 #include <isc/lang.h>
   20 #include <isc/net.h>
   21 #include <isc/types.h>
   22 #ifndef _WIN32
   23 #include <sys/un.h>
   24 #endif /* ifndef _WIN32 */
   25 
   26 struct isc_sockaddr {
   27     union {
   28         struct sockaddr     sa;
   29         struct sockaddr_in  sin;
   30         struct sockaddr_in6 sin6;
   31         struct sockaddr_storage ss;
   32 #ifndef _WIN32
   33         struct sockaddr_un sunix;
   34 #endif /* ifndef _WIN32 */
   35     } type;
   36     unsigned int length; /* XXXRTH beginning? */
   37     ISC_LINK(struct isc_sockaddr) link;
   38 };
   39 
   40 #define ISC_SOCKADDR_CMPADDR            \
   41     0x0001 /*%< compare the address \
   42         *   sin_addr/sin6_addr */
   43 #define ISC_SOCKADDR_CMPPORT         \
   44     0x0002 /*%< compare the port \
   45         *   sin_port/sin6_port */
   46 #define ISC_SOCKADDR_CMPSCOPE         \
   47     0x0004 /*%< compare the scope \
   48         *   sin6_scope */
   49 #define ISC_SOCKADDR_CMPSCOPEZERO         \
   50     0x0008 /*%< when comparing scopes \
   51         *   zero scopes always match */
   52 
   53 ISC_LANG_BEGINDECLS
   54 
   55 bool
   56 isc_sockaddr_compare(const isc_sockaddr_t *a, const isc_sockaddr_t *b,
   57              unsigned int flags);
   58 /*%<
   59  * Compare the elements of the two address ('a' and 'b') as specified
   60  * by 'flags' and report if they are equal or not.
   61  *
   62  * 'flags' is set from ISC_SOCKADDR_CMP*.
   63  */
   64 
   65 bool
   66 isc_sockaddr_equal(const isc_sockaddr_t *a, const isc_sockaddr_t *b);
   67 /*%<
   68  * Return true iff the socket addresses 'a' and 'b' are equal.
   69  */
   70 
   71 bool
   72 isc_sockaddr_eqaddr(const isc_sockaddr_t *a, const isc_sockaddr_t *b);
   73 /*%<
   74  * Return true iff the address parts of the socket addresses
   75  * 'a' and 'b' are equal, ignoring the ports.
   76  */
   77 
   78 bool
   79 isc_sockaddr_eqaddrprefix(const isc_sockaddr_t *a, const isc_sockaddr_t *b,
   80               unsigned int prefixlen);
   81 /*%<
   82  * Return true iff the most significant 'prefixlen' bits of the
   83  * socket addresses 'a' and 'b' are equal, ignoring the ports.
   84  * If 'b''s scope is zero then 'a''s scope will be ignored.
   85  */
   86 
   87 unsigned int
   88 isc_sockaddr_hash(const isc_sockaddr_t *sockaddr, bool address_only);
   89 /*%<
   90  * Return a hash value for the socket address 'sockaddr'.  If 'address_only'
   91  * is true, the hash value will not depend on the port.
   92  *
   93  * IPv6 addresses containing mapped IPv4 addresses generate the same hash
   94  * value as the equivalent IPv4 address.
   95  */
   96 
   97 void
   98 isc_sockaddr_any(isc_sockaddr_t *sockaddr);
   99 /*%<
  100  * Return the IPv4 wildcard address.
  101  */
  102 
  103 void
  104 isc_sockaddr_any6(isc_sockaddr_t *sockaddr);
  105 /*%<
  106  * Return the IPv6 wildcard address.
  107  */
  108 
  109 void
  110 isc_sockaddr_anyofpf(isc_sockaddr_t *sockaddr, int family);
  111 /*%<
  112  * Set '*sockaddr' to the wildcard address of protocol family
  113  * 'family'.
  114  *
  115  * Requires:
  116  * \li  'family' is AF_INET or AF_INET6.
  117  */
  118 
  119 void
  120 isc_sockaddr_fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina,
  121             in_port_t port);
  122 /*%<
  123  * Construct an isc_sockaddr_t from an IPv4 address and port.
  124  */
  125 
  126 void
  127 isc_sockaddr_fromin6(isc_sockaddr_t *sockaddr, const struct in6_addr *ina6,
  128              in_port_t port);
  129 /*%<
  130  * Construct an isc_sockaddr_t from an IPv6 address and port.
  131  */
  132 
  133 void
  134 isc_sockaddr_v6fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina,
  135               in_port_t port);
  136 /*%<
  137  * Construct an IPv6 isc_sockaddr_t representing a mapped IPv4 address.
  138  */
  139 
  140 void
  141 isc_sockaddr_fromnetaddr(isc_sockaddr_t *sockaddr, const isc_netaddr_t *na,
  142              in_port_t port);
  143 /*%<
  144  * Construct an isc_sockaddr_t from an isc_netaddr_t and port.
  145  */
  146 
  147 int
  148 isc_sockaddr_pf(const isc_sockaddr_t *sockaddr);
  149 /*%<
  150  * Get the protocol family of 'sockaddr'.
  151  *
  152  * Requires:
  153  *
  154  *\li   'sockaddr' is a valid sockaddr with an address family of AF_INET
  155  *  or AF_INET6.
  156  *
  157  * Returns:
  158  *
  159  *\li   The protocol family of 'sockaddr', e.g. PF_INET or PF_INET6.
  160  */
  161 
  162 void
  163 isc_sockaddr_setport(isc_sockaddr_t *sockaddr, in_port_t port);
  164 /*%<
  165  * Set the port of 'sockaddr' to 'port'.
  166  */
  167 
  168 in_port_t
  169 isc_sockaddr_getport(const isc_sockaddr_t *sockaddr);
  170 /*%<
  171  * Get the port stored in 'sockaddr'.
  172  */
  173 
  174 isc_result_t
  175 isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target);
  176 /*%<
  177  * Append a text representation of 'sockaddr' to the buffer 'target'.
  178  * The text will include both the IP address (v4 or v6) and the port.
  179  * The text is null terminated, but the terminating null is not
  180  * part of the buffer's used region.
  181  *
  182  * Returns:
  183  * \li  ISC_R_SUCCESS
  184  * \li  ISC_R_NOSPACE   The text or the null termination did not fit.
  185  */
  186 
  187 void
  188 isc_sockaddr_format(const isc_sockaddr_t *sa, char *array, unsigned int size);
  189 /*%<
  190  * Format a human-readable representation of the socket address '*sa'
  191  * into the character array 'array', which is of size 'size'.
  192  * The resulting string is guaranteed to be null-terminated.
  193  */
  194 
  195 bool
  196 isc_sockaddr_ismulticast(const isc_sockaddr_t *sa);
  197 /*%<
  198  * Returns #true if the address is a multicast address.
  199  */
  200 
  201 bool
  202 isc_sockaddr_isexperimental(const isc_sockaddr_t *sa);
  203 /*
  204  * Returns true if the address is a experimental (CLASS E) address.
  205  */
  206 
  207 bool
  208 isc_sockaddr_islinklocal(const isc_sockaddr_t *sa);
  209 /*%<
  210  * Returns true if the address is a link local address.
  211  */
  212 
  213 bool
  214 isc_sockaddr_issitelocal(const isc_sockaddr_t *sa);
  215 /*%<
  216  * Returns true if the address is a sitelocal address.
  217  */
  218 
  219 bool
  220 isc_sockaddr_isnetzero(const isc_sockaddr_t *sa);
  221 /*%<
  222  * Returns true if the address is in net zero.
  223  */
  224 
  225 isc_result_t
  226 isc_sockaddr_frompath(isc_sockaddr_t *sockaddr, const char *path);
  227 /*
  228  *  Create a UNIX domain sockaddr that refers to path.
  229  *
  230  * Returns:
  231  * \li  ISC_R_NOSPACE
  232  * \li  ISC_R_NOTIMPLEMENTED
  233  * \li  ISC_R_SUCCESS
  234  */
  235 
  236 isc_result_t
  237 isc_sockaddr_fromsockaddr(isc_sockaddr_t *isa, const struct sockaddr *sa);
  238 
  239 #define ISC_SOCKADDR_FORMATSIZE                                            \
  240     sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX%SSSSSSSSSS#" \
  241            "YYYYY")
  242 /*%<
  243  * Minimum size of array to pass to isc_sockaddr_format().
  244  */
  245 
  246 ISC_LANG_ENDDECLS
  247 
  248 #endif /* ISC_SOCKADDR_H */