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.

236 lines
6.0KB

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