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