public void Test() { DHCPConfig config = BasicConfig(); config.Netmask = "128.0.0.0"; config.IPBase = "128.0.0.0"; config.ReservedIPs = new DHCPConfig.ReservedIP[1]; config.ReservedIPs[0] = new DHCPConfig.ReservedIP(); config.ReservedIPs[0].IPBase = "130.0.0.0"; config.ReservedIPs[0].Mask = "255.0.0.0"; TestDhcpServer ds = new TestDhcpServer(config); byte[] ip = new byte[4] { 128, 0, 0, 1 }; Assert.IsFalse(ds.ValidIP(ip), "Server IP"); ip[0] = 129; Assert.IsTrue(ds.ValidIP(ip), "Non-Server IP"); ip = new byte[4] { 130, 0, 0, 0 }; ip[0] = 130; byte[] inc = ds.IncrementIP(ip); ip[0] = 131; Assert.AreEqual(MemBlock.Reference(ip), MemBlock.Reference(inc), "Invalid IPs before the first valid one"); ip[0] = 255; ip[1] = 255; ip[2] = 255; ip[3] = 254; inc = ds.IncrementIP(ip); ip[0] = 128; ip[1] = 0; ip[2] = 0; ip[3] = 2; Assert.AreEqual(MemBlock.Reference(ip), MemBlock.Reference(inc), "Skip broadcast and server"); ip[0] = 127; Assert.IsFalse(ds.ValidIP(ip), "Out of range - 127"); ip[0] = 0; Assert.IsFalse(ds.ValidIP(ip), "Out of range - 0"); Assert.IsTrue(ds.ValidIP(ds.RandomIPAddress()), "Random"); }
public void Test() { DHCPConfig config = BasicConfig(); config.Netmask = "128.0.0.0"; config.IPBase = "128.0.0.0"; config.ReservedIPs = new DHCPConfig.ReservedIP[1]; config.ReservedIPs[0] = new DHCPConfig.ReservedIP(); config.ReservedIPs[0].IPBase = "130.0.0.0"; config.ReservedIPs[0].Mask = "255.0.0.0"; TestDhcpServer ds = new TestDhcpServer(config); byte[] ip = new byte[4] { 128, 0, 0, 1}; Assert.IsFalse(ds.ValidIP(ip), "Server IP"); ip[0] = 129; Assert.IsTrue(ds.ValidIP(ip), "Non-Server IP"); ip = new byte[4] { 130, 0, 0, 0}; ip[0] = 130; byte[] inc = ds.IncrementIP(ip); ip[0] = 131; Assert.AreEqual(MemBlock.Reference(ip), MemBlock.Reference(inc), "Invalid IPs before the first valid one"); ip[0] = 255; ip[1] = 255; ip[2] = 255; ip[3] = 254; inc = ds.IncrementIP(ip); ip[0] = 128; ip[1] = 0; ip[2] = 0; ip[3] = 2; Assert.AreEqual(MemBlock.Reference(ip), MemBlock.Reference(inc), "Skip broadcast and server"); ip[0] = 127; Assert.IsFalse(ds.ValidIP(ip), "Out of range - 127"); ip[0] = 0; Assert.IsFalse(ds.ValidIP(ip), "Out of range - 0"); Assert.IsTrue(ds.ValidIP(ds.RandomIPAddress()), "Random"); }