-
Notifications
You must be signed in to change notification settings - Fork 5.2k
fix ReceiveFrom with dual mode socket #92086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,9 +155,9 @@ public override EndPoint Create(SocketAddress socketAddress) | |
| { | ||
| ArgumentNullException.ThrowIfNull(socketAddress); | ||
|
|
||
| if (socketAddress.Family != AddressFamily) | ||
| if (socketAddress.Family != AddressFamily.InterNetwork && socketAddress.Family != AddressFamily.InterNetworkV6) | ||
| { | ||
| throw new ArgumentException(SR.Format(SR.net_InvalidAddressFamily, socketAddress.Family.ToString(), GetType().FullName, AddressFamily.ToString()), nameof(socketAddress)); | ||
| throw new ArgumentException(SR.Format(SR.net_InvalidAddressFamily, socketAddress.Family.ToString(), GetType().FullName), nameof(socketAddress)); | ||
| } | ||
|
|
||
| int minSize = AddressFamily == AddressFamily.InterNetworkV6 ? SocketAddress.IPv6AddressSize : SocketAddress.IPv4AddressSize; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're no longer requiring that socketAddress.Family == AddressFamily, does this size check still matter?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to but than we can possibly get exception when we access the underlying buffer and it is too small. So I feel the extra check provides better feedback. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -927,13 +927,13 @@ internal void FinishOperationSyncSuccess(int bytesTransferred, SocketFlags flags | |
| { | ||
| try | ||
| { | ||
| if (_remoteEndPoint!.AddressFamily == _socketAddress!.Family) | ||
| if (_remoteEndPoint!.AddressFamily == AddressFamily.InterNetworkV6 && _socketAddress!.Family == AddressFamily.InterNetwork) | ||
| { | ||
| _remoteEndPoint = _remoteEndPoint!.Create(_socketAddress); | ||
| _remoteEndPoint = new IPEndPoint(_socketAddress.GetIPAddress().MapToIPv6(), _socketAddress.GetPort()); | ||
| } | ||
|
Comment on lines
+930
to
933
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this something IPEndPoint.Create(SocketAddress) should be doing instead of doing it at this one call site?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this one is tricky - we have cases when the address is IPv4 and |
||
| else if (_remoteEndPoint!.AddressFamily == AddressFamily.InterNetworkV6 && _socketAddress.Family == AddressFamily.InterNetwork) | ||
| else | ||
| { | ||
| _remoteEndPoint = new IPEndPoint(_socketAddress.GetIPAddress().MapToIPv6(), _socketAddress.GetPort()); | ||
| _remoteEndPoint = _remoteEndPoint!.Create(_socketAddress!); | ||
| } | ||
| } | ||
| catch | ||
|
|
@@ -949,7 +949,14 @@ internal void FinishOperationSyncSuccess(int bytesTransferred, SocketFlags flags | |
| { | ||
| try | ||
| { | ||
| _remoteEndPoint = _remoteEndPoint!.Create(_socketAddress!); | ||
| if (_remoteEndPoint!.AddressFamily == AddressFamily.InterNetworkV6 && _socketAddress!.Family == AddressFamily.InterNetwork) | ||
| { | ||
| _remoteEndPoint = new IPEndPoint(_socketAddress.GetIPAddress().MapToIPv6(), _socketAddress.GetPort()); | ||
| } | ||
| else | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly here: if this logic were moved into IPEndPoint.Create, would that a) address the duplication between these two call sites and b) potentially avoid bugs elsewhere? Or would that introduce problems? |
||
| { | ||
| _remoteEndPoint = _remoteEndPoint!.Create(_socketAddress!); | ||
| } | ||
| } | ||
| catch | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.