private void EndReceive(UDPSocket socket, Byte[] buffer, Int32 offset, Int32 count, System.Net.EndPoint ep) { #if LOG_UDP_CHANNEL _Log.Debug(m => m("EndReceive: length={0}", count)); #endif if (count > 0) { Byte[] bytes = new Byte[count]; Buffer.BlockCopy(buffer, offset, bytes, 0, count); if (ep.AddressFamily == AddressFamily.InterNetworkV6) { IPEndPoint ipep = (IPEndPoint)ep; if (IPAddressExtensions.IsIPv4MappedToIPv6(ipep.Address)) { ep = new IPEndPoint(IPAddressExtensions.MapToIPv4(ipep.Address), ipep.Port); } } FireDataReceived(bytes, ep); } #if LOG_UDP_CHANNEL _Log.Debug("EndReceive: restart the read"); #endif BeginReceive(socket); }
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); } }
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); }
private void EndReceiveMessage(UDPSocket socket, byte[] buffer, int offset, int count, System.Net.EndPoint ep, IPAddress ipLocal) { #if LOG_UDP_CHANNEL _Log.Debug(m => m("EndReceive: length={0}", count)); #endif if (count > 0) { byte[] bytes = new byte[count]; Buffer.BlockCopy(buffer, offset, bytes, 0, count); if (ep.AddressFamily == AddressFamily.InterNetworkV6) { IPEndPoint ipep = (IPEndPoint)ep; if (IPAddressExtensions.IsIPv4MappedToIPv6(ipep.Address)) { ep = new IPEndPoint(IPAddressExtensions.MapToIPv4(ipep.Address), ipep.Port); } } IPEndPoint epLocal; epLocal = (IPEndPoint)socket.Socket.LocalEndPoint; if (ipLocal != null) { epLocal = new IPEndPoint(ipLocal, epLocal.Port); } if (epLocal.AddressFamily == AddressFamily.InterNetworkV6) { if (IPAddressExtensions.IsIPv4MappedToIPv6(epLocal.Address)) { epLocal = new IPEndPoint(IPAddressExtensions.MapToIPv4(epLocal.Address), epLocal.Port); } } if (!socket.MulticastOnly || IPAddressExtensions.IsMulticastAddress(epLocal.Address)) { FireDataReceived(bytes, ep, epLocal); } } #if LOG_UDP_CHANNEL _Log.Debug("EndReceive: restart the read"); #endif BeginReceive(socket); }