Example #1
0
        private void BeginSend()
        {
            if (_running == 0)
            {
                return;
            }

            RawData raw;

            if (!_sendingQueue.TryDequeue(out raw))
            {
                System.Threading.Interlocked.Exchange(ref _writing, 0);
                return;
            }

            UDPSocket  socket   = _socket;
            IPEndPoint remoteEP = (IPEndPoint)raw.EndPoint;

            if (remoteEP.AddressFamily == AddressFamily.InterNetwork)
            {
                if (_socketBackup != null)
                {
                    // use the separated socket of IPv4 to deal with IPv4 conversions.
                    socket = _socketBackup;
                }
                else if (_socket.Socket.AddressFamily == AddressFamily.InterNetworkV6)
                {
                    remoteEP = new IPEndPoint(IPAddressExtensions.MapToIPv6(remoteEP.Address), remoteEP.Port);
                }
            }

            BeginSend(socket, raw.Data, remoteEP);
        }
Example #2
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);
            }
        }
Example #3
0
        public void TestNoMapping()
        {
            IPAddress ipv4  = new IPAddress(new byte[] { 10, 0, 0, 5 });
            IPAddress ipv4X = IPAddressExtensions.MapToIPv4(ipv4);

            Assert.AreEqual(ipv4, ipv4X);

            IPAddress ipv6  = IPAddress.Parse("[2001:0db8:ac10:fe01::]");
            IPAddress ipv6X = IPAddressExtensions.MapToIPv6(ipv6);

            Assert.AreEqual(ipv6, ipv6X);
        }