Exemplo n.º 1
0
        public void TestMapBetweenIPv4AndIPv6()
        {
            for (Byte i = 0; i < Byte.MaxValue; i++)
            {
                IPAddress ipv4 = new IPAddress(new Byte[] { 10, 0, 0, i });
                IPAddress ipv6 = IPAddressExtensions.MapToIPv6(ipv4);
                Assert.IsTrue(IPAddressExtensions.IsIPv4MappedToIPv6(ipv6));

                IPAddress ipv4Mapped = IPAddressExtensions.MapToIPv4(ipv6);
                Assert.AreEqual(ipv4, ipv4Mapped);
            }
        }
Exemplo n.º 2
0
        private void EndReceive(UDPSocket socket, Byte[] buffer, Int32 offset, Int32 count, System.Net.EndPoint ep)
        {
            if (count > 0)
            {
                Byte[] bytes = new Byte[count];
                Buffer.BlockCopy(buffer, 0, bytes, 0, count);

                if (ep.AddressFamily == AddressFamily.InterNetworkV6)
                {
                    IPEndPoint ipep = (IPEndPoint)ep;
                    if (IPAddressExtensions.IsIPv4MappedToIPv6(ipep.Address))
                    {
                        ipep.Address = IPAddressExtensions.MapToIPv4(ipep.Address);
                    }
                }

                FireDataReceived(bytes, ep);
            }

            BeginReceive(socket);
        }