Clementine
address_v6.hpp
1 //
2 // ip/address_v6.hpp
3 // ~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2020 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 
11 #ifndef ASIO_IP_ADDRESS_V6_HPP
12 #define ASIO_IP_ADDRESS_V6_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 #include <string>
20 #include "asio/detail/array.hpp"
21 #include "asio/detail/socket_types.hpp"
22 #include "asio/detail/string_view.hpp"
23 #include "asio/detail/winsock_init.hpp"
24 #include "asio/error_code.hpp"
25 #include "asio/ip/address_v4.hpp"
26 
27 #if !defined(ASIO_NO_IOSTREAM)
28 # include <iosfwd>
29 #endif // !defined(ASIO_NO_IOSTREAM)
30 
31 #include "asio/detail/push_options.hpp"
32 
33 namespace asio {
34 namespace ip {
35 
36 template <typename> class basic_address_iterator;
37 
39 
48 {
49 public:
51 
55 #if defined(GENERATING_DOCUMENTATION)
56  typedef array<unsigned char, 16> bytes_type;
57 #else
59 #endif
60 
62  ASIO_DECL address_v6() ASIO_NOEXCEPT;
63 
65  ASIO_DECL explicit address_v6(const bytes_type& bytes,
66  unsigned long scope_id = 0);
67 
69  ASIO_DECL address_v6(const address_v6& other) ASIO_NOEXCEPT;
70 
71 #if defined(ASIO_HAS_MOVE)
72  ASIO_DECL address_v6(address_v6&& other) ASIO_NOEXCEPT;
74 #endif // defined(ASIO_HAS_MOVE)
75 
77  ASIO_DECL address_v6& operator=(
78  const address_v6& other) ASIO_NOEXCEPT;
79 
80 #if defined(ASIO_HAS_MOVE)
81  ASIO_DECL address_v6& operator=(address_v6&& other) ASIO_NOEXCEPT;
83 #endif // defined(ASIO_HAS_MOVE)
84 
86 
89  unsigned long scope_id() const ASIO_NOEXCEPT
90  {
91  return scope_id_;
92  }
93 
95 
98  void scope_id(unsigned long id) ASIO_NOEXCEPT
99  {
100  scope_id_ = id;
101  }
102 
104  ASIO_DECL bytes_type to_bytes() const ASIO_NOEXCEPT;
105 
107  ASIO_DECL std::string to_string() const;
108 
109 #if !defined(ASIO_NO_DEPRECATED)
110  ASIO_DECL std::string to_string(asio::error_code& ec) const;
112 
115  static address_v6 from_string(const char* str);
116 
119  static address_v6 from_string(
120  const char* str, asio::error_code& ec);
121 
124  static address_v6 from_string(const std::string& str);
125 
128  static address_v6 from_string(
129  const std::string& str, asio::error_code& ec);
130 
133  ASIO_DECL address_v4 to_v4() const;
134 #endif // !defined(ASIO_NO_DEPRECATED)
135 
137  ASIO_DECL bool is_loopback() const ASIO_NOEXCEPT;
138 
140  ASIO_DECL bool is_unspecified() const ASIO_NOEXCEPT;
141 
143  ASIO_DECL bool is_link_local() const ASIO_NOEXCEPT;
144 
146  ASIO_DECL bool is_site_local() const ASIO_NOEXCEPT;
147 
149  ASIO_DECL bool is_v4_mapped() const ASIO_NOEXCEPT;
150 
151 #if !defined(ASIO_NO_DEPRECATED)
152  ASIO_DECL bool is_v4_compatible() const;
155 #endif // !defined(ASIO_NO_DEPRECATED)
156 
158  ASIO_DECL bool is_multicast() const ASIO_NOEXCEPT;
159 
161  ASIO_DECL bool is_multicast_global() const ASIO_NOEXCEPT;
162 
164  ASIO_DECL bool is_multicast_link_local() const ASIO_NOEXCEPT;
165 
167  ASIO_DECL bool is_multicast_node_local() const ASIO_NOEXCEPT;
168 
170  ASIO_DECL bool is_multicast_org_local() const ASIO_NOEXCEPT;
171 
173  ASIO_DECL bool is_multicast_site_local() const ASIO_NOEXCEPT;
174 
176  ASIO_DECL friend bool operator==(const address_v6& a1,
177  const address_v6& a2) ASIO_NOEXCEPT;
178 
180  friend bool operator!=(const address_v6& a1,
181  const address_v6& a2) ASIO_NOEXCEPT
182  {
183  return !(a1 == a2);
184  }
185 
187  ASIO_DECL friend bool operator<(const address_v6& a1,
188  const address_v6& a2) ASIO_NOEXCEPT;
189 
191  friend bool operator>(const address_v6& a1,
192  const address_v6& a2) ASIO_NOEXCEPT
193  {
194  return a2 < a1;
195  }
196 
198  friend bool operator<=(const address_v6& a1,
199  const address_v6& a2) ASIO_NOEXCEPT
200  {
201  return !(a2 < a1);
202  }
203 
205  friend bool operator>=(const address_v6& a1,
206  const address_v6& a2) ASIO_NOEXCEPT
207  {
208  return !(a1 < a2);
209  }
210 
212  static address_v6 any() ASIO_NOEXCEPT
213  {
214  return address_v6();
215  }
216 
218  ASIO_DECL static address_v6 loopback() ASIO_NOEXCEPT;
219 
220 #if !defined(ASIO_NO_DEPRECATED)
221  ASIO_DECL static address_v6 v4_mapped(const address_v4& addr);
223 
225  ASIO_DECL static address_v6 v4_compatible(const address_v4& addr);
226 #endif // !defined(ASIO_NO_DEPRECATED)
227 
228 private:
229  friend class basic_address_iterator<address_v6>;
230 
231  // The underlying IPv6 address.
232  asio::detail::in6_addr_type addr_;
233 
234  // The scope ID associated with the address.
235  unsigned long scope_id_;
236 };
237 
239 
243  unsigned long scope_id = 0)
244 {
245  return address_v6(bytes, scope_id);
246 }
247 
249 
252 ASIO_DECL address_v6 make_address_v6(const char* str);
253 
255 
258 ASIO_DECL address_v6 make_address_v6(const char* str,
259  asio::error_code& ec) ASIO_NOEXCEPT;
260 
262 
265 ASIO_DECL address_v6 make_address_v6(const std::string& str);
266 
268 
271 ASIO_DECL address_v6 make_address_v6(const std::string& str,
272  asio::error_code& ec) ASIO_NOEXCEPT;
273 
274 #if defined(ASIO_HAS_STRING_VIEW) \
275  || defined(GENERATING_DOCUMENTATION)
276 
278 
281 ASIO_DECL address_v6 make_address_v6(string_view str);
282 
284 
288  asio::error_code& ec) ASIO_NOEXCEPT;
289 
290 #endif // defined(ASIO_HAS_STRING_VIEW)
291  // || defined(GENERATING_DOCUMENTATION)
292 
295 enum v4_mapped_t { v4_mapped };
296 
298 
301 ASIO_DECL address_v4 make_address_v4(
302  v4_mapped_t, const address_v6& v6_addr);
303 
305 
308 ASIO_DECL address_v6 make_address_v6(
309  v4_mapped_t, const address_v4& v4_addr);
310 
311 #if !defined(ASIO_NO_IOSTREAM)
312 
314 
325 template <typename Elem, typename Traits>
326 std::basic_ostream<Elem, Traits>& operator<<(
327  std::basic_ostream<Elem, Traits>& os, const address_v6& addr);
328 
329 #endif // !defined(ASIO_NO_IOSTREAM)
330 
331 } // namespace ip
332 } // namespace asio
333 
334 #include "asio/detail/pop_options.hpp"
335 
336 #include "asio/ip/impl/address_v6.hpp"
337 #if defined(ASIO_HEADER_ONLY)
338 # include "asio/ip/impl/address_v6.ipp"
339 #endif // defined(ASIO_HEADER_ONLY)
340 
341 #endif // ASIO_IP_ADDRESS_V6_HPP
address_v6 make_address_v6(const address_v6::bytes_type &bytes, unsigned long scope_id=0)
Create an IPv6 address from raw bytes and scope ID.
Definition: address_v6.hpp:242
ASIO_DECL bool is_loopback() const ASIO_NOEXCEPT
Determine whether the address is a loopback address.
Definition: address_v6.ipp:141
ASIO_DECL bytes_type to_bytes() const ASIO_NOEXCEPT
Get the address in bytes, in network byte order.
Definition: address_v6.ipp:89
ASIO_DECL bool is_multicast() const ASIO_NOEXCEPT
Determine whether the address is a multicast address.
Definition: address_v6.ipp:201
static ASIO_DECL address_v6 loopback() ASIO_NOEXCEPT
Obtain an address object that represents the loopback address.
Definition: address_v6.ipp:251
friend bool operator!=(const address_v6 &a1, const address_v6 &a2) ASIO_NOEXCEPT
Compare two addresses for inequality.
Definition: address_v6.hpp:180
ASIO_DECL std::string to_string() const
Get the address as a string.
Definition: address_v6.ipp:101
Definition: address_v4_iterator.hpp:26
static ASIO_DECL address_v6 v4_mapped(const address_v4 &addr)
(Deprecated: Use make_address_v6().) Create an IPv4-mapped IPv6 address.
Definition: address_v6.ipp:259
ASIO_DECL friend bool operator<(const address_v6 &a1, const address_v6 &a2) ASIO_NOEXCEPT
Compare addresses for ordering.
Definition: address_v6.ipp:239
Implements IP version 4 style addresses.
Definition: address_v4.hpp:45
ASIO_DECL address_v6 & operator=(const address_v6 &other) ASIO_NOEXCEPT
Assign from another address.
Definition: address_v6.ipp:73
friend bool operator<=(const address_v6 &a1, const address_v6 &a2) ASIO_NOEXCEPT
Compare addresses for ordering.
Definition: address_v6.hpp:198
ASIO_DECL bool is_multicast_node_local() const ASIO_NOEXCEPT
Determine whether the address is a node-local multicast address.
Definition: address_v6.ipp:216
ASIO_DECL address_v4 to_v4() const
(Deprecated: Use make_address_v4().) Converts an IPv4-mapped or IPv4-compatible address to an IPv4 ad...
Definition: address_v6.ipp:127
asio::detail::array< unsigned char, 16 > bytes_type
The type used to represent an address as an array of bytes.
Definition: address_v6.hpp:58
ASIO_DECL bool is_multicast_global() const ASIO_NOEXCEPT
Determine whether the address is a global multicast address.
Definition: address_v6.ipp:206
ASIO_DECL address_v6() ASIO_NOEXCEPT
Default constructor.
Definition: address_v6.ipp:34
ASIO_DECL friend bool operator==(const address_v6 &a1, const address_v6 &a2) ASIO_NOEXCEPT
Compare two addresses for equality.
Definition: address_v6.ipp:231
ASIO_DECL bool is_link_local() const ASIO_NOEXCEPT
Determine whether the address is link local.
Definition: address_v6.ipp:165
friend bool operator>(const address_v6 &a1, const address_v6 &a2) ASIO_NOEXCEPT
Compare addresses for ordering.
Definition: address_v6.hpp:191
friend bool operator>=(const address_v6 &a1, const address_v6 &a2) ASIO_NOEXCEPT
Compare addresses for ordering.
Definition: address_v6.hpp:205
ASIO_DECL bool is_multicast_org_local() const ASIO_NOEXCEPT
Determine whether the address is a org-local multicast address.
Definition: address_v6.ipp:221
static address_v6 from_string(const char *str)
(Deprecated: Use make_address_v6().) Create an IPv6 address from an IP address string.
Definition: address_v6.hpp:29
static address_v6 any() ASIO_NOEXCEPT
Obtain an address object that represents any address.
Definition: address_v6.hpp:212
ASIO_DECL bool is_unspecified() const ASIO_NOEXCEPT
Determine whether the address is unspecified.
Definition: address_v6.ipp:153
ASIO_DECL bool is_multicast_link_local() const ASIO_NOEXCEPT
Determine whether the address is a link-local multicast address.
Definition: address_v6.ipp:211
Class to represent an error code value.
Definition: error_code.hpp:80
Implements IP version 6 style addresses.
Definition: address_v6.hpp:47
unsigned long scope_id() const ASIO_NOEXCEPT
The scope ID of the address.
Definition: address_v6.hpp:89
std::basic_ostream< Elem, Traits > & operator<<(std::basic_ostream< Elem, Traits > &os, const address_v6 &addr)
Output an address as a string.
Definition: address_v6.hpp:54
ASIO_DECL bool is_v4_mapped() const ASIO_NOEXCEPT
Determine whether the address is a mapped IPv4 address.
Definition: address_v6.ipp:175
ASIO_DECL bool is_multicast_site_local() const ASIO_NOEXCEPT
Determine whether the address is a site-local multicast address.
Definition: address_v6.ipp:226
void scope_id(unsigned long id) ASIO_NOEXCEPT
The scope ID of the address.
Definition: address_v6.hpp:98
Definition: any_io_executor.hpp:28
ASIO_DECL bool is_v4_compatible() const
(Deprecated: No replacement.) Determine whether the address is an IPv4-compatible address...
Definition: address_v6.ipp:186
ASIO_DECL bool is_site_local() const ASIO_NOEXCEPT
Determine whether the address is site local.
Definition: address_v6.ipp:170
Definition: format.h:3611
Definition: array_fwd.hpp:23
static ASIO_DECL address_v6 v4_compatible(const address_v4 &addr)
(Deprecated: No replacement.) Create an IPv4-compatible IPv6 address.
Definition: address_v6.ipp:267