Fix: Detect local IP address (& 169.254) as fallback when routing is not available#3288
Merged
mergify[bot] merged 10 commits intomainfrom Dec 28, 2025
Merged
Fix: Detect local IP address (& 169.254) as fallback when routing is not available#3288mergify[bot] merged 10 commits intomainfrom
mergify[bot] merged 10 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request enhances the network interface detection logic to support fallback mechanisms when standard routing-based detection fails. The main improvement allows the application to detect local IP addresses from active network interfaces, including link-local addresses (169.254.x.x), addressing issue #3277 where users with static link-local IP configurations encountered errors.
Key changes:
- Added new fallback method
DetectLocalIPAddressFromNetworkInterfacethat iterates through operational network interfaces, preferring non-link-local addresses for IPv4 - Refactored method names for clarity (e.g.,
DetectLocalIPAddressBasedOnRouting→DetectLocalIPAddressFromRouting,DetectGatewayBasedOnLocalIPAddress→DetectGatewayFromLocalIPAddress) - Modernized collection initializations using C# collection expressions
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| Source/NETworkManager.Models/Network/NetworkInterface.cs | Added new fallback method for detecting local IP addresses from network interfaces; renamed existing detection methods for consistency; improved documentation; modernized collection syntax |
| Source/NETworkManager/ViewModels/IPScannerViewModel.cs | Integrated fallback IP detection mechanism in subnet detection; refactored method name from DetectIPRange to DetectSubnet |
| Source/NETworkManager/ViewModels/NetworkConnectionWidgetViewModel.cs | Updated method calls to use renamed gateway detection method |
| Website/docs/application/ip-scanner.md | Added documentation explaining the fallback mechanism for local IP detection |
| Website/docs/changelog/next-release.md | Added changelog entry describing the improved subnet detection feature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return ipAddress.Address; | ||
| } | ||
| catch (SocketException) | ||
| catch (SocketException) { } |
There was a problem hiding this comment.
Poor error handling: empty catch block.
Suggested change
| catch (SocketException) { } | |
| catch (SocketException ex) | |
| { | |
| System.Diagnostics.Debug.WriteLine($"DetectLocalIPAddressFromRouting: SocketException while determining local IP for remote address '{remoteIPAddress}': {ex}"); | |
| } |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Changes proposed in this pull request
Related issue(s)
Copilot generated summary
Provide a Copilot generated summary of the changes in this pull request.
Copilot summary
This pull request refactors and improves the detection and handling of local IP addresses and gateways in the network interface logic, modernizes collection initializations, and clarifies method names and documentation. The changes also enhance subnet detection in the IP scanner view model and ensure more robust fallback mechanisms.
Major improvements and refactoring:
NetworkInterfacefor clarity and consistency (e.g.,DetectLocalIPAddressBasedOnRoutingAsync→DetectLocalIPAddressFromRoutingAsync,DetectGatewayBasedOnLocalIPAddressAsync→DetectGatewayFromLocalIPAddressAsync). Enhanced documentation to clarify return values and behaviors, and improved error handling to returnnullinstead of throwing exceptions. [1] [2] [3] [4]Modernization and code quality:
[.. list]and[]), simplifying and modernizing the codebase. [1] [2]Subnet and IP detection logic improvements:
IPScannerViewModelto use the new fallback mechanism for local IP detection, and to more robustly extract subnet information from detected network interfaces. Improved error handling and user feedback when detection fails. [1] [2]Code organization:
UserHasCanceledevent and its handler to the end of theNetworkInterfaceclass for better code organization. [1] [2]Other minor changes:
using System.Diagnostics;statement, possibly for future debugging purposes.These changes collectively improve code clarity, maintainability, and robustness, especially around network interface and subnet detection logic.
To-Do
Contributing
By submitting this pull request, I confirm the following: