5 // Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_IP_ADDRESS_V6_HPP
12 #define BOOST_ASIO_IP_ADDRESS_V6_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #include <boost/asio/detail/array.hpp>
21 #include <boost/asio/detail/socket_types.hpp>
22 #include <boost/asio/detail/winsock_init.hpp>
23 #include <boost/system/error_code.hpp>
24 #include <boost/asio/ip/address_v4.hpp>
26 #if !defined(BOOST_ASIO_NO_IOSTREAM)
28 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
30 #include <boost/asio/detail/push_options.hpp>
36 /// Implements IP version 6 style addresses.
38 * The boost::asio::ip::address_v6 class provides the ability to use and
39 * manipulate IP version 6 addresses.
42 * @e Distinct @e objects: Safe.@n
43 * @e Shared @e objects: Unsafe.
48 /// The type used to represent an address as an array of bytes.
50 * @note This type is defined in terms of the C++0x template @c std::array
51 * when it is available. Otherwise, it uses @c boost:array.
53 #if defined(GENERATING_DOCUMENTATION)
54 typedef array<unsigned char, 16> bytes_type;
56 typedef boost::asio::detail::array<unsigned char, 16> bytes_type;
59 /// Default constructor.
60 BOOST_ASIO_DECL address_v6();
62 /// Construct an address from raw bytes and scope ID.
63 BOOST_ASIO_DECL explicit address_v6(const bytes_type& bytes,
64 unsigned long scope_id = 0);
67 BOOST_ASIO_DECL address_v6(const address_v6& other);
69 #if defined(BOOST_ASIO_HAS_MOVE)
71 BOOST_ASIO_DECL address_v6(address_v6&& other);
72 #endif // defined(BOOST_ASIO_HAS_MOVE)
74 /// Assign from another address.
75 BOOST_ASIO_DECL address_v6& operator=(const address_v6& other);
77 #if defined(BOOST_ASIO_HAS_MOVE)
78 /// Move-assign from another address.
79 BOOST_ASIO_DECL address_v6& operator=(address_v6&& other);
80 #endif // defined(BOOST_ASIO_HAS_MOVE)
82 /// The scope ID of the address.
84 * Returns the scope ID associated with the IPv6 address.
86 unsigned long scope_id() const
91 /// The scope ID of the address.
93 * Modifies the scope ID associated with the IPv6 address.
95 void scope_id(unsigned long id)
100 /// Get the address in bytes, in network byte order.
101 BOOST_ASIO_DECL bytes_type to_bytes() const;
103 /// Get the address as a string.
104 BOOST_ASIO_DECL std::string to_string() const;
106 /// Get the address as a string.
107 BOOST_ASIO_DECL std::string to_string(boost::system::error_code& ec) const;
109 /// Create an address from an IP address string.
110 BOOST_ASIO_DECL static address_v6 from_string(const char* str);
112 /// Create an address from an IP address string.
113 BOOST_ASIO_DECL static address_v6 from_string(
114 const char* str, boost::system::error_code& ec);
116 /// Create an address from an IP address string.
117 BOOST_ASIO_DECL static address_v6 from_string(const std::string& str);
119 /// Create an address from an IP address string.
120 BOOST_ASIO_DECL static address_v6 from_string(
121 const std::string& str, boost::system::error_code& ec);
123 /// Converts an IPv4-mapped or IPv4-compatible address to an IPv4 address.
124 BOOST_ASIO_DECL address_v4 to_v4() const;
126 /// Determine whether the address is a loopback address.
127 BOOST_ASIO_DECL bool is_loopback() const;
129 /// Determine whether the address is unspecified.
130 BOOST_ASIO_DECL bool is_unspecified() const;
132 /// Determine whether the address is link local.
133 BOOST_ASIO_DECL bool is_link_local() const;
135 /// Determine whether the address is site local.
136 BOOST_ASIO_DECL bool is_site_local() const;
138 /// Determine whether the address is a mapped IPv4 address.
139 BOOST_ASIO_DECL bool is_v4_mapped() const;
141 /// Determine whether the address is an IPv4-compatible address.
142 BOOST_ASIO_DECL bool is_v4_compatible() const;
144 /// Determine whether the address is a multicast address.
145 BOOST_ASIO_DECL bool is_multicast() const;
147 /// Determine whether the address is a global multicast address.
148 BOOST_ASIO_DECL bool is_multicast_global() const;
150 /// Determine whether the address is a link-local multicast address.
151 BOOST_ASIO_DECL bool is_multicast_link_local() const;
153 /// Determine whether the address is a node-local multicast address.
154 BOOST_ASIO_DECL bool is_multicast_node_local() const;
156 /// Determine whether the address is a org-local multicast address.
157 BOOST_ASIO_DECL bool is_multicast_org_local() const;
159 /// Determine whether the address is a site-local multicast address.
160 BOOST_ASIO_DECL bool is_multicast_site_local() const;
162 /// Compare two addresses for equality.
163 BOOST_ASIO_DECL friend bool operator==(
164 const address_v6& a1, const address_v6& a2);
166 /// Compare two addresses for inequality.
167 friend bool operator!=(const address_v6& a1, const address_v6& a2)
172 /// Compare addresses for ordering.
173 BOOST_ASIO_DECL friend bool operator<(
174 const address_v6& a1, const address_v6& a2);
176 /// Compare addresses for ordering.
177 friend bool operator>(const address_v6& a1, const address_v6& a2)
182 /// Compare addresses for ordering.
183 friend bool operator<=(const address_v6& a1, const address_v6& a2)
188 /// Compare addresses for ordering.
189 friend bool operator>=(const address_v6& a1, const address_v6& a2)
194 /// Obtain an address object that represents any address.
195 static address_v6 any()
200 /// Obtain an address object that represents the loopback address.
201 BOOST_ASIO_DECL static address_v6 loopback();
203 /// Create an IPv4-mapped IPv6 address.
204 BOOST_ASIO_DECL static address_v6 v4_mapped(const address_v4& addr);
206 /// Create an IPv4-compatible IPv6 address.
207 BOOST_ASIO_DECL static address_v6 v4_compatible(const address_v4& addr);
210 // The underlying IPv6 address.
211 boost::asio::detail::in6_addr_type addr_;
213 // The scope ID associated with the address.
214 unsigned long scope_id_;
217 #if !defined(BOOST_ASIO_NO_IOSTREAM)
219 /// Output an address as a string.
221 * Used to output a human-readable string for a specified address.
223 * @param os The output stream to which the string will be written.
225 * @param addr The address to be written.
227 * @return The output stream.
229 * @relates boost::asio::ip::address_v6
231 template <typename Elem, typename Traits>
232 std::basic_ostream<Elem, Traits>& operator<<(
233 std::basic_ostream<Elem, Traits>& os, const address_v6& addr);
235 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
241 #include <boost/asio/detail/pop_options.hpp>
243 #include <boost/asio/ip/impl/address_v6.hpp>
244 #if defined(BOOST_ASIO_HEADER_ONLY)
245 # include <boost/asio/ip/impl/address_v6.ipp>
246 #endif // defined(BOOST_ASIO_HEADER_ONLY)
248 #endif // BOOST_ASIO_IP_ADDRESS_V6_HPP