Chris@16: // Chris@16: // ip/address.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_HPP Chris@16: #define BOOST_ASIO_IP_ADDRESS_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: 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 version-independent IP addresses. Chris@16: /** Chris@16: * The boost::asio::ip::address class provides the ability to use either IP Chris@16: * version 4 or 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 Chris@16: { Chris@16: public: Chris@16: /// Default constructor. Chris@16: BOOST_ASIO_DECL address(); Chris@16: Chris@16: /// Construct an address from an IPv4 address. Chris@16: BOOST_ASIO_DECL address(const boost::asio::ip::address_v4& ipv4_address); Chris@16: Chris@16: /// Construct an address from an IPv6 address. Chris@16: BOOST_ASIO_DECL address(const boost::asio::ip::address_v6& ipv6_address); Chris@16: Chris@16: /// Copy constructor. Chris@16: BOOST_ASIO_DECL address(const address& other); Chris@16: Chris@16: #if defined(BOOST_ASIO_HAS_MOVE) Chris@16: /// Move constructor. Chris@16: BOOST_ASIO_DECL address(address&& other); Chris@16: #endif // defined(BOOST_ASIO_HAS_MOVE) Chris@16: Chris@16: /// Assign from another address. Chris@16: BOOST_ASIO_DECL address& operator=(const address& other); Chris@16: Chris@16: #if defined(BOOST_ASIO_HAS_MOVE) Chris@16: /// Move-assign from another address. Chris@16: BOOST_ASIO_DECL address& operator=(address&& other); Chris@16: #endif // defined(BOOST_ASIO_HAS_MOVE) Chris@16: Chris@16: /// Assign from an IPv4 address. Chris@16: BOOST_ASIO_DECL address& operator=( Chris@16: const boost::asio::ip::address_v4& ipv4_address); Chris@16: Chris@16: /// Assign from an IPv6 address. Chris@16: BOOST_ASIO_DECL address& operator=( Chris@16: const boost::asio::ip::address_v6& ipv6_address); Chris@16: Chris@16: /// Get whether the address is an IP version 4 address. Chris@16: bool is_v4() const Chris@16: { Chris@16: return type_ == ipv4; Chris@16: } Chris@16: Chris@16: /// Get whether the address is an IP version 6 address. Chris@16: bool is_v6() const Chris@16: { Chris@16: return type_ == ipv6; Chris@16: } Chris@16: Chris@16: /// Get the address as an IP version 4 address. Chris@16: BOOST_ASIO_DECL boost::asio::ip::address_v4 to_v4() const; Chris@16: Chris@16: /// Get the address as an IP version 6 address. Chris@16: BOOST_ASIO_DECL boost::asio::ip::address_v6 to_v6() const; Chris@16: Chris@16: /// Get the address as a string in dotted decimal format. Chris@16: BOOST_ASIO_DECL std::string to_string() const; Chris@16: Chris@16: /// Get the address as a string in dotted decimal format. Chris@16: BOOST_ASIO_DECL std::string to_string(boost::system::error_code& ec) const; Chris@16: Chris@16: /// Create an address from an IPv4 address string in dotted decimal form, Chris@16: /// or from an IPv6 address in hexadecimal notation. Chris@16: BOOST_ASIO_DECL static address from_string(const char* str); Chris@16: Chris@16: /// Create an address from an IPv4 address string in dotted decimal form, Chris@16: /// or from an IPv6 address in hexadecimal notation. Chris@16: BOOST_ASIO_DECL static address from_string( Chris@16: const char* str, boost::system::error_code& ec); Chris@16: Chris@16: /// Create an address from an IPv4 address string in dotted decimal form, Chris@16: /// or from an IPv6 address in hexadecimal notation. Chris@16: BOOST_ASIO_DECL static address from_string(const std::string& str); Chris@16: Chris@16: /// Create an address from an IPv4 address string in dotted decimal form, Chris@16: /// or from an IPv6 address in hexadecimal notation. Chris@16: BOOST_ASIO_DECL static address from_string( Chris@16: const std::string& str, boost::system::error_code& ec); 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 a multicast address. Chris@16: BOOST_ASIO_DECL bool is_multicast() const; Chris@16: Chris@16: /// Compare two addresses for equality. Chris@16: BOOST_ASIO_DECL friend bool operator==(const address& a1, const address& a2); Chris@16: Chris@16: /// Compare two addresses for inequality. Chris@16: friend bool operator!=(const address& a1, const address& 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<(const address& a1, const address& a2); Chris@16: Chris@16: /// Compare addresses for ordering. Chris@16: friend bool operator>(const address& a1, const address& 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& a1, const address& 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& a1, const address& a2) Chris@16: { Chris@16: return !(a1 < a2); Chris@16: } Chris@16: Chris@16: private: Chris@16: // The type of the address. Chris@16: enum { ipv4, ipv6 } type_; Chris@16: Chris@16: // The underlying IPv4 address. Chris@16: boost::asio::ip::address_v4 ipv4_address_; Chris@16: Chris@16: // The underlying IPv6 address. Chris@16: boost::asio::ip::address_v6 ipv6_address_; 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 Chris@16: */ Chris@16: template Chris@16: std::basic_ostream& operator<<( Chris@16: std::basic_ostream& os, const address& 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_HPP