public void Socket_SendToAsyncV4IPEndPointToV4Host_Throws()
{
Socket socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Udp);
SocketAsyncEventArgs args = new SocketAsyncEventArgs();
args.RemoteEndPoint = new IPEndPoint(IPAddress.Loopback, UnusedPort);
args.SetBuffer(new byte[1], 0, 1);
bool async = socket.SendToAsync(args);
Assert.False(async);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Assert.Equal(SocketError.Fault, args.SocketError);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
// NOTE: on Linux, this API returns ENETUNREACH instead of EFAULT: this platform
// checks the family of the provided socket address before checking its size
// (as long as the socket address is large enough to store an address family).
Assert.Equal(SocketError.NetworkUnreachable, args.SocketError);
}
else
{
// NOTE: on other Unix platforms, this API returns EINVAL instead of EFAULT.
Assert.Equal(SocketError.InvalidArgument, args.SocketError);
}
}