: asV6().isLoopback();
}
+ // Return true if the address qualifies as link local
+ bool isLinkLocal() const {
+ return isV4() ? asV4().isLinkLocal()
+ : asV6().isLinkLocal();
+ }
+
// Return true if the address qualifies as broadcast.
bool isLinkLocalBroadcast() const {
return isV4() ? asV4().isLinkLocalBroadcast()
return (mask == subMask);
}
+// public
bool IPAddressV4::isLoopback() const {
static IPAddressV4 loopback_addr("127.0.0.0");
return inSubnetWithMask(loopback_addr, fetchMask(8));
}
+// public
+bool IPAddressV4::isLinkLocal() const {
+ static IPAddressV4 linklocal_addr("169.254.0.0");
+ return inSubnetWithMask(linklocal_addr, fetchMask(16));
+}
+
// public
bool IPAddressV4::isNonroutable() const {
auto ip = toLongHBO();
TEST_P(IPAddressFlagTest, IsLinkLocal) {
AddressFlags param = GetParam();
- if (param.version != 6) {
- return;
- }
- IPAddressV6 addr(param.address);
+ IPAddress addr(param.address);
EXPECT_EQ(param.isLinkLocal(), addr.isLinkLocal()) << addr;
}
AddressFlags("127.0.0.1", 4, IS_LOCAL | IS_PVT_NONROUTE),
AddressFlags("::1", 6, IS_LOCAL | IS_PVT_NONROUTE),
+ // link-local v4
+ AddressFlags("169.254.0.1", 4, IS_LINK_LOCAL | IS_PVT_NONROUTE),
+
// private v4
AddressFlags("10.0.0.0", 4, IS_PVT_NONROUTE),
AddressFlags("10.11.12.13", 4, IS_PVT_NONROUTE),
AddressFlags("10.255.255.255", 4, IS_PVT_NONROUTE),
AddressFlags("127.128.129.200", 4, IS_LOCAL | IS_PVT_NONROUTE),
AddressFlags("127.255.255.255", 4, IS_LOCAL | IS_PVT_NONROUTE),
- AddressFlags("169.254.0.0", 4, IS_PVT_NONROUTE),
+ AddressFlags("169.254.0.0", 4, IS_LINK_LOCAL | IS_PVT_NONROUTE),
AddressFlags("192.168.0.0", 4, IS_PVT_NONROUTE),
AddressFlags("192.168.200.255", 4, IS_PVT_NONROUTE),
AddressFlags("192.168.255.255", 4, IS_PVT_NONROUTE),