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 8.7KB

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