コード例 #1
0
ファイル: IPv4Network.cs プロジェクト: Paul1nh0/Singularity
 public IPv4Network(IPv4 ipNetwork, int maskLength)
 {
     if (maskLength < 0 || maskLength > IPv4.BitCount) {
         throw new ArgumentException();
     }
     this.maskLength = maskLength;
     this.ipNetwork  = ipNetwork & IPv4.NetMask(maskLength);
 }
コード例 #2
0
ファイル: TestIPv4.cs プロジェクト: vmkc/research-environment
        private static void TestBits()
        {
            IPv4 a = new IPv4(0x7f7f7f7f);
            IPv4 b = new IPv4(0xc1c1c1c1);

            if ((uint)(a | b) != ~0U)
            {
                throw new TestFailedException("OR");
            }

            if ((uint)(a & b) != 0x41414141)
            {
                throw new TestFailedException("AND");
            }

            if ((uint)(a ^ b) != 0xbebebebe)
            {
                throw new TestFailedException("XOR");
            }

            if ((uint)(~a) != 0x80808080)
            {
                throw new TestFailedException("NOT");
            }

            if ((uint)IPv4.NetMask(0) != 0)
            {
                throw new TestFailedException("NetMask(0)");
            }

            if ((uint)IPv4.NetMask(17) != 0xffff8000)
            {
                throw new TestFailedException("NetMask(17)");
            }

            if ((uint)IPv4.NetMask(32) != 0xffffffffu)
            {
                throw new TestFailedException("NetMask(32)");
            }

            try {
                IPv4 n = IPv4.NetMask(66);
                throw new TestFailedException("Bad Netmask +");
            }
            catch (ArgumentException) {
            }
            try {
                IPv4 n = IPv4.NetMask(-1);
                throw new TestFailedException("Bad Netmask -");
            }
            catch (ArgumentException) {
            }
        }
コード例 #3
0
ファイル: TestIPv4.cs プロジェクト: vmkc/research-environment
        public static void TestCount()
        {
            for (int i = IPv4.BitCount; i >= 0; i--)
            {
                IPv4 addr = IPv4.NetMask(i);
                if (IPv4.GetMaskLength(addr) != i)
                {
                    throw new TestFailedException(
                              String.Format("TestCount {0}", i)
                              );
                }

                IPv4 addrDup = IPv4.Parse(addr.ToString());
                if (addrDup != addr)
                {
                    throw new TestFailedException(
                              String.Format("TestCountDup {0}", i)
                              );
                }
            }
        }
コード例 #4
0
ファイル: IPv4Network.cs プロジェクト: Paul1nh0/Singularity
 public IPv4Network(IPv4 networkAddress, IPv4 networkMask)
 {
     this.maskLength = IPv4.GetMaskLength(networkMask);
     this.ipNetwork  = networkAddress & IPv4.NetMask(this.maskLength);
 }