// ip/address_v4.hpp
// ~~~~~~~~~~~~~~~~~
//
-// Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/asio/detail/winsock_init.hpp>
#include <boost/system/error_code.hpp>
+#if defined(BOOST_ASIO_HAS_STD_HASH)
+# include <functional>
+#endif // defined(BOOST_ASIO_HAS_STD_HASH)
+
#if !defined(BOOST_ASIO_NO_IOSTREAM)
# include <iosfwd>
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
#endif
/// Default constructor.
+ /**
+ * Initialises the @c address_v4 object such that:
+ * @li <tt>to_bytes()</tt> yields <tt>{0, 0, 0, 0}</tt>; and
+ * @li <tt>to_uint() == 0</tt>.
+ */
address_v4() BOOST_ASIO_NOEXCEPT
{
addr_.s_addr = 0;
}
/// Construct an address from raw bytes.
+ /**
+ * Initialises the @c address_v4 object such that <tt>to_bytes() ==
+ * bytes</tt>.
+ *
+ * @throws out_of_range Thrown if any element in @c bytes is not in the range
+ * <tt>0 - 0xFF</tt>. Note that no range checking is required for platforms
+ * where <tt>std::numeric_limits<unsigned char>::max()</tt> is <tt>0xFF</tt>.
+ */
BOOST_ASIO_DECL explicit address_v4(const bytes_type& bytes);
/// Construct an address from an unsigned integer in host byte order.
+ /**
+ * Initialises the @c address_v4 object such that <tt>to_uint() == addr</tt>.
+ */
BOOST_ASIO_DECL explicit address_v4(uint_type addr);
/// Copy constructor.
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
/// Determine whether the address is a loopback address.
+ /**
+ * This function tests whether the address is in the address block
+ * <tt>127.0.0.0/8</tt>, which corresponds to the address range
+ * <tt>127.0.0.0 - 127.255.255.255</tt>.
+ *
+ * @returns <tt>(to_uint() & 0xFF000000) == 0x7F000000</tt>.
+ */
BOOST_ASIO_DECL bool is_loopback() const BOOST_ASIO_NOEXCEPT;
/// Determine whether the address is unspecified.
+ /**
+ * This function tests whether the address is the unspecified address
+ * <tt>0.0.0.0</tt>.
+ *
+ * @returns <tt>to_uint() == 0</tt>.
+ */
BOOST_ASIO_DECL bool is_unspecified() const BOOST_ASIO_NOEXCEPT;
#if !defined(BOOST_ASIO_NO_DEPRECATED)
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
/// Determine whether the address is a multicast address.
+ /**
+ * This function tests whether the address is in the multicast address block
+ * <tt>224.0.0.0/4</tt>, which corresponds to the address range
+ * <tt>224.0.0.0 - 239.255.255.255</tt>.
+ *
+ * @returns <tt>(to_uint() & 0xF0000000) == 0xE0000000</tt>.
+ */
BOOST_ASIO_DECL bool is_multicast() const BOOST_ASIO_NOEXCEPT;
/// Compare two addresses for equality.
}
/// Compare addresses for ordering.
+ /**
+ * Compares two addresses in host byte order.
+ *
+ * @returns <tt>a1.to_uint() < a2.to_uint()</tt>.
+ */
friend bool operator<(const address_v4& a1,
const address_v4& a2) BOOST_ASIO_NOEXCEPT
{
}
/// Compare addresses for ordering.
+ /**
+ * Compares two addresses in host byte order.
+ *
+ * @returns <tt>a1.to_uint() > a2.to_uint()</tt>.
+ */
friend bool operator>(const address_v4& a1,
const address_v4& a2) BOOST_ASIO_NOEXCEPT
{
}
/// Compare addresses for ordering.
+ /**
+ * Compares two addresses in host byte order.
+ *
+ * @returns <tt>a1.to_uint() <= a2.to_uint()</tt>.
+ */
friend bool operator<=(const address_v4& a1,
const address_v4& a2) BOOST_ASIO_NOEXCEPT
{
}
/// Compare addresses for ordering.
+ /**
+ * Compares two addresses in host byte order.
+ *
+ * @returns <tt>a1.to_uint() >= a2.to_uint()</tt>.
+ */
friend bool operator>=(const address_v4& a1,
const address_v4& a2) BOOST_ASIO_NOEXCEPT
{
}
/// Obtain an address object that represents any address.
+ /**
+ * This functions returns an address that represents the "any" address
+ * <tt>0.0.0.0</tt>.
+ *
+ * @returns A default-constructed @c address_v4 object.
+ */
static address_v4 any() BOOST_ASIO_NOEXCEPT
{
return address_v4();
}
/// Obtain an address object that represents the loopback address.
+ /**
+ * This function returns an address that represents the well-known loopback
+ * address <tt>127.0.0.1</tt>.
+ *
+ * @returns <tt>address_v4(0x7F000001)</tt>.
+ */
static address_v4 loopback() BOOST_ASIO_NOEXCEPT
{
return address_v4(0x7F000001);
}
/// Obtain an address object that represents the broadcast address.
+ /**
+ * This function returns an address that represents the broadcast address
+ * <tt>255.255.255.255</tt>.
+ *
+ * @returns <tt>address_v4(0xFFFFFFFF)</tt>.
+ */
static address_v4 broadcast() BOOST_ASIO_NOEXCEPT
{
return address_v4(0xFFFFFFFF);
} // namespace asio
} // namespace boost
+#if defined(BOOST_ASIO_HAS_STD_HASH)
+namespace std {
+
+template <>
+struct hash<boost::asio::ip::address_v4>
+{
+ std::size_t operator()(const boost::asio::ip::address_v4& addr)
+ const BOOST_ASIO_NOEXCEPT
+ {
+ return std::hash<unsigned int>()(addr.to_uint());
+ }
+};
+
+} // namespace std
+#endif // defined(BOOST_ASIO_HAS_STD_HASH)
+
#include <boost/asio/detail/pop_options.hpp>
#include <boost/asio/ip/impl/address_v4.hpp>