Rename address_v4's to_ulong() to to_uint() and add uint_type typedef.
diff --git a/asio/include/asio/detail/cstdint.hpp b/asio/include/asio/detail/cstdint.hpp index 8d5ad57..5bb7c24 100644 --- a/asio/include/asio/detail/cstdint.hpp +++ b/asio/include/asio/detail/cstdint.hpp
@@ -27,19 +27,31 @@ #if defined(ASIO_HAS_CSTDINT) using std::int16_t; +using std::int_least16_t; using std::uint16_t; +using std::uint_least16_t; using std::int32_t; +using std::int_least32_t; using std::uint32_t; +using std::uint_least32_t; using std::int64_t; +using std::int_least64_t; using std::uint64_t; +using std::uint_least64_t; using std::uintmax_t; #else // defined(ASIO_HAS_CSTDINT) using boost::int16_t; +using boost::int_least16_t; using boost::uint16_t; +using boost::uint_least16_t; using boost::int32_t; +using boost::int_least32_t; using boost::uint32_t; +using boost::uint_least32_t; using boost::int64_t; +using boost::int_least64_t; using boost::uint64_t; +using boost::uint_least64_t; using boost::uintmax_t; #endif // defined(ASIO_HAS_CSTDINT)
diff --git a/asio/include/asio/ip/address_v4.hpp b/asio/include/asio/ip/address_v4.hpp index eeb22e9..71aafc4 100644 --- a/asio/include/asio/ip/address_v4.hpp +++ b/asio/include/asio/ip/address_v4.hpp
@@ -18,6 +18,7 @@ #include "asio/detail/config.hpp" #include <string> #include "asio/detail/array.hpp" +#include "asio/detail/cstdint.hpp" #include "asio/detail/socket_types.hpp" #include "asio/detail/winsock_init.hpp" #include "asio/error_code.hpp" @@ -43,6 +44,9 @@ class address_v4 { public: + /// The type used to represent an address as an unsigned integer. + typedef uint_least32_t uint_type; + /// The type used to represent an address as an array of bytes. /** * @note This type is defined in terms of the C++0x template @c std::array @@ -63,8 +67,8 @@ /// Construct an address from raw bytes. ASIO_DECL explicit address_v4(const bytes_type& bytes); - /// Construct an address from an unsigned long in host byte order. - ASIO_DECL explicit address_v4(unsigned long addr); + /// Construct an address from an unsigned integer in host byte order. + ASIO_DECL explicit address_v4(uint_type addr); /// Copy constructor. address_v4(const address_v4& other) @@ -99,8 +103,13 @@ /// Get the address in bytes, in network byte order. ASIO_DECL bytes_type to_bytes() const; + /// Get the address as an unsigned integer in host byte order + ASIO_DECL uint_type to_uint() const; + +#if !defined(ASIO_NO_DEPRECATED) /// Get the address as an unsigned long in host byte order ASIO_DECL unsigned long to_ulong() const; +#endif // !defined(ASIO_NO_DEPRECATED) /// Get the address as a string in dotted decimal format. ASIO_DECL std::string to_string() const; @@ -167,25 +176,25 @@ /// Compare addresses for ordering. friend bool operator<(const address_v4& a1, const address_v4& a2) { - return a1.to_ulong() < a2.to_ulong(); + return a1.to_uint() < a2.to_uint(); } /// Compare addresses for ordering. friend bool operator>(const address_v4& a1, const address_v4& a2) { - return a1.to_ulong() > a2.to_ulong(); + return a1.to_uint() > a2.to_uint(); } /// Compare addresses for ordering. friend bool operator<=(const address_v4& a1, const address_v4& a2) { - return a1.to_ulong() <= a2.to_ulong(); + return a1.to_uint() <= a2.to_uint(); } /// Compare addresses for ordering. friend bool operator>=(const address_v4& a1, const address_v4& a2) { - return a1.to_ulong() >= a2.to_ulong(); + return a1.to_uint() >= a2.to_uint(); } /// Obtain an address object that represents any address. @@ -232,11 +241,11 @@ return address_v4(bytes); } -/// Create an IPv4 address from an unsigned long in host byte order. +/// Create an IPv4 address from an unsigned integer in host byte order. /** * @relates address_v4 */ -inline address_v4 make_address_v4(unsigned long addr) +inline address_v4 make_address_v4(address_v4::uint_type addr) { return address_v4(addr); }
diff --git a/asio/include/asio/ip/address_v4_iterator.hpp b/asio/include/asio/ip/address_v4_iterator.hpp index 9defad9..a7bbf88 100644 --- a/asio/include/asio/ip/address_v4_iterator.hpp +++ b/asio/include/asio/ip/address_v4_iterator.hpp
@@ -106,7 +106,7 @@ /// Pre-increment operator. basic_address_iterator& operator++() ASIO_NOEXCEPT { - address_ = address_v4((address_.to_ulong() + 1) & 0xFFFFFFFF); + address_ = address_v4((address_.to_uint() + 1) & 0xFFFFFFFF); return *this; } @@ -121,7 +121,7 @@ /// Pre-decrement operator. basic_address_iterator& operator--() ASIO_NOEXCEPT { - address_ = address_v4((address_.to_ulong() - 1) & 0xFFFFFFFF); + address_ = address_v4((address_.to_uint() - 1) & 0xFFFFFFFF); return *this; }
diff --git a/asio/include/asio/ip/address_v4_range.hpp b/asio/include/asio/ip/address_v4_range.hpp index 159705e..7f172cb 100644 --- a/asio/include/asio/ip/address_v4_range.hpp +++ b/asio/include/asio/ip/address_v4_range.hpp
@@ -109,7 +109,7 @@ /// Return the size of the range. std::size_t size() const ASIO_NOEXCEPT { - return end_->to_ulong() - begin_->to_ulong(); + return end_->to_uint() - begin_->to_uint(); } /// Find an address in the range.
diff --git a/asio/include/asio/ip/detail/impl/endpoint.ipp b/asio/include/asio/ip/detail/impl/endpoint.ipp index 25b2343..2a5e335 100644 --- a/asio/include/asio/ip/detail/impl/endpoint.ipp +++ b/asio/include/asio/ip/detail/impl/endpoint.ipp
@@ -80,7 +80,7 @@ asio::detail::socket_ops::host_to_network_short(port_num); data_.v4.sin_addr.s_addr = asio::detail::socket_ops::host_to_network_long( - addr.to_v4().to_ulong()); + addr.to_v4().to_uint()); } else {
diff --git a/asio/include/asio/ip/detail/socket_option.hpp b/asio/include/asio/ip/detail/socket_option.hpp index 93a9017..c3912b7 100644 --- a/asio/include/asio/ip/detail/socket_option.hpp +++ b/asio/include/asio/ip/detail/socket_option.hpp
@@ -407,10 +407,10 @@ { ipv4_value_.imr_multiaddr.s_addr = asio::detail::socket_ops::host_to_network_long( - multicast_address.to_v4().to_ulong()); + multicast_address.to_v4().to_uint()); ipv4_value_.imr_interface.s_addr = asio::detail::socket_ops::host_to_network_long( - address_v4::any().to_ulong()); + address_v4::any().to_uint()); } } @@ -421,10 +421,10 @@ { ipv4_value_.imr_multiaddr.s_addr = asio::detail::socket_ops::host_to_network_long( - multicast_address.to_ulong()); + multicast_address.to_uint()); ipv4_value_.imr_interface.s_addr = asio::detail::socket_ops::host_to_network_long( - network_interface.to_ulong()); + network_interface.to_uint()); } // Construct with multicast address and IPv6 network interface index. @@ -493,7 +493,7 @@ { ipv4_value_.s_addr = asio::detail::socket_ops::host_to_network_long( - address_v4::any().to_ulong()); + address_v4::any().to_uint()); ipv6_value_ = 0; } @@ -502,7 +502,7 @@ { ipv4_value_.s_addr = asio::detail::socket_ops::host_to_network_long( - ipv4_interface.to_ulong()); + ipv4_interface.to_uint()); ipv6_value_ = 0; } @@ -511,7 +511,7 @@ { ipv4_value_.s_addr = asio::detail::socket_ops::host_to_network_long( - address_v4::any().to_ulong()); + address_v4::any().to_uint()); ipv6_value_ = ipv6_interface; }
diff --git a/asio/include/asio/ip/impl/address_v4.ipp b/asio/include/asio/ip/impl/address_v4.ipp index 7d7056f..c6ee4c9 100644 --- a/asio/include/asio/ip/impl/address_v4.ipp +++ b/asio/include/asio/ip/impl/address_v4.ipp
@@ -17,6 +17,7 @@ #include "asio/detail/config.hpp" #include <climits> +#include <limits> #include <stdexcept> #include "asio/error.hpp" #include "asio/detail/socket_ops.hpp" @@ -44,15 +45,13 @@ memcpy(&addr_.s_addr, bytes.data(), 4); } -address_v4::address_v4(unsigned long addr) +address_v4::address_v4(address_v4::uint_type addr) { -#if ULONG_MAX > 0xFFFFFFFF - if (addr > 0xFFFFFFFF) + if ((std::numeric_limits<uint_type>::max)() > 0xFFFFFFFF) { - std::out_of_range ex("address_v4 from unsigned long"); + std::out_of_range ex("address_v4 from unsigned integer"); asio::detail::throw_exception(ex); } -#endif // ULONG_MAX > 0xFFFFFFFF addr_.s_addr = asio::detail::socket_ops::host_to_network_long( static_cast<asio::detail::u_long_type>(addr)); @@ -70,10 +69,17 @@ return bytes; } +address_v4::uint_type address_v4::to_uint() const +{ + return asio::detail::socket_ops::network_to_host_long(addr_.s_addr); +} + +#if !defined(ASIO_NO_DEPRECATED) unsigned long address_v4::to_ulong() const { return asio::detail::socket_ops::network_to_host_long(addr_.s_addr); } +#endif // !defined(ASIO_NO_DEPRECATED) std::string address_v4::to_string() const { @@ -104,40 +110,40 @@ bool address_v4::is_loopback() const { - return (to_ulong() & 0xFF000000) == 0x7F000000; + return (to_uint() & 0xFF000000) == 0x7F000000; } bool address_v4::is_unspecified() const { - return to_ulong() == 0; + return to_uint() == 0; } #if !defined(ASIO_NO_DEPRECATED) bool address_v4::is_class_a() const { - return (to_ulong() & 0x80000000) == 0; + return (to_uint() & 0x80000000) == 0; } bool address_v4::is_class_b() const { - return (to_ulong() & 0xC0000000) == 0x80000000; + return (to_uint() & 0xC0000000) == 0x80000000; } bool address_v4::is_class_c() const { - return (to_ulong() & 0xE0000000) == 0xC0000000; + return (to_uint() & 0xE0000000) == 0xC0000000; } #endif // !defined(ASIO_NO_DEPRECATED) bool address_v4::is_multicast() const { - return (to_ulong() & 0xF0000000) == 0xE0000000; + return (to_uint() & 0xF0000000) == 0xE0000000; } #if !defined(ASIO_NO_DEPRECATED) address_v4 address_v4::broadcast(const address_v4& addr, const address_v4& mask) { - return address_v4(addr.to_ulong() | (mask.to_ulong() ^ 0xFFFFFFFF)); + return address_v4(addr.to_uint() | (mask.to_uint() ^ 0xFFFFFFFF)); } address_v4 address_v4::netmask(const address_v4& addr)
diff --git a/asio/include/asio/ip/impl/network_v4.ipp b/asio/include/asio/ip/impl/network_v4.ipp index b508ae2..079d13f 100644 --- a/asio/include/asio/ip/impl/network_v4.ipp +++ b/asio/include/asio/ip/impl/network_v4.ipp
@@ -104,8 +104,8 @@ address_v4_range network_v4::hosts() const ASIO_NOEXCEPT { return is_host() - ? address_v4_range(address_, address_v4(address_.to_ulong() + 1)) - : address_v4_range(address_v4(network().to_ulong() + 1), broadcast()); + ? address_v4_range(address_, address_v4(address_.to_uint() + 1)) + : address_v4_range(address_v4(network().to_uint() + 1), broadcast()); } bool network_v4::is_subnet_of(const network_v4& other) const
diff --git a/asio/include/asio/ip/network_v4.hpp b/asio/include/asio/ip/network_v4.hpp index 71d9ddd..ec45548 100644 --- a/asio/include/asio/ip/network_v4.hpp +++ b/asio/include/asio/ip/network_v4.hpp
@@ -106,14 +106,13 @@ /// Obtain an address object that represents the network address. address_v4 network() const ASIO_NOEXCEPT { - return address_v4(address_.to_ulong() & netmask().to_ulong()); + return address_v4(address_.to_uint() & netmask().to_uint()); } /// Obtain an address object that represents the network's broadcast address. address_v4 broadcast() const ASIO_NOEXCEPT { - return address_v4(network().to_ulong() - | (netmask().to_ulong() ^ 0xFFFFFFFF)); + return address_v4(network().to_uint() | (netmask().to_uint() ^ 0xFFFFFFFF)); } /// Obtain an address range corresponding to the hosts in the network.