mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-17 02:53:18 +01:00
CID-1116483 cidr to netmask bitshifts guarded with casts
and simple test
This commit is contained in:
parent
2fadfe93dc
commit
f9d5c6918c
@ -921,7 +921,7 @@ public class NetUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getCidrNetmask(final long cidrSize) {
|
public static String getCidrNetmask(final long cidrSize) {
|
||||||
final long numericNetmask = 0xffffffff >> MAX_CIDR - cidrSize << MAX_CIDR - cidrSize;
|
final long numericNetmask = (long)0xffffffff >> MAX_CIDR - cidrSize << MAX_CIDR - cidrSize;
|
||||||
return long2Ip(numericNetmask);
|
return long2Ip(numericNetmask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -419,6 +419,13 @@ public class NetUtilsTest {
|
|||||||
assertTrue("It should pass! 31 bit prefix.", is31PrefixCidr);
|
assertTrue("It should pass! 31 bit prefix.", is31PrefixCidr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetCidrNetMask() {
|
||||||
|
final String cidr = "10.10.0.0/16";
|
||||||
|
String netmask = NetUtils.getCidrNetmask("10.10.10.10/16");
|
||||||
|
assertTrue(cidr + " does not generate valid netmask " + netmask,NetUtils.isValidNetmask(netmask));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCidrSubNet() {
|
public void testGetCidrSubNet() {
|
||||||
final String cidr = "10.10.0.0/16";
|
final String cidr = "10.10.0.0/16";
|
||||||
@ -430,6 +437,6 @@ public class NetUtilsTest {
|
|||||||
public void testGetCidrSubNetWithWidth() {
|
public void testGetCidrSubNetWithWidth() {
|
||||||
final String cidr = "10.10.0.0/16";
|
final String cidr = "10.10.0.0/16";
|
||||||
String subnet = NetUtils.getCidrSubNet("10.10.10.10", 16);
|
String subnet = NetUtils.getCidrSubNet("10.10.10.10", 16);
|
||||||
assertTrue(NetUtils.isIpWithtInCidrRange(subnet, cidr));
|
assertTrue(cidr + " does not contain " + subnet,NetUtils.isIpWithtInCidrRange(subnet, cidr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user