public IPEndPointStruct ToIPEndPoint(IPAddress reuseAddress = null) { if (Family == AddressFamily.InterNetwork) { long value; fixed(byte *address = Address) { value = ((address[3] << 24 | address[2] << 16 | address[1] << 8 | address[0]) & 0x0FFFFFFFF); } bool matchesReuseAddress = reuseAddress != null && reuseAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork && reuseAddress.Address == value; return(new IPEndPointStruct(matchesReuseAddress ? reuseAddress : new IPAddress(value), Port)); } else if (Family == AddressFamily.InterNetworkV6) { // We can't check if we can use reuseAddress without allocating. const int length = 16; var bytes = new byte[length]; fixed(byte *address = Address) { for (int i = 0; i < length; i++) { bytes[i] = address[i]; } } return(new IPEndPointStruct(new IPAddress(bytes, ScopeId), Port)); } else { var result = new PosixResult(PosixResult.EAFNOSUPPORT); throw result.AsException(); } }
public IPEndPoint ToIPEndPoint() { if (Family == AddressFamily.InterNetwork) { long value; fixed(byte *address = Address) { value = ((address[3] << 24 | address[2] << 16 | address[1] << 8 | address[0]) & 0x0FFFFFFFF); } return(new IPEndPoint(new IPAddress(value), Port)); } else if (Family == AddressFamily.InterNetworkV6) { const int length = 16; var bytes = new byte[length]; fixed(byte *address = Address) { for (int i = 0; i < length; i++) { bytes[i] = address[i]; } } return(new IPEndPoint(new IPAddress(bytes, ScopeId), Port)); } else { var result = new PosixResult(PosixResult.EAFNOSUPPORT); throw result.AsException(); } }