private ISet IntersectIPRange(byte[] ipWithSubmask1, byte[] ipWithSubmask2)
{
if (ipWithSubmask1.Length != ipWithSubmask2.Length)
{
//Collections.EMPTY_SET;
return new HashSet();
}
byte[][] temp = ExtractIPsAndSubnetMasks(ipWithSubmask1, ipWithSubmask2);
byte[] ip1 = temp[0];
byte[] subnetmask1 = temp[1];
byte[] ip2 = temp[2];
byte[] subnetmask2 = temp[3];
byte[][] minMax = MinMaxIPs(ip1, subnetmask1, ip2, subnetmask2);
byte[] min;
byte[] max;
max = Min(minMax[1], minMax[3]);
min = Max(minMax[0], minMax[2]);
// minimum IP address must be bigger than max
if (CompareTo(min, max) == 1)
{
//return Collections.EMPTY_SET;
return new HashSet();
}
// OR keeps all significant bits
byte[] ip = Or(minMax[0], minMax[2]);
byte[] subnetmask = Or(subnetmask1, subnetmask2);
//return new HashSet( ICollectionsingleton(IpWithSubnetMask(ip, subnetmask));
ISet hs = new HashSet();
hs.Add(IpWithSubnetMask(ip, subnetmask));
return hs;
}