Clementine
network_v6.hpp
1 //
2 // ip/network_v6.hpp
3 // ~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2020 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 
12 #ifndef ASIO_IP_NETWORK_V6_HPP
13 #define ASIO_IP_NETWORK_V6_HPP
14 
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 # pragma once
17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 
19 #include "asio/detail/config.hpp"
20 #include <string>
21 #include "asio/detail/string_view.hpp"
22 #include "asio/error_code.hpp"
23 #include "asio/ip/address_v6_range.hpp"
24 
25 #include "asio/detail/push_options.hpp"
26 
27 namespace asio {
28 namespace ip {
29 
31 
40 {
41 public:
43  network_v6() ASIO_NOEXCEPT
44  : address_(),
45  prefix_length_(0)
46  {
47  }
48 
50  ASIO_DECL network_v6(const address_v6& addr,
51  unsigned short prefix_len);
52 
54  network_v6(const network_v6& other) ASIO_NOEXCEPT
55  : address_(other.address_),
56  prefix_length_(other.prefix_length_)
57  {
58  }
59 
60 #if defined(ASIO_HAS_MOVE)
61  network_v6(network_v6&& other) ASIO_NOEXCEPT
63  : address_(ASIO_MOVE_CAST(address_v6)(other.address_)),
64  prefix_length_(other.prefix_length_)
65  {
66  }
67 #endif // defined(ASIO_HAS_MOVE)
68 
70  network_v6& operator=(const network_v6& other) ASIO_NOEXCEPT
71  {
72  address_ = other.address_;
73  prefix_length_ = other.prefix_length_;
74  return *this;
75  }
76 
77 #if defined(ASIO_HAS_MOVE)
78  network_v6& operator=(network_v6&& other) ASIO_NOEXCEPT
80  {
81  address_ = ASIO_MOVE_CAST(address_v6)(other.address_);
82  prefix_length_ = other.prefix_length_;
83  return *this;
84  }
85 #endif // defined(ASIO_HAS_MOVE)
86 
88  address_v6 address() const ASIO_NOEXCEPT
89  {
90  return address_;
91  }
92 
95  unsigned short prefix_length() const ASIO_NOEXCEPT
96  {
97  return prefix_length_;
98  }
99 
101  ASIO_DECL address_v6 network() const ASIO_NOEXCEPT;
102 
104  ASIO_DECL address_v6_range hosts() const ASIO_NOEXCEPT;
105 
107  network_v6 canonical() const ASIO_NOEXCEPT
108  {
109  return network_v6(network(), prefix_length());
110  }
111 
113  bool is_host() const ASIO_NOEXCEPT
114  {
115  return prefix_length_ == 128;
116  }
117 
119  ASIO_DECL bool is_subnet_of(const network_v6& other) const;
120 
122  ASIO_DECL std::string to_string() const;
123 
125  ASIO_DECL std::string to_string(asio::error_code& ec) const;
126 
128  friend bool operator==(const network_v6& a, const network_v6& b)
129  {
130  return a.address_ == b.address_ && a.prefix_length_ == b.prefix_length_;
131  }
132 
134  friend bool operator!=(const network_v6& a, const network_v6& b)
135  {
136  return !(a == b);
137  }
138 
139 private:
140  address_v6 address_;
141  unsigned short prefix_length_;
142 };
143 
145 
149  const address_v6& addr, unsigned short prefix_len)
150 {
151  return network_v6(addr, prefix_len);
152 }
153 
156 
159 ASIO_DECL network_v6 make_network_v6(const char* str);
160 
163 
166 ASIO_DECL network_v6 make_network_v6(
167  const char* str, asio::error_code& ec);
168 
171 
174 ASIO_DECL network_v6 make_network_v6(const std::string& str);
175 
178 
181 ASIO_DECL network_v6 make_network_v6(
182  const std::string& str, asio::error_code& ec);
183 
184 #if defined(ASIO_HAS_STRING_VIEW) \
185  || defined(GENERATING_DOCUMENTATION)
186 
189 
192 ASIO_DECL network_v6 make_network_v6(string_view str);
193 
196 
199 ASIO_DECL network_v6 make_network_v6(
200  string_view str, asio::error_code& ec);
201 
202 #endif // defined(ASIO_HAS_STRING_VIEW)
203  // || defined(GENERATING_DOCUMENTATION)
204 
205 #if !defined(ASIO_NO_IOSTREAM)
206 
208 
219 template <typename Elem, typename Traits>
220 std::basic_ostream<Elem, Traits>& operator<<(
221  std::basic_ostream<Elem, Traits>& os, const network_v6& net);
222 
223 #endif // !defined(ASIO_NO_IOSTREAM)
224 
225 } // namespace ip
226 } // namespace asio
227 
228 #include "asio/detail/pop_options.hpp"
229 
230 #include "asio/ip/impl/network_v6.hpp"
231 #if defined(ASIO_HEADER_ONLY)
232 # include "asio/ip/impl/network_v6.ipp"
233 #endif // defined(ASIO_HEADER_ONLY)
234 
235 #endif // ASIO_IP_NETWORK_V6_HPP
Represents an IPv6 network.
Definition: network_v6.hpp:39
friend bool operator!=(const network_v6 &a, const network_v6 &b)
Compare two networks for inequality.
Definition: network_v6.hpp:134
network_v6 & operator=(const network_v6 &other) ASIO_NOEXCEPT
Assign from another network.
Definition: network_v6.hpp:70
bool is_host() const ASIO_NOEXCEPT
Test if network is a valid host address.
Definition: network_v6.hpp:113
address_v6 address() const ASIO_NOEXCEPT
Obtain the address object specified when the network object was created.
Definition: network_v6.hpp:88
ASIO_DECL address_v6_range hosts() const ASIO_NOEXCEPT
Obtain an address range corresponding to the hosts in the network.
Definition: network_v6.ipp:58
network_v6 canonical() const ASIO_NOEXCEPT
Obtain the true network address, omitting any host bits.
Definition: network_v6.hpp:107
friend bool operator==(const network_v6 &a, const network_v6 &b)
Compare two networks for equality.
Definition: network_v6.hpp:128
unsigned short prefix_length() const ASIO_NOEXCEPT
Obtain the prefix length that was specified when the network object was created.
Definition: network_v6.hpp:95
Represents a range of IPv6 addresses.
Definition: address_v6_range.hpp:35
Class to represent an error code value.
Definition: error_code.hpp:80
Implements IP version 6 style addresses.
Definition: address_v6.hpp:47
ASIO_DECL bool is_subnet_of(const network_v6 &other) const
Test if a network is a real subnet of another network.
Definition: network_v6.ipp:80
network_v6() ASIO_NOEXCEPT
Default constructor.
Definition: network_v6.hpp:43
ASIO_DECL std::string to_string() const
Get the network as an address in dotted decimal format.
Definition: network_v6.ipp:88
network_v6 make_network_v6(const address_v6 &addr, unsigned short prefix_len)
Create an IPv6 network from an address and prefix length.
Definition: network_v6.hpp:148
ASIO_DECL network_v6 make_network_v6(const char *str)
Create an IPv6 network from a string containing IP address and prefix length.
Definition: network_v6.ipp:109
Definition: any_io_executor.hpp:28
network_v6(const network_v6 &other) ASIO_NOEXCEPT
Copy constructor.
Definition: network_v6.hpp:54
ASIO_DECL address_v6 network() const ASIO_NOEXCEPT
Obtain an address object that represents the network address.
Definition: network_v6.ipp:45