// address_v4.cpp
// ~~~~~~~~~~~~~~
//
-// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2017 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)
b = addr1.is_unspecified();
(void)b;
+#if !defined(BOOST_ASIO_NO_DEPRECATED)
b = addr1.is_class_a();
(void)b;
b = addr1.is_class_c();
(void)b;
+#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
b = addr1.is_multicast();
(void)b;
ip::address_v4::bytes_type bytes_value = addr1.to_bytes();
(void)bytes_value;
+ ip::address_v4::uint_type uint_value = addr1.to_uint();
+ (void)uint_value;
+
+#if !defined(BOOST_ASIO_NO_DEPRECATED)
unsigned long ulong_value = addr1.to_ulong();
(void)ulong_value;
+#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
std::string string_value = addr1.to_string();
+#if !defined(BOOST_ASIO_NO_DEPRECATED)
string_value = addr1.to_string(ec);
+#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
// address_v4 static functions.
+#if !defined(BOOST_ASIO_NO_DEPRECATED)
addr1 = ip::address_v4::from_string("127.0.0.1");
addr1 = ip::address_v4::from_string("127.0.0.1", ec);
addr1 = ip::address_v4::from_string(string_value);
addr1 = ip::address_v4::from_string(string_value, ec);
+#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
addr1 = ip::address_v4::any();
addr1 = ip::address_v4::broadcast();
+#if !defined(BOOST_ASIO_NO_DEPRECATED)
addr1 = ip::address_v4::broadcast(addr2, addr3);
addr1 = ip::address_v4::netmask(addr2);
+#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
// address_v4 comparisons.
b = (addr1 >= addr2);
(void)b;
+ // address_v4 creation functions.
+
+ addr1 = ip::make_address_v4(const_bytes_value);
+ addr1 = ip::make_address_v4(const_ulong_value);
+ addr1 = ip::make_address_v4("127.0.0.1");
+ addr1 = ip::make_address_v4("127.0.0.1", ec);
+ addr1 = ip::make_address_v4(string_value);
+ addr1 = ip::make_address_v4(string_value, ec);
+#if defined(BOOST_ASIO_HAS_STD_STRING_VIEW)
+# if defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
+ std::experimental::string_view string_view_value("127.0.0.1");
+# else // defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
+ std::string_view string_view_value("127.0.0.1");
+# endif // defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
+ addr1 = ip::make_address_v4(string_view_value);
+ addr1 = ip::make_address_v4(string_view_value, ec);
+#endif // defined(BOOST_ASIO_HAS_STD_STRING_VIEW)
+
// address_v4 I/O.
std::ostringstream os;
BOOST_ASIO_CHECK(a1.to_bytes()[1] == 0);
BOOST_ASIO_CHECK(a1.to_bytes()[2] == 0);
BOOST_ASIO_CHECK(a1.to_bytes()[3] == 0);
+ BOOST_ASIO_CHECK(a1.to_uint() == 0);
+#if !defined(BOOST_ASIO_NO_DEPRECATED)
BOOST_ASIO_CHECK(a1.to_ulong() == 0);
+#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
address_v4::bytes_type b1 = {{ 1, 2, 3, 4 }};
address_v4 a2(b1);
BOOST_ASIO_CHECK(a2.to_bytes()[1] == 2);
BOOST_ASIO_CHECK(a2.to_bytes()[2] == 3);
BOOST_ASIO_CHECK(a2.to_bytes()[3] == 4);
+ BOOST_ASIO_CHECK(((a2.to_uint() >> 24) & 0xFF) == b1[0]);
+ BOOST_ASIO_CHECK(((a2.to_uint() >> 16) & 0xFF) == b1[1]);
+ BOOST_ASIO_CHECK(((a2.to_uint() >> 8) & 0xFF) == b1[2]);
+ BOOST_ASIO_CHECK((a2.to_uint() & 0xFF) == b1[3]);
+#if !defined(BOOST_ASIO_NO_DEPRECATED)
BOOST_ASIO_CHECK(((a2.to_ulong() >> 24) & 0xFF) == b1[0]);
BOOST_ASIO_CHECK(((a2.to_ulong() >> 16) & 0xFF) == b1[1]);
BOOST_ASIO_CHECK(((a2.to_ulong() >> 8) & 0xFF) == b1[2]);
BOOST_ASIO_CHECK((a2.to_ulong() & 0xFF) == b1[3]);
+#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
address_v4 a3(0x01020304);
BOOST_ASIO_CHECK(a3.to_bytes()[0] == 1);
BOOST_ASIO_CHECK(a3.to_bytes()[1] == 2);
BOOST_ASIO_CHECK(a3.to_bytes()[2] == 3);
BOOST_ASIO_CHECK(a3.to_bytes()[3] == 4);
+ BOOST_ASIO_CHECK(a3.to_uint() == 0x01020304);
+#if !defined(BOOST_ASIO_NO_DEPRECATED)
BOOST_ASIO_CHECK(a3.to_ulong() == 0x01020304);
+#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
BOOST_ASIO_CHECK(address_v4(0x7F000001).is_loopback());
BOOST_ASIO_CHECK(address_v4(0x7F000002).is_loopback());
BOOST_ASIO_CHECK(!address_v4(0x7F000001).is_unspecified());
BOOST_ASIO_CHECK(!address_v4(0x01020304).is_unspecified());
+#if !defined(BOOST_ASIO_NO_DEPRECATED)
BOOST_ASIO_CHECK(address_v4(0x01000000).is_class_a());
BOOST_ASIO_CHECK(address_v4(0x7F000000).is_class_a());
BOOST_ASIO_CHECK(!address_v4(0x80000000).is_class_a());
BOOST_ASIO_CHECK(!address_v4(0xEFFFFFFF).is_class_c());
BOOST_ASIO_CHECK(!address_v4(0xF0000000).is_class_c());
BOOST_ASIO_CHECK(!address_v4(0xFFFFFFFF).is_class_c());
+#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
BOOST_ASIO_CHECK(!address_v4(0x01000000).is_multicast());
BOOST_ASIO_CHECK(!address_v4(0x7F000000).is_multicast());
BOOST_ASIO_CHECK(a4.to_bytes()[1] == 0);
BOOST_ASIO_CHECK(a4.to_bytes()[2] == 0);
BOOST_ASIO_CHECK(a4.to_bytes()[3] == 0);
+ BOOST_ASIO_CHECK(a4.to_uint() == 0);
+#if !defined(BOOST_ASIO_NO_DEPRECATED)
BOOST_ASIO_CHECK(a4.to_ulong() == 0);
+#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
address_v4 a5 = address_v4::loopback();
BOOST_ASIO_CHECK(a5.to_bytes()[0] == 0x7F);
BOOST_ASIO_CHECK(a5.to_bytes()[1] == 0);
BOOST_ASIO_CHECK(a5.to_bytes()[2] == 0);
BOOST_ASIO_CHECK(a5.to_bytes()[3] == 0x01);
+ BOOST_ASIO_CHECK(a5.to_uint() == 0x7F000001);
+#if !defined(BOOST_ASIO_NO_DEPRECATED)
BOOST_ASIO_CHECK(a5.to_ulong() == 0x7F000001);
+#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
address_v4 a6 = address_v4::broadcast();
BOOST_ASIO_CHECK(a6.to_bytes()[0] == 0xFF);
BOOST_ASIO_CHECK(a6.to_bytes()[1] == 0xFF);
BOOST_ASIO_CHECK(a6.to_bytes()[2] == 0xFF);
BOOST_ASIO_CHECK(a6.to_bytes()[3] == 0xFF);
+ BOOST_ASIO_CHECK(a6.to_uint() == 0xFFFFFFFF);
+#if !defined(BOOST_ASIO_NO_DEPRECATED)
BOOST_ASIO_CHECK(a6.to_ulong() == 0xFFFFFFFF);
+#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
+#if !defined(BOOST_ASIO_NO_DEPRECATED)
address_v4 class_a_net(0xFF000000);
address_v4 class_b_net(0xFFFF0000);
address_v4 class_c_net(0xFFFFFF00);
BOOST_ASIO_CHECK(address_v4::netmask(address_v4(0xEFFFFFFF)) == other_net);
BOOST_ASIO_CHECK(address_v4::netmask(address_v4(0xF0000000)) == other_net);
BOOST_ASIO_CHECK(address_v4::netmask(address_v4(0xFFFFFFFF)) == other_net);
+#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
}
} // namespace ip_address_v4_runtime