Beispiel #1
0
        public void TestFromBytes()
        {
            Action <ulong, ulong, byte[]> testFromBytes = (topHalf, bottomHalf, input) =>
            {
                var addr = IPv6Address.MaybeFromBytes(input).Value;
                Assert.Equal(topHalf, addr.TopHalf);
                Assert.Equal(bottomHalf, addr.BottomHalf);
            };

            testFromBytes(0x0000000000000000ul, 0x0000000000000000ul, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
            testFromBytes(0x0000000000000000ul, 0x0000000000000001ul, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 });
            testFromBytes(0xFE80000000000000ul, 0xA55E55ED0B501E7Eul, new byte[] { 0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA5, 0x5E, 0x55, 0xED, 0x0B, 0x50, 0x1E, 0x7E });
            testFromBytes(0x123456789ABCDEF0ul, 0xFEDCBA9876543210ul, new byte[] { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 });

            Assert.Null(IPv6Address.MaybeFromBytes(new byte[] { 0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA5, 0x5E, 0x55, 0xED, 0x0B, 0x50, 0x1E }));
            Assert.Null(IPv6Address.MaybeFromBytes(new byte[] { 0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA5, 0x5E, 0x55, 0xED, 0x0B, 0x50, 0x1E, 0x7E, 0x99 }));
        }