public void SetNetMaskTest()
        {
            NetworkAddressIPv4 test = new NetworkAddressIPv4();

            test.SetNetMask(255, 255, 255, 0);
            Assert.AreEqual(24, test.GetNetmask());

            test.SetNetMask(128, 0, 0, 0);
            Assert.AreEqual(1, test.GetNetmask());

            test.SetNetMask(255, 128, 0, 0);
            Assert.AreEqual(9, test.GetNetmask());

            test.SetNetMask("255.255.255.0");
            Assert.AreEqual(24, test.GetNetmask());

            test.SetNetMask("128.0.0.0");
            Assert.AreEqual(1, test.GetNetmask());

            test.SetNetMask("255.128.0.0");
            Assert.AreEqual(9, test.GetNetmask());

            try
            {
                test.SetNetMask(127, 0, 0, 0);
                test.SetNetMask(128, 1, 0, 0);
                test.SetNetMask(255, 128, 4, 0);
                test.SetNetMask(255, 255, 3, 0);

                Assert.Fail();
            }
            catch (IPAddressNotValid)
            {

            }
        }
예제 #2
0
 public void SetIPV4Address(NetworkAddressIPv4 ip)
 {
     this.IPv4Address = ip;
 }
예제 #3
0
        public void SetIPv4Address(string address, string gateway = null, int netMask = 0)
        {
            if (this.IPv4Address == null)
                this.IPv4Address = new NetworkAddressIPv4();

            this.IPv4Address.SetAddress(address);

            if (gateway != null)
                this.IPv4Address.SetGateway(gateway);

            if (netMask != 0)
                this.IPv4Address.SetNetMask(netMask);
        }