Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

211 lines
5.4KB

  1. //
  2. // ip/network_v6.hpp
  3. // ~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. // Copyright (c) 2014 Oliver Kowalke (oliver dot kowalke at gmail dot com)
  7. //
  8. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  9. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. #ifndef ASIO_IP_NETWORK_V6_HPP
  12. #define ASIO_IP_NETWORK_V6_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  16. #include "asio/detail/config.hpp"
  17. #include <string>
  18. #include "asio/error_code.hpp"
  19. #include "asio/ip/address_v6_range.hpp"
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. namespace ip {
  23. /// Represents an IPv6 network.
  24. /**
  25. * The asio::ip::network_v6 class provides the ability to use and
  26. * manipulate IP version 6 networks.
  27. *
  28. * @par Thread Safety
  29. * @e Distinct @e objects: Safe.@n
  30. * @e Shared @e objects: Unsafe.
  31. */
  32. class network_v6
  33. {
  34. public:
  35. /// Default constructor.
  36. network_v6() ASIO_NOEXCEPT
  37. : address_(),
  38. prefix_length_(0)
  39. {
  40. }
  41. /// Construct a network based on the specified address and prefix length.
  42. ASIO_DECL network_v6(const address_v6& addr,
  43. unsigned short prefix_len);
  44. /// Copy constructor.
  45. network_v6(const network_v6& other) ASIO_NOEXCEPT
  46. : address_(other.address_),
  47. prefix_length_(other.prefix_length_)
  48. {
  49. }
  50. #if defined(ASIO_HAS_MOVE)
  51. /// Move constructor.
  52. network_v6(network_v6&& other) ASIO_NOEXCEPT
  53. : address_(ASIO_MOVE_CAST(address_v6)(other.address_)),
  54. prefix_length_(other.prefix_length_)
  55. {
  56. }
  57. #endif // defined(ASIO_HAS_MOVE)
  58. /// Assign from another network.
  59. network_v6& operator=(const network_v6& other) ASIO_NOEXCEPT
  60. {
  61. address_ = other.address_;
  62. prefix_length_ = other.prefix_length_;
  63. return *this;
  64. }
  65. #if defined(ASIO_HAS_MOVE)
  66. /// Move-assign from another network.
  67. network_v6& operator=(network_v6&& other) ASIO_NOEXCEPT
  68. {
  69. address_ = ASIO_MOVE_CAST(address_v6)(other.address_);
  70. prefix_length_ = other.prefix_length_;
  71. return *this;
  72. }
  73. #endif // defined(ASIO_HAS_MOVE)
  74. /// Obtain the address object specified when the network object was created.
  75. address_v6 address() const ASIO_NOEXCEPT
  76. {
  77. return address_;
  78. }
  79. /// Obtain the prefix length that was specified when the network object was
  80. /// created.
  81. unsigned short prefix_length() const ASIO_NOEXCEPT
  82. {
  83. return prefix_length_;
  84. }
  85. /// Obtain an address object that represents the network address.
  86. ASIO_DECL address_v6 network() const ASIO_NOEXCEPT;
  87. /// Obtain an address range corresponding to the hosts in the network.
  88. ASIO_DECL address_v6_range hosts() const ASIO_NOEXCEPT;
  89. /// Obtain the true network address, omitting any host bits.
  90. network_v6 canonical() const ASIO_NOEXCEPT
  91. {
  92. return network_v6(network(), prefix_length());
  93. }
  94. /// Test if network is a valid host address.
  95. bool is_host() const ASIO_NOEXCEPT
  96. {
  97. return prefix_length_ == 128;
  98. }
  99. /// Test if a network is a real subnet of another network.
  100. ASIO_DECL bool is_subnet_of(const network_v6& other) const;
  101. /// Get the network as an address in dotted decimal format.
  102. ASIO_DECL std::string to_string() const;
  103. /// Get the network as an address in dotted decimal format.
  104. ASIO_DECL std::string to_string(asio::error_code& ec) const;
  105. /// Compare two networks for equality.
  106. friend bool operator==(const network_v6& a, const network_v6& b)
  107. {
  108. return a.address_ == b.address_ && a.prefix_length_ == b.prefix_length_;
  109. }
  110. /// Compare two networks for inequality.
  111. friend bool operator!=(const network_v6& a, const network_v6& b)
  112. {
  113. return !(a == b);
  114. }
  115. private:
  116. address_v6 address_;
  117. unsigned short prefix_length_;
  118. };
  119. /// Create an IPv6 network from an address and prefix length.
  120. /**
  121. * @relates address_v6
  122. */
  123. inline network_v6 make_network_v6(
  124. const address_v6& addr, unsigned short prefix_len)
  125. {
  126. return network_v6(addr, prefix_len);
  127. }
  128. /// Create an IPv6 network from a string containing IP address and prefix
  129. /// length.
  130. /**
  131. * @relates network_v6
  132. */
  133. ASIO_DECL network_v6 make_network_v6(const char* str);
  134. /// Create an IPv6 address from an IP address string in dotted decimal form.
  135. /**
  136. * @relates network_v6
  137. */
  138. ASIO_DECL network_v6 make_network_v6(
  139. const char* str, asio::error_code& ec);
  140. /// Create an IPv6 address from an IP address string in dotted decimal form.
  141. /**
  142. * @relates network_v6
  143. */
  144. ASIO_DECL network_v6 make_network_v6(const std::string& str);
  145. /// Create an IPv6 address from an IP address string in dotted decimal form.
  146. /**
  147. * @relates network_v6
  148. */
  149. ASIO_DECL network_v6 make_network_v6(
  150. const std::string& str, asio::error_code& ec);
  151. #if !defined(ASIO_NO_IOSTREAM)
  152. /// Output a network as a string.
  153. /**
  154. * Used to output a human-readable string for a specified network.
  155. *
  156. * @param os The output stream to which the string will be written.
  157. *
  158. * @param net The network to be written.
  159. *
  160. * @return The output stream.
  161. *
  162. * @relates asio::ip::address_v6
  163. */
  164. template <typename Elem, typename Traits>
  165. std::basic_ostream<Elem, Traits>& operator<<(
  166. std::basic_ostream<Elem, Traits>& os, const network_v6& net);
  167. #endif // !defined(ASIO_NO_IOSTREAM)
  168. } // namespace ip
  169. } // namespace asio
  170. #include "asio/detail/pop_options.hpp"
  171. #include "asio/ip/impl/network_v6.hpp"
  172. #if defined(ASIO_HEADER_ONLY)
  173. # include "asio/ip/impl/network_v6.ipp"
  174. #endif // defined(ASIO_HEADER_ONLY)
  175. #endif // ASIO_IP_NETWORK_V6_HPP