GenerateNextAvailableIP fixed
This commit is contained in:
parent
f3ece2fafc
commit
b199054bcf
2 changed files with 42 additions and 23 deletions
|
@ -5,7 +5,7 @@ using System.Web;
|
|||
|
||||
namespace WebsitePanel.EnterpriseServer {
|
||||
|
||||
public struct IPAddress {
|
||||
public struct IPAddress : IComparable {
|
||||
public Int128 Address;
|
||||
public bool V6 { get; private set; }
|
||||
public bool V4 { get { return !V6 || Null; } }
|
||||
|
@ -68,10 +68,19 @@ namespace WebsitePanel.EnterpriseServer {
|
|||
if (Null)
|
||||
return "";
|
||||
var s = new System.Text.StringBuilder();
|
||||
if (!V6) {
|
||||
var ipl = Address;
|
||||
s.Append(String.Format("{0}.{1}.{2}.{3}", (ipl >> 24) & 0xFFL, (ipl >> 16) & 0xFFL, (ipl >> 8) & 0xFFL, (ipl & 0xFFL)));
|
||||
} else if (!IsMask) {
|
||||
if (!V6)
|
||||
{
|
||||
var ipl = Address;
|
||||
if (IsMask)
|
||||
{
|
||||
int digits = 32 - Cidr;
|
||||
ipl = (Int128.MaxValue << 1) | 0x1; // remove left sign bit
|
||||
ipl = ipl << digits;
|
||||
}
|
||||
s.Append(String.Format("{0}.{1}.{2}.{3}", (ipl >> 24) & 0xFFL, (ipl >> 16) & 0xFFL, (ipl >> 8) & 0xFFL, (ipl & 0xFFL)));
|
||||
}
|
||||
else if (!IsMask)
|
||||
{
|
||||
|
||||
var vals = new List<int>();
|
||||
int i;
|
||||
|
@ -181,7 +190,20 @@ namespace WebsitePanel.EnterpriseServer {
|
|||
}
|
||||
|
||||
public static implicit operator IPAddress(NullIPAddress a) { return new IPAddress { Null = true, Address = 0, Cidr = -1 }; }
|
||||
}
|
||||
|
||||
public int CompareTo(object obj)
|
||||
{
|
||||
var a = this.Address;
|
||||
var b = ((IPAddress)obj).Address;
|
||||
|
||||
if (a < b)
|
||||
return 1;
|
||||
else if (a > b)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public class NullIPAddress { }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue