Fix UdpClient.EnableBroadcast not preventing broadcast sends#124482
Open
MatanTsach wants to merge 2 commits intodotnet:mainfrom
Open
Fix UdpClient.EnableBroadcast not preventing broadcast sends#124482MatanTsach wants to merge 2 commits intodotnet:mainfrom
MatanTsach wants to merge 2 commits intodotnet:mainfrom
Conversation
When a user explicitly sets EnableBroadcast to false, CheckForBroadcast() should respect that choice and not auto-enable the broadcast socket option. Fixes dotnet#118055 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Group related broadcast fields together, following the existing convention in UDPClient.cs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
This was referenced Feb 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #118055
UdpClient.CheckForBroadcast()unconditionally auto-enables theBroadcastsocket option when sending toIPAddress.Broadcast, even when the user has explicitly setEnableBroadcast = false. This PR makesCheckForBroadcast()respect the user's explicit choice.Changes
_isBroadcastSetByUserfield to track whetherEnableBroadcasthas been explicitly set by the userCheckForBroadcast()to skip auto-enable when the user has explicitly setEnableBroadcastNote: The pre-existing
_isBroadcastflag is not reset when theClientsocket is replaced via the property setter. The new_isBroadcastSetByUserflag follows this same pattern for consistency. Resetting state on socket replacement could be a follow-up improvement.Testing
EnableBroadcast_ExplicitlyDisabled_NotAutoEnabled— verifies that explicitly disabling broadcast prevents auto-enable on broadcast sendEnableBroadcast_ExplicitlyEnabledThenDisabled_NotAutoEnabled— verifies the toggle case (enable → disable) also prevents auto-enableEnableBroadcast_NotExplicitlySet_AutoEnabled— verifies backward compatibility: auto-enable still works when the user hasn't set the property