return isV6() && asV6().isIPv4Mapped();
}
+ // @return true if address is uninitialized
+ bool empty() const { return (family_ == AF_UNSPEC); }
+
+ // @return true if address is initialized
+ explicit operator bool() { return !empty(); }
+
// @return true if this is an IPAddressV4 instance
bool isV4() const { return (family_ == AF_INET); }
EXPECT_EQ(4, sizeof(IPAddressV4));
EXPECT_EQ(16, sizeof(IPAddressV6));
EXPECT_EQ(20, sizeof(IPAddress));
+ IPAddress uninitaddr;
IPAddress v4addr("192.0.2.129");
IPAddress v6map("::ffff:192.0.2.129");
+ ASSERT_TRUE(uninitaddr.empty());
+ ASSERT_FALSE(v4addr.empty());
+ ASSERT_FALSE(v6map.empty());
EXPECT_TRUE(v4addr.inSubnet("192.0.2.0/24"));
EXPECT_TRUE(v4addr.inSubnet(IPAddress("192.0.2.0"), 24));
EXPECT_TRUE(v4addr.inSubnet("192.0.2.128/30"));
EXPECT_FALSE(v4addr.inSubnet("192.0.2.128/32"));
EXPECT_EQ(2164392128, v4addr.asV4().toLong());
EXPECT_EQ(3221226113, v4addr.asV4().toLongHBO());
+ ASSERT_FALSE(uninitaddr.isV4());
+ ASSERT_FALSE(uninitaddr.isV6());
ASSERT_TRUE(v4addr.isV4());
ASSERT_TRUE(v6map.isV6());
EXPECT_TRUE(v4addr == v6map);