Chris@16: // Chris@16: // ip/address_v6.hpp Chris@16: // ~~~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_IP_ADDRESS_V6_HPP Chris@16: #define BOOST_ASIO_IP_ADDRESS_V6_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #if !defined(BOOST_ASIO_NO_IOSTREAM) Chris@16: # include Chris@16: #endif // !defined(BOOST_ASIO_NO_IOSTREAM) Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace ip { Chris@16: Chris@16: /// Implements IP version 6 style addresses. Chris@16: /** Chris@16: * The boost::asio::ip::address_v6 class provides the ability to use and Chris@16: * manipulate IP version 6 addresses. Chris@16: * Chris@16: * @par Thread Safety Chris@16: * @e Distinct @e objects: Safe.@n Chris@16: * @e Shared @e objects: Unsafe. Chris@16: */ Chris@16: class address_v6 Chris@16: { Chris@16: public: Chris@16: /// The type used to represent an address as an array of bytes. Chris@16: /** Chris@16: * @note This type is defined in terms of the C++0x template @c std::array Chris@16: * when it is available. Otherwise, it uses @c boost:array. Chris@16: */ Chris@16: #if defined(GENERATING_DOCUMENTATION) Chris@16: typedef array bytes_type; Chris@16: #else Chris@16: typedef boost::asio::detail::array bytes_type; Chris@16: #endif Chris@16: Chris@16: /// Default constructor. Chris@16: BOOST_ASIO_DECL address_v6(); Chris@16: Chris@16: /// Construct an address from raw bytes and scope ID. Chris@16: BOOST_ASIO_DECL explicit address_v6(const bytes_type& bytes, Chris@16: unsigned long scope_id = 0); Chris@16: Chris@16: /// Copy constructor. Chris@16: BOOST_ASIO_DECL address_v6(const address_v6& other); Chris@16: Chris@16: #if defined(BOOST_ASIO_HAS_MOVE) Chris@16: /// Move constructor. Chris@16: BOOST_ASIO_DECL address_v6(address_v6&& other); Chris@16: #endif // defined(BOOST_ASIO_HAS_MOVE) Chris@16: Chris@16: /// Assign from another address. Chris@16: BOOST_ASIO_DECL address_v6& operator=(const address_v6& other); Chris@16: Chris@16: #if defined(BOOST_ASIO_HAS_MOVE) Chris@16: /// Move-assign from another address. Chris@16: BOOST_ASIO_DECL address_v6& operator=(address_v6&& other); Chris@16: #endif // defined(BOOST_ASIO_HAS_MOVE) Chris@16: Chris@16: /// The scope ID of the address. Chris@16: /** Chris@16: * Returns the scope ID associated with the IPv6 address. Chris@16: */ Chris@16: unsigned long scope_id() const Chris@16: { Chris@16: return scope_id_; Chris@16: } Chris@16: Chris@16: /// The scope ID of the address. Chris@16: /** Chris@16: * Modifies the scope ID associated with the IPv6 address. Chris@16: */ Chris@16: void scope_id(unsigned long id) Chris@16: { Chris@16: scope_id_ = id; Chris@16: } Chris@16: Chris@16: /// Get the address in bytes, in network byte order. Chris@16: BOOST_ASIO_DECL bytes_type to_bytes() const; Chris@16: Chris@16: /// Get the address as a string. Chris@16: BOOST_ASIO_DECL std::string to_string() const; Chris@16: Chris@16: /// Get the address as a string. Chris@16: BOOST_ASIO_DECL std::string to_string(boost::system::error_code& ec) const; Chris@16: Chris@16: /// Create an address from an IP address string. Chris@16: BOOST_ASIO_DECL static address_v6 from_string(const char* str); Chris@16: Chris@16: /// Create an address from an IP address string. Chris@16: BOOST_ASIO_DECL static address_v6 from_string( Chris@16: const char* str, boost::system::error_code& ec); Chris@16: Chris@16: /// Create an address from an IP address string. Chris@16: BOOST_ASIO_DECL static address_v6 from_string(const std::string& str); Chris@16: Chris@16: /// Create an address from an IP address string. Chris@16: BOOST_ASIO_DECL static address_v6 from_string( Chris@16: const std::string& str, boost::system::error_code& ec); Chris@16: Chris@16: /// Converts an IPv4-mapped or IPv4-compatible address to an IPv4 address. Chris@16: BOOST_ASIO_DECL address_v4 to_v4() const; Chris@16: Chris@16: /// Determine whether the address is a loopback address. Chris@16: BOOST_ASIO_DECL bool is_loopback() const; Chris@16: Chris@16: /// Determine whether the address is unspecified. Chris@16: BOOST_ASIO_DECL bool is_unspecified() const; Chris@16: Chris@16: /// Determine whether the address is link local. Chris@16: BOOST_ASIO_DECL bool is_link_local() const; Chris@16: Chris@16: /// Determine whether the address is site local. Chris@16: BOOST_ASIO_DECL bool is_site_local() const; Chris@16: Chris@16: /// Determine whether the address is a mapped IPv4 address. Chris@16: BOOST_ASIO_DECL bool is_v4_mapped() const; Chris@16: Chris@16: /// Determine whether the address is an IPv4-compatible address. Chris@16: BOOST_ASIO_DECL bool is_v4_compatible() const; Chris@16: Chris@16: /// Determine whether the address is a multicast address. Chris@16: BOOST_ASIO_DECL bool is_multicast() const; Chris@16: Chris@16: /// Determine whether the address is a global multicast address. Chris@16: BOOST_ASIO_DECL bool is_multicast_global() const; Chris@16: Chris@16: /// Determine whether the address is a link-local multicast address. Chris@16: BOOST_ASIO_DECL bool is_multicast_link_local() const; Chris@16: Chris@16: /// Determine whether the address is a node-local multicast address. Chris@16: BOOST_ASIO_DECL bool is_multicast_node_local() const; Chris@16: Chris@16: /// Determine whether the address is a org-local multicast address. Chris@16: BOOST_ASIO_DECL bool is_multicast_org_local() const; Chris@16: Chris@16: /// Determine whether the address is a site-local multicast address. Chris@16: BOOST_ASIO_DECL bool is_multicast_site_local() const; Chris@16: Chris@16: /// Compare two addresses for equality. Chris@16: BOOST_ASIO_DECL friend bool operator==( Chris@16: const address_v6& a1, const address_v6& a2); Chris@16: Chris@16: /// Compare two addresses for inequality. Chris@16: friend bool operator!=(const address_v6& a1, const address_v6& a2) Chris@16: { Chris@16: return !(a1 == a2); Chris@16: } Chris@16: Chris@16: /// Compare addresses for ordering. Chris@16: BOOST_ASIO_DECL friend bool operator<( Chris@16: const address_v6& a1, const address_v6& a2); Chris@16: Chris@16: /// Compare addresses for ordering. Chris@16: friend bool operator>(const address_v6& a1, const address_v6& a2) Chris@16: { Chris@16: return a2 < a1; Chris@16: } Chris@16: Chris@16: /// Compare addresses for ordering. Chris@16: friend bool operator<=(const address_v6& a1, const address_v6& a2) Chris@16: { Chris@16: return !(a2 < a1); Chris@16: } Chris@16: Chris@16: /// Compare addresses for ordering. Chris@16: friend bool operator>=(const address_v6& a1, const address_v6& a2) Chris@16: { Chris@16: return !(a1 < a2); Chris@16: } Chris@16: Chris@16: /// Obtain an address object that represents any address. Chris@16: static address_v6 any() Chris@16: { Chris@16: return address_v6(); Chris@16: } Chris@16: Chris@16: /// Obtain an address object that represents the loopback address. Chris@16: BOOST_ASIO_DECL static address_v6 loopback(); Chris@16: Chris@16: /// Create an IPv4-mapped IPv6 address. Chris@16: BOOST_ASIO_DECL static address_v6 v4_mapped(const address_v4& addr); Chris@16: Chris@16: /// Create an IPv4-compatible IPv6 address. Chris@16: BOOST_ASIO_DECL static address_v6 v4_compatible(const address_v4& addr); Chris@16: Chris@16: private: Chris@16: // The underlying IPv6 address. Chris@16: boost::asio::detail::in6_addr_type addr_; Chris@16: Chris@16: // The scope ID associated with the address. Chris@16: unsigned long scope_id_; Chris@16: }; Chris@16: Chris@16: #if !defined(BOOST_ASIO_NO_IOSTREAM) Chris@16: Chris@16: /// Output an address as a string. Chris@16: /** Chris@16: * Used to output a human-readable string for a specified address. Chris@16: * Chris@16: * @param os The output stream to which the string will be written. Chris@16: * Chris@16: * @param addr The address to be written. Chris@16: * Chris@16: * @return The output stream. Chris@16: * Chris@16: * @relates boost::asio::ip::address_v6 Chris@16: */ Chris@16: template Chris@16: std::basic_ostream& operator<<( Chris@16: std::basic_ostream& os, const address_v6& addr); Chris@16: Chris@16: #endif // !defined(BOOST_ASIO_NO_IOSTREAM) Chris@16: Chris@16: } // namespace ip Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #if defined(BOOST_ASIO_HEADER_ONLY) Chris@16: # include Chris@16: #endif // defined(BOOST_ASIO_HEADER_ONLY) Chris@16: Chris@16: #endif // BOOST_ASIO_IP_ADDRESS_V6_HPP