dotnet/runtime

SendTo*** and Receive(Message)From*** throw different exceptions when remoteEP AddressFamily does not match

Offen

#47.772 geöffnet am 02.02.2021

 (4 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C# (5.445 Forks)batch import
area-System.Net.Socketsbughelp wanted

Repository-Metriken

Stars
 (17.886 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 12T 11h) (661 gemergte PRs in 30 T)

Beschreibung

If the address family of the remoteEP argument does not match the socket's address family, variants of Receive(Message)From throw an ArgumentException thanks to this guard: https://github.com/dotnet/runtime/blob/4df29c9715659a7957ffeae8b79ba8b52d71ba02/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs#L1710-L1714

SendTo has the same limitation, but we do not guard those methods, instead we let the underlying PAL to fail with a SocketError.InvalidArgument. We may want to change this behavior for consistency.

Also note that the Recive(Message)From exception is undocumented.

Contributor Guide