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.

address_v6.hpp 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. //
  2. // ip/address_v6.hpp
  3. // ~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef ASIO_IP_ADDRESS_V6_HPP
  11. #define ASIO_IP_ADDRESS_V6_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include <string>
  17. #include "asio/detail/array.hpp"
  18. #include "asio/detail/socket_types.hpp"
  19. #include "asio/detail/string_view.hpp"
  20. #include "asio/detail/winsock_init.hpp"
  21. #include "asio/error_code.hpp"
  22. #include "asio/ip/address_v4.hpp"
  23. #if !defined(ASIO_NO_IOSTREAM)
  24. # include <iosfwd>
  25. #endif // !defined(ASIO_NO_IOSTREAM)
  26. #include "asio/detail/push_options.hpp"
  27. namespace asio {
  28. namespace ip {
  29. template <typename> class basic_address_iterator;
  30. /// Implements IP version 6 style addresses.
  31. /**
  32. * The asio::ip::address_v6 class provides the ability to use and
  33. * manipulate IP version 6 addresses.
  34. *
  35. * @par Thread Safety
  36. * @e Distinct @e objects: Safe.@n
  37. * @e Shared @e objects: Unsafe.
  38. */
  39. class address_v6
  40. {
  41. public:
  42. /// The type used to represent an address as an array of bytes.
  43. /**
  44. * @note This type is defined in terms of the C++0x template @c std::array
  45. * when it is available. Otherwise, it uses @c boost:array.
  46. */
  47. #if defined(GENERATING_DOCUMENTATION)
  48. typedef array<unsigned char, 16> bytes_type;
  49. #else
  50. typedef asio::detail::array<unsigned char, 16> bytes_type;
  51. #endif
  52. /// Default constructor.
  53. ASIO_DECL address_v6() ASIO_NOEXCEPT;
  54. /// Construct an address from raw bytes and scope ID.
  55. ASIO_DECL explicit address_v6(const bytes_type& bytes,
  56. unsigned long scope_id = 0);
  57. /// Copy constructor.
  58. ASIO_DECL address_v6(const address_v6& other) ASIO_NOEXCEPT;
  59. #if defined(ASIO_HAS_MOVE)
  60. /// Move constructor.
  61. ASIO_DECL address_v6(address_v6&& other) ASIO_NOEXCEPT;
  62. #endif // defined(ASIO_HAS_MOVE)
  63. /// Assign from another address.
  64. ASIO_DECL address_v6& operator=(
  65. const address_v6& other) ASIO_NOEXCEPT;
  66. #if defined(ASIO_HAS_MOVE)
  67. /// Move-assign from another address.
  68. ASIO_DECL address_v6& operator=(address_v6&& other) ASIO_NOEXCEPT;
  69. #endif // defined(ASIO_HAS_MOVE)
  70. /// The scope ID of the address.
  71. /**
  72. * Returns the scope ID associated with the IPv6 address.
  73. */
  74. unsigned long scope_id() const ASIO_NOEXCEPT
  75. {
  76. return scope_id_;
  77. }
  78. /// The scope ID of the address.
  79. /**
  80. * Modifies the scope ID associated with the IPv6 address.
  81. */
  82. void scope_id(unsigned long id) ASIO_NOEXCEPT
  83. {
  84. scope_id_ = id;
  85. }
  86. /// Get the address in bytes, in network byte order.
  87. ASIO_DECL bytes_type to_bytes() const ASIO_NOEXCEPT;
  88. /// Get the address as a string.
  89. ASIO_DECL std::string to_string() const;
  90. #if !defined(ASIO_NO_DEPRECATED)
  91. /// (Deprecated: Use other overload.) Get the address as a string.
  92. ASIO_DECL std::string to_string(asio::error_code& ec) const;
  93. /// (Deprecated: Use make_address_v6().) Create an IPv6 address from an IP
  94. /// address string.
  95. static address_v6 from_string(const char* str);
  96. /// (Deprecated: Use make_address_v6().) Create an IPv6 address from an IP
  97. /// address string.
  98. static address_v6 from_string(
  99. const char* str, asio::error_code& ec);
  100. /// (Deprecated: Use make_address_v6().) Create an IPv6 address from an IP
  101. /// address string.
  102. static address_v6 from_string(const std::string& str);
  103. /// (Deprecated: Use make_address_v6().) Create an IPv6 address from an IP
  104. /// address string.
  105. static address_v6 from_string(
  106. const std::string& str, asio::error_code& ec);
  107. /// (Deprecated: Use make_address_v4().) Converts an IPv4-mapped or
  108. /// IPv4-compatible address to an IPv4 address.
  109. ASIO_DECL address_v4 to_v4() const;
  110. #endif // !defined(ASIO_NO_DEPRECATED)
  111. /// Determine whether the address is a loopback address.
  112. ASIO_DECL bool is_loopback() const ASIO_NOEXCEPT;
  113. /// Determine whether the address is unspecified.
  114. ASIO_DECL bool is_unspecified() const ASIO_NOEXCEPT;
  115. /// Determine whether the address is link local.
  116. ASIO_DECL bool is_link_local() const ASIO_NOEXCEPT;
  117. /// Determine whether the address is site local.
  118. ASIO_DECL bool is_site_local() const ASIO_NOEXCEPT;
  119. /// Determine whether the address is a mapped IPv4 address.
  120. ASIO_DECL bool is_v4_mapped() const ASIO_NOEXCEPT;
  121. #if !defined(ASIO_NO_DEPRECATED)
  122. /// (Deprecated: No replacement.) Determine whether the address is an
  123. /// IPv4-compatible address.
  124. ASIO_DECL bool is_v4_compatible() const;
  125. #endif // !defined(ASIO_NO_DEPRECATED)
  126. /// Determine whether the address is a multicast address.
  127. ASIO_DECL bool is_multicast() const ASIO_NOEXCEPT;
  128. /// Determine whether the address is a global multicast address.
  129. ASIO_DECL bool is_multicast_global() const ASIO_NOEXCEPT;
  130. /// Determine whether the address is a link-local multicast address.
  131. ASIO_DECL bool is_multicast_link_local() const ASIO_NOEXCEPT;
  132. /// Determine whether the address is a node-local multicast address.
  133. ASIO_DECL bool is_multicast_node_local() const ASIO_NOEXCEPT;
  134. /// Determine whether the address is a org-local multicast address.
  135. ASIO_DECL bool is_multicast_org_local() const ASIO_NOEXCEPT;
  136. /// Determine whether the address is a site-local multicast address.
  137. ASIO_DECL bool is_multicast_site_local() const ASIO_NOEXCEPT;
  138. /// Compare two addresses for equality.
  139. ASIO_DECL friend bool operator==(const address_v6& a1,
  140. const address_v6& a2) ASIO_NOEXCEPT;
  141. /// Compare two addresses for inequality.
  142. friend bool operator!=(const address_v6& a1,
  143. const address_v6& a2) ASIO_NOEXCEPT
  144. {
  145. return !(a1 == a2);
  146. }
  147. /// Compare addresses for ordering.
  148. ASIO_DECL friend bool operator<(const address_v6& a1,
  149. const address_v6& a2) ASIO_NOEXCEPT;
  150. /// Compare addresses for ordering.
  151. friend bool operator>(const address_v6& a1,
  152. const address_v6& a2) ASIO_NOEXCEPT
  153. {
  154. return a2 < a1;
  155. }
  156. /// Compare addresses for ordering.
  157. friend bool operator<=(const address_v6& a1,
  158. const address_v6& a2) ASIO_NOEXCEPT
  159. {
  160. return !(a2 < a1);
  161. }
  162. /// Compare addresses for ordering.
  163. friend bool operator>=(const address_v6& a1,
  164. const address_v6& a2) ASIO_NOEXCEPT
  165. {
  166. return !(a1 < a2);
  167. }
  168. /// Obtain an address object that represents any address.
  169. static address_v6 any() ASIO_NOEXCEPT
  170. {
  171. return address_v6();
  172. }
  173. /// Obtain an address object that represents the loopback address.
  174. ASIO_DECL static address_v6 loopback() ASIO_NOEXCEPT;
  175. #if !defined(ASIO_NO_DEPRECATED)
  176. /// (Deprecated: Use make_address_v6().) Create an IPv4-mapped IPv6 address.
  177. ASIO_DECL static address_v6 v4_mapped(const address_v4& addr);
  178. /// (Deprecated: No replacement.) Create an IPv4-compatible IPv6 address.
  179. ASIO_DECL static address_v6 v4_compatible(const address_v4& addr);
  180. #endif // !defined(ASIO_NO_DEPRECATED)
  181. private:
  182. friend class basic_address_iterator<address_v6>;
  183. // The underlying IPv6 address.
  184. asio::detail::in6_addr_type addr_;
  185. // The scope ID associated with the address.
  186. unsigned long scope_id_;
  187. };
  188. /// Create an IPv6 address from raw bytes and scope ID.
  189. /**
  190. * @relates address_v6
  191. */
  192. inline address_v6 make_address_v6(const address_v6::bytes_type& bytes,
  193. unsigned long scope_id = 0)
  194. {
  195. return address_v6(bytes, scope_id);
  196. }
  197. /// Create an IPv6 address from an IP address string.
  198. /**
  199. * @relates address_v6
  200. */
  201. ASIO_DECL address_v6 make_address_v6(const char* str);
  202. /// Create an IPv6 address from an IP address string.
  203. /**
  204. * @relates address_v6
  205. */
  206. ASIO_DECL address_v6 make_address_v6(const char* str,
  207. asio::error_code& ec) ASIO_NOEXCEPT;
  208. /// Createan IPv6 address from an IP address string.
  209. /**
  210. * @relates address_v6
  211. */
  212. ASIO_DECL address_v6 make_address_v6(const std::string& str);
  213. /// Create an IPv6 address from an IP address string.
  214. /**
  215. * @relates address_v6
  216. */
  217. ASIO_DECL address_v6 make_address_v6(const std::string& str,
  218. asio::error_code& ec) ASIO_NOEXCEPT;
  219. #if defined(ASIO_HAS_STRING_VIEW) \
  220. || defined(GENERATING_DOCUMENTATION)
  221. /// Create an IPv6 address from an IP address string.
  222. /**
  223. * @relates address_v6
  224. */
  225. ASIO_DECL address_v6 make_address_v6(string_view str);
  226. /// Create an IPv6 address from an IP address string.
  227. /**
  228. * @relates address_v6
  229. */
  230. ASIO_DECL address_v6 make_address_v6(string_view str,
  231. asio::error_code& ec) ASIO_NOEXCEPT;
  232. #endif // defined(ASIO_HAS_STRING_VIEW)
  233. // || defined(GENERATING_DOCUMENTATION)
  234. /// Tag type used for distinguishing overloads that deal in IPv4-mapped IPv6
  235. /// addresses.
  236. enum v4_mapped_t { v4_mapped };
  237. /// Create an IPv4 address from a IPv4-mapped IPv6 address.
  238. /**
  239. * @relates address_v4
  240. */
  241. ASIO_DECL address_v4 make_address_v4(
  242. v4_mapped_t, const address_v6& v6_addr);
  243. /// Create an IPv4-mapped IPv6 address from an IPv4 address.
  244. /**
  245. * @relates address_v6
  246. */
  247. ASIO_DECL address_v6 make_address_v6(
  248. v4_mapped_t, const address_v4& v4_addr);
  249. #if !defined(ASIO_NO_IOSTREAM)
  250. /// Output an address as a string.
  251. /**
  252. * Used to output a human-readable string for a specified address.
  253. *
  254. * @param os The output stream to which the string will be written.
  255. *
  256. * @param addr The address to be written.
  257. *
  258. * @return The output stream.
  259. *
  260. * @relates asio::ip::address_v6
  261. */
  262. template <typename Elem, typename Traits>
  263. std::basic_ostream<Elem, Traits>& operator<<(
  264. std::basic_ostream<Elem, Traits>& os, const address_v6& addr);
  265. #endif // !defined(ASIO_NO_IOSTREAM)
  266. } // namespace ip
  267. } // namespace asio
  268. #include "asio/detail/pop_options.hpp"
  269. #include "asio/ip/impl/address_v6.hpp"
  270. #if defined(ASIO_HEADER_ONLY)
  271. # include "asio/ip/impl/address_v6.ipp"
  272. #endif // defined(ASIO_HEADER_ONLY)
  273. #endif // ASIO_IP_ADDRESS_V6_HPP