-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
NetworkInterface.GetAllNetworkInterfaces()
doesn't list disabled adapters on Windows
#89990
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsDescriptionOn Windows, a disabled network adapter is not listed by Reproduction Steps
Expected behaviorThe disabled adapter is listed with Actual behaviorThe disabled adapter is not listed. Regression?No response Known WorkaroundsNo response ConfigurationWindows 11 Other informationNo response
|
.NET returns what GetAdapterAddresses OS function gives us back: Lines 103 to 117 in e2b5936
I assume that the function does not list disabled interfaces and that's why you don't see them. Not critical for 8.0, moving to Future. |
We should verify what |
It depends on the "flags" parameter we asked for "GetAdaptersAddresses" The current .Net implementation is: Lines 88 to 91 in e2b5936
Based on Windows API docs, we need to pass "GAA_FLAG_INCLUDE_ALL_INTERFACES" as flag, if we want information of all adapters: Then the received "IP_ADAPTER_ADDRESSES_LH" structure contains "OperStatus", which indicates the enabled state of the adapter. |
@wfurt I want to pick this ticket up. |
What does it do on Linux/Mac? |
I don't think the concept is the same. You can do |
@wfurt I fixed the issue and updated one of the tests because of that change. Based on the documentation of GetAdaptersAddresses, this change will retrieve even those addresses associated with adapters not bound to an address family specified in the Family parameter.
Maybe to make it more fancy, we can add an optional parameter with the default value for backward compatibility like this: internal static unsafe NetworkInterface[] GetNetworkInterfaces(Interop.IpHlpApi.GetAdaptersAddressesFlags flags =Interop.IpHlpApi.GetAdaptersAddressesFlags.IncludeAllInterfaces)
{
} This modification allows developers to choose interface types according to their preferences while ensuring backward compatibility by providing a default value for the flags parameter. |
Description
On Windows, a disabled network adapter is not listed by
NetworkInterface.GetAllNetworkInterfaces()
.Reproduction Steps
Expected behavior
The disabled adapter is listed with
OperationalStatus.Down
.Actual behavior
The disabled adapter is not listed.
Regression?
No response
Known Workarounds
No response
Configuration
Windows 10
.NET 6 / .NET 7
Other information
No response
The text was updated successfully, but these errors were encountered: