summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/asio/include/asio/ip/impl/network_v4.ipp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/asio/include/asio/ip/impl/network_v4.ipp')
-rw-r--r--3rdparty/asio/include/asio/ip/impl/network_v4.ipp29
1 files changed, 21 insertions, 8 deletions
diff --git a/3rdparty/asio/include/asio/ip/impl/network_v4.ipp b/3rdparty/asio/include/asio/ip/impl/network_v4.ipp
index ec39aae1c04..e7e68ed443a 100644
--- a/3rdparty/asio/include/asio/ip/impl/network_v4.ipp
+++ b/3rdparty/asio/include/asio/ip/impl/network_v4.ipp
@@ -2,7 +2,7 @@
// ip/impl/network_v4.ipp
// ~~~~~~~~~~~~~~~~~~~~~~
//
-// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2014 Oliver Kowalke (oliver dot kowalke at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -91,7 +91,7 @@ network_v4::network_v4(const address_v4& addr, const address_v4& mask)
}
}
-address_v4 network_v4::netmask() const ASIO_NOEXCEPT
+address_v4 network_v4::netmask() const noexcept
{
uint32_t nmbits = 0xffffffff;
if (prefix_length_ == 0)
@@ -101,7 +101,7 @@ address_v4 network_v4::netmask() const ASIO_NOEXCEPT
return address_v4(nmbits);
}
-address_v4_range network_v4::hosts() const ASIO_NOEXCEPT
+address_v4_range network_v4::hosts() const noexcept
{
return is_host()
? address_v4_range(address_, address_v4(address_.to_uint() + 1))
@@ -126,9 +126,12 @@ std::string network_v4::to_string() const
std::string network_v4::to_string(asio::error_code& ec) const
{
+ using namespace std; // For sprintf.
ec = asio::error_code();
char prefix_len[16];
-#if defined(ASIO_HAS_SECURE_RTL)
+#if defined(ASIO_HAS_SNPRINTF)
+ snprintf(prefix_len, sizeof(prefix_len), "/%u", prefix_length_);
+#elif defined(ASIO_HAS_SECURE_RTL)
sprintf_s(prefix_len, sizeof(prefix_len), "/%u", prefix_length_);
#else // defined(ASIO_HAS_SECURE_RTL)
sprintf(prefix_len, "/%u", prefix_length_);
@@ -178,11 +181,21 @@ network_v4 make_network_v4(const std::string& str,
return network_v4();
}
- return network_v4(make_address_v4(str.substr(0, pos)),
- std::atoi(str.substr(pos + 1).c_str()));
+ const address_v4 addr = make_address_v4(str.substr(0, pos), ec);
+ if (ec)
+ return network_v4();
+
+ const int prefix_len = std::atoi(str.substr(pos + 1).c_str());
+ if (prefix_len < 0 || prefix_len > 32)
+ {
+ ec = asio::error::invalid_argument;
+ return network_v4();
+ }
+
+ return network_v4(addr, static_cast<unsigned short>(prefix_len));
}
-#if defined(ASIO_HAS_STD_STRING_VIEW)
+#if defined(ASIO_HAS_STRING_VIEW)
network_v4 make_network_v4(string_view str)
{
@@ -195,7 +208,7 @@ network_v4 make_network_v4(string_view str,
return make_network_v4(static_cast<std::string>(str), ec);
}
-#endif // defined(ASIO_HAS_STD_STRING_VIEW)
+#endif // defined(ASIO_HAS_STRING_VIEW)
} // namespace ip
} // namespace asio