summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/asio/include/asio/ip/address_v6.hpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/asio/include/asio/ip/address_v6.hpp')
-rw-r--r--3rdparty/asio/include/asio/ip/address_v6.hpp161
1 files changed, 116 insertions, 45 deletions
diff --git a/3rdparty/asio/include/asio/ip/address_v6.hpp b/3rdparty/asio/include/asio/ip/address_v6.hpp
index 663601d4c4d..aa650825cf3 100644
--- a/3rdparty/asio/include/asio/ip/address_v6.hpp
+++ b/3rdparty/asio/include/asio/ip/address_v6.hpp
@@ -2,7 +2,7 @@
// ip/address_v6.hpp
// ~~~~~~~~~~~~~~~~~
//
-// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2024 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)
@@ -16,8 +16,10 @@
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
+#include <functional>
#include <string>
#include "asio/detail/array.hpp"
+#include "asio/detail/cstdint.hpp"
#include "asio/detail/socket_types.hpp"
#include "asio/detail/string_view.hpp"
#include "asio/detail/winsock_init.hpp"
@@ -35,6 +37,9 @@ namespace ip {
template <typename> class basic_address_iterator;
+/// Type used for storing IPv6 scope IDs.
+typedef uint_least32_t scope_id_type;
+
/// Implements IP version 6 style addresses.
/**
* The asio::ip::address_v6 class provides the ability to use and
@@ -59,33 +64,44 @@ public:
#endif
/// Default constructor.
- ASIO_DECL address_v6();
+ /**
+ * Initialises the @c address_v6 object such that:
+ * @li <tt>to_bytes()</tt> yields <tt>{0, 0, ..., 0}</tt>; and
+ * @li <tt>scope_id() == 0</tt>.
+ */
+ ASIO_DECL address_v6() noexcept;
/// Construct an address from raw bytes and scope ID.
+ /**
+ * Initialises the @c address_v6 object such that:
+ * @li <tt>to_bytes() == bytes</tt>; and
+ * @li <tt>this->scope_id() == scope_id</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>.
+ */
ASIO_DECL explicit address_v6(const bytes_type& bytes,
- unsigned long scope_id = 0);
+ scope_id_type scope_id = 0);
/// Copy constructor.
- ASIO_DECL address_v6(const address_v6& other);
+ ASIO_DECL address_v6(const address_v6& other) noexcept;
-#if defined(ASIO_HAS_MOVE)
/// Move constructor.
- ASIO_DECL address_v6(address_v6&& other);
-#endif // defined(ASIO_HAS_MOVE)
+ ASIO_DECL address_v6(address_v6&& other) noexcept;
/// Assign from another address.
- ASIO_DECL address_v6& operator=(const address_v6& other);
+ ASIO_DECL address_v6& operator=(
+ const address_v6& other) noexcept;
-#if defined(ASIO_HAS_MOVE)
/// Move-assign from another address.
- ASIO_DECL address_v6& operator=(address_v6&& other);
-#endif // defined(ASIO_HAS_MOVE)
+ ASIO_DECL address_v6& operator=(address_v6&& other) noexcept;
/// The scope ID of the address.
/**
* Returns the scope ID associated with the IPv6 address.
*/
- unsigned long scope_id() const
+ scope_id_type scope_id() const noexcept
{
return scope_id_;
}
@@ -93,14 +109,16 @@ public:
/// The scope ID of the address.
/**
* Modifies the scope ID associated with the IPv6 address.
+ *
+ * @param id The new scope ID.
*/
- void scope_id(unsigned long id)
+ void scope_id(scope_id_type id) noexcept
{
scope_id_ = id;
}
/// Get the address in bytes, in network byte order.
- ASIO_DECL bytes_type to_bytes() const;
+ ASIO_DECL bytes_type to_bytes() const noexcept;
/// Get the address as a string.
ASIO_DECL std::string to_string() const;
@@ -133,19 +151,27 @@ public:
#endif // !defined(ASIO_NO_DEPRECATED)
/// Determine whether the address is a loopback address.
- ASIO_DECL bool is_loopback() const;
+ /**
+ * This function tests whether the address is the loopback address
+ * <tt>::1</tt>.
+ */
+ ASIO_DECL bool is_loopback() const noexcept;
/// Determine whether the address is unspecified.
- ASIO_DECL bool is_unspecified() const;
+ /**
+ * This function tests whether the address is the loopback address
+ * <tt>::</tt>.
+ */
+ ASIO_DECL bool is_unspecified() const noexcept;
/// Determine whether the address is link local.
- ASIO_DECL bool is_link_local() const;
+ ASIO_DECL bool is_link_local() const noexcept;
/// Determine whether the address is site local.
- ASIO_DECL bool is_site_local() const;
+ ASIO_DECL bool is_site_local() const noexcept;
/// Determine whether the address is a mapped IPv4 address.
- ASIO_DECL bool is_v4_mapped() const;
+ ASIO_DECL bool is_v4_mapped() const noexcept;
#if !defined(ASIO_NO_DEPRECATED)
/// (Deprecated: No replacement.) Determine whether the address is an
@@ -154,63 +180,77 @@ public:
#endif // !defined(ASIO_NO_DEPRECATED)
/// Determine whether the address is a multicast address.
- ASIO_DECL bool is_multicast() const;
+ ASIO_DECL bool is_multicast() const noexcept;
/// Determine whether the address is a global multicast address.
- ASIO_DECL bool is_multicast_global() const;
+ ASIO_DECL bool is_multicast_global() const noexcept;
/// Determine whether the address is a link-local multicast address.
- ASIO_DECL bool is_multicast_link_local() const;
+ ASIO_DECL bool is_multicast_link_local() const noexcept;
/// Determine whether the address is a node-local multicast address.
- ASIO_DECL bool is_multicast_node_local() const;
+ ASIO_DECL bool is_multicast_node_local() const noexcept;
/// Determine whether the address is a org-local multicast address.
- ASIO_DECL bool is_multicast_org_local() const;
+ ASIO_DECL bool is_multicast_org_local() const noexcept;
/// Determine whether the address is a site-local multicast address.
- ASIO_DECL bool is_multicast_site_local() const;
+ ASIO_DECL bool is_multicast_site_local() const noexcept;
/// Compare two addresses for equality.
- ASIO_DECL friend bool operator==(
- const address_v6& a1, const address_v6& a2);
+ ASIO_DECL friend bool operator==(const address_v6& a1,
+ const address_v6& a2) noexcept;
/// Compare two addresses for inequality.
- friend bool operator!=(const address_v6& a1, const address_v6& a2)
+ friend bool operator!=(const address_v6& a1,
+ const address_v6& a2) noexcept
{
return !(a1 == a2);
}
/// Compare addresses for ordering.
- ASIO_DECL friend bool operator<(
- const address_v6& a1, const address_v6& a2);
+ ASIO_DECL friend bool operator<(const address_v6& a1,
+ const address_v6& a2) noexcept;
/// Compare addresses for ordering.
- friend bool operator>(const address_v6& a1, const address_v6& a2)
+ friend bool operator>(const address_v6& a1,
+ const address_v6& a2) noexcept
{
return a2 < a1;
}
/// Compare addresses for ordering.
- friend bool operator<=(const address_v6& a1, const address_v6& a2)
+ friend bool operator<=(const address_v6& a1,
+ const address_v6& a2) noexcept
{
return !(a2 < a1);
}
/// Compare addresses for ordering.
- friend bool operator>=(const address_v6& a1, const address_v6& a2)
+ friend bool operator>=(const address_v6& a1,
+ const address_v6& a2) noexcept
{
return !(a1 < a2);
}
/// Obtain an address object that represents any address.
- static address_v6 any()
+ /**
+ * This functions returns an address that represents the "any" address
+ * <tt>::</tt>.
+ *
+ * @returns A default-constructed @c address_v6 object.
+ */
+ static address_v6 any() noexcept
{
return address_v6();
}
/// Obtain an address object that represents the loopback address.
- ASIO_DECL static address_v6 loopback();
+ /**
+ * This function returns an address that represents the well-known loopback
+ * address <tt>::1</tt>.
+ */
+ ASIO_DECL static address_v6 loopback() noexcept;
#if !defined(ASIO_NO_DEPRECATED)
/// (Deprecated: Use make_address_v6().) Create an IPv4-mapped IPv6 address.
@@ -227,7 +267,7 @@ private:
asio::detail::in6_addr_type addr_;
// The scope ID associated with the address.
- unsigned long scope_id_;
+ scope_id_type scope_id_;
};
/// Create an IPv6 address from raw bytes and scope ID.
@@ -235,7 +275,7 @@ private:
* @relates address_v6
*/
inline address_v6 make_address_v6(const address_v6::bytes_type& bytes,
- unsigned long scope_id = 0)
+ scope_id_type scope_id = 0)
{
return address_v6(bytes, scope_id);
}
@@ -250,8 +290,8 @@ ASIO_DECL address_v6 make_address_v6(const char* str);
/**
* @relates address_v6
*/
-ASIO_DECL address_v6 make_address_v6(
- const char* str, asio::error_code& ec);
+ASIO_DECL address_v6 make_address_v6(const char* str,
+ asio::error_code& ec) noexcept;
/// Createan IPv6 address from an IP address string.
/**
@@ -263,10 +303,10 @@ ASIO_DECL address_v6 make_address_v6(const std::string& str);
/**
* @relates address_v6
*/
-ASIO_DECL address_v6 make_address_v6(
- const std::string& str, asio::error_code& ec);
+ASIO_DECL address_v6 make_address_v6(const std::string& str,
+ asio::error_code& ec) noexcept;
-#if defined(ASIO_HAS_STD_STRING_VIEW) \
+#if defined(ASIO_HAS_STRING_VIEW) \
|| defined(GENERATING_DOCUMENTATION)
/// Create an IPv6 address from an IP address string.
@@ -279,10 +319,10 @@ ASIO_DECL address_v6 make_address_v6(string_view str);
/**
* @relates address_v6
*/
-ASIO_DECL address_v6 make_address_v6(
- string_view str, asio::error_code& ec);
+ASIO_DECL address_v6 make_address_v6(string_view str,
+ asio::error_code& ec) noexcept;
-#endif // defined(ASIO_HAS_STD_STRING_VIEW)
+#endif // defined(ASIO_HAS_STRING_VIEW)
// || defined(GENERATING_DOCUMENTATION)
/// Tag type used for distinguishing overloads that deal in IPv4-mapped IPv6
@@ -326,6 +366,37 @@ std::basic_ostream<Elem, Traits>& operator<<(
} // namespace ip
} // namespace asio
+namespace std {
+
+template <>
+struct hash<asio::ip::address_v6>
+{
+ std::size_t operator()(const asio::ip::address_v6& addr)
+ const noexcept
+ {
+ const asio::ip::address_v6::bytes_type bytes = addr.to_bytes();
+ std::size_t result = static_cast<std::size_t>(addr.scope_id());
+ combine_4_bytes(result, &bytes[0]);
+ combine_4_bytes(result, &bytes[4]);
+ combine_4_bytes(result, &bytes[8]);
+ combine_4_bytes(result, &bytes[12]);
+ return result;
+ }
+
+private:
+ static void combine_4_bytes(std::size_t& seed, const unsigned char* bytes)
+ {
+ const std::size_t bytes_hash =
+ (static_cast<std::size_t>(bytes[0]) << 24) |
+ (static_cast<std::size_t>(bytes[1]) << 16) |
+ (static_cast<std::size_t>(bytes[2]) << 8) |
+ (static_cast<std::size_t>(bytes[3]));
+ seed ^= bytes_hash + 0x9e3779b9 + (seed << 6) + (seed >> 2);
+ }
+};
+
+} // namespace std
+
#include "asio/detail/pop_options.hpp"
#include "asio/ip/impl/address_v6.hpp"