2 // ip/detail/endpoint.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2016 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_DETAIL_ENDPOINT_HPP
12 #define BOOST_ASIO_IP_DETAIL_ENDPOINT_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/socket_types.hpp>
21 #include <boost/asio/detail/winsock_init.hpp>
22 #include <boost/system/error_code.hpp>
23 #include <boost/asio/ip/address.hpp>
25 #include <boost/asio/detail/push_options.hpp>
32 // Helper class for implementating an IP endpoint.
36 // Default constructor.
37 BOOST_ASIO_DECL endpoint();
39 // Construct an endpoint using a family and port number.
40 BOOST_ASIO_DECL endpoint(int family, unsigned short port_num);
42 // Construct an endpoint using an address and port number.
43 BOOST_ASIO_DECL endpoint(const boost::asio::ip::address& addr,
44 unsigned short port_num);
47 endpoint(const endpoint& other)
52 // Assign from another endpoint.
53 endpoint& operator=(const endpoint& other)
59 // Get the underlying endpoint in the native type.
60 boost::asio::detail::socket_addr_type* data()
65 // Get the underlying endpoint in the native type.
66 const boost::asio::detail::socket_addr_type* data() const
71 // Get the underlying size of the endpoint in the native type.
72 std::size_t size() const
75 return sizeof(boost::asio::detail::sockaddr_in4_type);
77 return sizeof(boost::asio::detail::sockaddr_in6_type);
80 // Set the underlying size of the endpoint in the native type.
81 BOOST_ASIO_DECL void resize(std::size_t new_size);
83 // Get the capacity of the endpoint in the native type.
84 std::size_t capacity() const
89 // Get the port associated with the endpoint.
90 BOOST_ASIO_DECL unsigned short port() const;
92 // Set the port associated with the endpoint.
93 BOOST_ASIO_DECL void port(unsigned short port_num);
95 // Get the IP address associated with the endpoint.
96 BOOST_ASIO_DECL boost::asio::ip::address address() const;
98 // Set the IP address associated with the endpoint.
99 BOOST_ASIO_DECL void address(const boost::asio::ip::address& addr);
101 // Compare two endpoints for equality.
102 BOOST_ASIO_DECL friend bool operator==(
103 const endpoint& e1, const endpoint& e2);
105 // Compare endpoints for ordering.
106 BOOST_ASIO_DECL friend bool operator<(
107 const endpoint& e1, const endpoint& e2);
109 // Determine whether the endpoint is IPv4.
112 return data_.base.sa_family == BOOST_ASIO_OS_DEF(AF_INET);
115 #if !defined(BOOST_ASIO_NO_IOSTREAM)
116 // Convert to a string.
117 BOOST_ASIO_DECL std::string to_string(boost::system::error_code& ec) const;
118 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
121 // The underlying IP socket address.
124 boost::asio::detail::socket_addr_type base;
125 boost::asio::detail::sockaddr_in4_type v4;
126 boost::asio::detail::sockaddr_in6_type v6;
130 } // namespace detail
135 #include <boost/asio/detail/pop_options.hpp>
137 #if defined(BOOST_ASIO_HEADER_ONLY)
138 # include <boost/asio/ip/detail/impl/endpoint.ipp>
139 #endif // defined(BOOST_ASIO_HEADER_ONLY)
141 #endif // BOOST_ASIO_IP_DETAIL_ENDPOINT_HPP