Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:00

0001 //
0002 // ip/network_v6.hpp
0003 // ~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 // Copyright (c) 2014 Oliver Kowalke (oliver dot kowalke at gmail dot com)
0007 //
0008 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0009 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0010 //
0011 
0012 #ifndef BOOST_ASIO_IP_NETWORK_V6_HPP
0013 #define BOOST_ASIO_IP_NETWORK_V6_HPP
0014 
0015 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0016 # pragma once
0017 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0018 
0019 #include <boost/asio/detail/config.hpp>
0020 #include <string>
0021 #include <boost/asio/detail/string_view.hpp>
0022 #include <boost/system/error_code.hpp>
0023 #include <boost/asio/ip/address_v6_range.hpp>
0024 
0025 #include <boost/asio/detail/push_options.hpp>
0026 
0027 namespace boost {
0028 namespace asio {
0029 namespace ip {
0030 
0031 /// Represents an IPv6 network.
0032 /**
0033  * The boost::asio::ip::network_v6 class provides the ability to use and
0034  * manipulate IP version 6 networks.
0035  *
0036  * @par Thread Safety
0037  * @e Distinct @e objects: Safe.@n
0038  * @e Shared @e objects: Unsafe.
0039  */
0040 class network_v6
0041 {
0042 public:
0043   /// Default constructor.
0044   network_v6() noexcept
0045     : address_(),
0046       prefix_length_(0)
0047   {
0048   }
0049 
0050   /// Construct a network based on the specified address and prefix length.
0051   BOOST_ASIO_DECL network_v6(const address_v6& addr,
0052       unsigned short prefix_len);
0053 
0054   /// Copy constructor.
0055   network_v6(const network_v6& other) noexcept
0056     : address_(other.address_),
0057       prefix_length_(other.prefix_length_)
0058   {
0059   }
0060 
0061   /// Move constructor.
0062   network_v6(network_v6&& other) noexcept
0063     : address_(static_cast<address_v6&&>(other.address_)),
0064       prefix_length_(other.prefix_length_)
0065   {
0066   }
0067 
0068   /// Assign from another network.
0069   network_v6& operator=(const network_v6& other) noexcept
0070   {
0071     address_ = other.address_;
0072     prefix_length_ = other.prefix_length_;
0073     return *this;
0074   }
0075 
0076   /// Move-assign from another network.
0077   network_v6& operator=(network_v6&& other) noexcept
0078   {
0079     address_ = static_cast<address_v6&&>(other.address_);
0080     prefix_length_ = other.prefix_length_;
0081     return *this;
0082   }
0083 
0084   /// Obtain the address object specified when the network object was created.
0085   address_v6 address() const noexcept
0086   {
0087     return address_;
0088   }
0089 
0090   /// Obtain the prefix length that was specified when the network object was
0091   /// created.
0092   unsigned short prefix_length() const noexcept
0093   {
0094     return prefix_length_;
0095   }
0096 
0097   /// Obtain an address object that represents the network address.
0098   BOOST_ASIO_DECL address_v6 network() const noexcept;
0099 
0100   /// Obtain an address range corresponding to the hosts in the network.
0101   BOOST_ASIO_DECL address_v6_range hosts() const noexcept;
0102 
0103   /// Obtain the true network address, omitting any host bits.
0104   network_v6 canonical() const noexcept
0105   {
0106     return network_v6(network(), prefix_length());
0107   }
0108 
0109   /// Test if network is a valid host address.
0110   bool is_host() const noexcept
0111   {
0112     return prefix_length_ == 128;
0113   }
0114 
0115   /// Test if a network is a real subnet of another network.
0116   BOOST_ASIO_DECL bool is_subnet_of(const network_v6& other) const;
0117 
0118   /// Get the network as an address in dotted decimal format.
0119   BOOST_ASIO_DECL std::string to_string() const;
0120 
0121   /// Get the network as an address in dotted decimal format.
0122   BOOST_ASIO_DECL std::string to_string(boost::system::error_code& ec) const;
0123 
0124   /// Compare two networks for equality.
0125   friend bool operator==(const network_v6& a, const network_v6& b)
0126   {
0127     return a.address_ == b.address_ && a.prefix_length_ == b.prefix_length_;
0128   }
0129 
0130   /// Compare two networks for inequality.
0131   friend bool operator!=(const network_v6& a, const network_v6& b)
0132   {
0133     return !(a == b);
0134   }
0135 
0136 private:
0137   address_v6 address_;
0138   unsigned short prefix_length_;
0139 };
0140 
0141 /// Create an IPv6 network from an address and prefix length.
0142 /**
0143  * @relates address_v6
0144  */
0145 inline network_v6 make_network_v6(
0146     const address_v6& addr, unsigned short prefix_len)
0147 {
0148   return network_v6(addr, prefix_len);
0149 }
0150 
0151 /// Create an IPv6 network from a string containing IP address and prefix
0152 /// length.
0153 /**
0154  * @relates network_v6
0155  */
0156 BOOST_ASIO_DECL network_v6 make_network_v6(const char* str);
0157 
0158 /// Create an IPv6 network from a string containing IP address and prefix
0159 /// length.
0160 /**
0161  * @relates network_v6
0162  */
0163 BOOST_ASIO_DECL network_v6 make_network_v6(
0164     const char* str, boost::system::error_code& ec);
0165 
0166 /// Create an IPv6 network from a string containing IP address and prefix
0167 /// length.
0168 /**
0169  * @relates network_v6
0170  */
0171 BOOST_ASIO_DECL network_v6 make_network_v6(const std::string& str);
0172 
0173 /// Create an IPv6 network from a string containing IP address and prefix
0174 /// length.
0175 /**
0176  * @relates network_v6
0177  */
0178 BOOST_ASIO_DECL network_v6 make_network_v6(
0179     const std::string& str, boost::system::error_code& ec);
0180 
0181 #if defined(BOOST_ASIO_HAS_STRING_VIEW) \
0182   || defined(GENERATING_DOCUMENTATION)
0183 
0184 /// Create an IPv6 network from a string containing IP address and prefix
0185 /// length.
0186 /**
0187  * @relates network_v6
0188  */
0189 BOOST_ASIO_DECL network_v6 make_network_v6(string_view str);
0190 
0191 /// Create an IPv6 network from a string containing IP address and prefix
0192 /// length.
0193 /**
0194  * @relates network_v6
0195  */
0196 BOOST_ASIO_DECL network_v6 make_network_v6(
0197     string_view str, boost::system::error_code& ec);
0198 
0199 #endif // defined(BOOST_ASIO_HAS_STRING_VIEW)
0200        //  || defined(GENERATING_DOCUMENTATION)
0201 
0202 #if !defined(BOOST_ASIO_NO_IOSTREAM)
0203 
0204 /// Output a network as a string.
0205 /**
0206  * Used to output a human-readable string for a specified network.
0207  *
0208  * @param os The output stream to which the string will be written.
0209  *
0210  * @param net The network to be written.
0211  *
0212  * @return The output stream.
0213  *
0214  * @relates boost::asio::ip::address_v6
0215  */
0216 template <typename Elem, typename Traits>
0217 std::basic_ostream<Elem, Traits>& operator<<(
0218     std::basic_ostream<Elem, Traits>& os, const network_v6& net);
0219 
0220 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
0221 
0222 } // namespace ip
0223 } // namespace asio
0224 } // namespace boost
0225 
0226 #include <boost/asio/detail/pop_options.hpp>
0227 
0228 #include <boost/asio/ip/impl/network_v6.hpp>
0229 #if defined(BOOST_ASIO_HEADER_ONLY)
0230 # include <boost/asio/ip/impl/network_v6.ipp>
0231 #endif // defined(BOOST_ASIO_HEADER_ONLY)
0232 
0233 #endif // BOOST_ASIO_IP_NETWORK_V6_HPP