Chris@16: // Chris@16: // ip/detail/endpoint.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_DETAIL_ENDPOINT_HPP Chris@16: #define BOOST_ASIO_IP_DETAIL_ENDPOINT_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: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace ip { Chris@16: namespace detail { Chris@16: Chris@16: // Helper class for implementating an IP endpoint. Chris@16: class endpoint Chris@16: { Chris@16: public: Chris@16: // Default constructor. Chris@16: BOOST_ASIO_DECL endpoint(); Chris@16: Chris@16: // Construct an endpoint using a family and port number. Chris@16: BOOST_ASIO_DECL endpoint(int family, unsigned short port_num); Chris@16: Chris@16: // Construct an endpoint using an address and port number. Chris@16: BOOST_ASIO_DECL endpoint(const boost::asio::ip::address& addr, Chris@16: unsigned short port_num); Chris@16: Chris@16: // Copy constructor. Chris@16: endpoint(const endpoint& other) Chris@16: : data_(other.data_) Chris@16: { Chris@16: } Chris@16: Chris@16: // Assign from another endpoint. Chris@16: endpoint& operator=(const endpoint& other) Chris@16: { Chris@16: data_ = other.data_; Chris@16: return *this; Chris@16: } Chris@16: Chris@16: // Get the underlying endpoint in the native type. Chris@16: boost::asio::detail::socket_addr_type* data() Chris@16: { Chris@16: return &data_.base; Chris@16: } Chris@16: Chris@16: // Get the underlying endpoint in the native type. Chris@16: const boost::asio::detail::socket_addr_type* data() const Chris@16: { Chris@16: return &data_.base; Chris@16: } Chris@16: Chris@16: // Get the underlying size of the endpoint in the native type. Chris@16: std::size_t size() const Chris@16: { Chris@16: if (is_v4()) Chris@16: return sizeof(boost::asio::detail::sockaddr_in4_type); Chris@16: else Chris@16: return sizeof(boost::asio::detail::sockaddr_in6_type); Chris@16: } Chris@16: Chris@16: // Set the underlying size of the endpoint in the native type. Chris@16: BOOST_ASIO_DECL void resize(std::size_t new_size); Chris@16: Chris@16: // Get the capacity of the endpoint in the native type. Chris@16: std::size_t capacity() const Chris@16: { Chris@16: return sizeof(data_); Chris@16: } Chris@16: Chris@16: // Get the port associated with the endpoint. Chris@16: BOOST_ASIO_DECL unsigned short port() const; Chris@16: Chris@16: // Set the port associated with the endpoint. Chris@16: BOOST_ASIO_DECL void port(unsigned short port_num); Chris@16: Chris@16: // Get the IP address associated with the endpoint. Chris@16: BOOST_ASIO_DECL boost::asio::ip::address address() const; Chris@16: Chris@16: // Set the IP address associated with the endpoint. Chris@16: BOOST_ASIO_DECL void address(const boost::asio::ip::address& addr); Chris@16: Chris@16: // Compare two endpoints for equality. Chris@16: BOOST_ASIO_DECL friend bool operator==( Chris@16: const endpoint& e1, const endpoint& e2); Chris@16: Chris@16: // Compare endpoints for ordering. Chris@16: BOOST_ASIO_DECL friend bool operator<( Chris@16: const endpoint& e1, const endpoint& e2); Chris@16: Chris@16: // Determine whether the endpoint is IPv4. Chris@16: bool is_v4() const Chris@16: { Chris@16: return data_.base.sa_family == BOOST_ASIO_OS_DEF(AF_INET); Chris@16: } Chris@16: Chris@16: #if !defined(BOOST_ASIO_NO_IOSTREAM) Chris@16: // Convert to a string. Chris@16: BOOST_ASIO_DECL std::string to_string(boost::system::error_code& ec) const; Chris@16: #endif // !defined(BOOST_ASIO_NO_IOSTREAM) Chris@16: Chris@16: private: Chris@16: // The underlying IP socket address. Chris@16: union data_union Chris@16: { Chris@16: boost::asio::detail::socket_addr_type base; Chris@16: boost::asio::detail::sockaddr_in4_type v4; Chris@16: boost::asio::detail::sockaddr_in6_type v6; Chris@16: } data_; Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: } // namespace ip Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: 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_DETAIL_ENDPOINT_HPP