Skip to content

Commit

Permalink
Changed GetNetworkInterfaces method to to retrieve information relate…
Browse files Browse the repository at this point in the history
…d to all interfaces (dotnet#100824)

* Add IncludeAllInterfaces as falg to reterive all avaliable interfaces including disabled ones

* Update tests to accommodate new adapters. Ensure adapters reflect proper speeds; non-positive speeds indicates absence of physical address.

* Removed unnecessary assertion

* Add assertion over physical address bytes
  • Loading branch information
MojtabaTajik authored and Ruihan-Yin committed May 30, 2024
1 parent 4d4b477 commit 9aa8c6f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ internal static unsafe NetworkInterface[] GetNetworkInterfaces()
List<SystemNetworkInterface> interfaceList = new List<SystemNetworkInterface>();

Interop.IpHlpApi.GetAdaptersAddressesFlags flags =
Interop.IpHlpApi.GetAdaptersAddressesFlags.IncludeGateways
| Interop.IpHlpApi.GetAdaptersAddressesFlags.IncludeWins;
Interop.IpHlpApi.GetAdaptersAddressesFlags.IncludeAllInterfaces;

// Figure out the right buffer size for the adapter information.
uint result = Interop.IpHlpApi.GetAdaptersAddresses(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public NetworkInterfaceBasicTest(ITestOutputHelper output)
[Fact]
public void BasicTest_GetNetworkInterfaces_AtLeastOne()
{

Assert.NotEqual<int>(0, NetworkInterface.GetAllNetworkInterfaces().Length);
}

Expand Down Expand Up @@ -50,7 +51,8 @@ public void BasicTest_AccessInstanceProperties_NoExceptions()

if (nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
{
Assert.Equal(6, nic.GetPhysicalAddress().GetAddressBytes().Length);
var physicalAddressLength = nic.GetPhysicalAddress().GetAddressBytes().Length;
Assert.True(physicalAddressLength == 0 || physicalAddressLength == 6);
}
}
}
Expand Down

0 comments on commit 9aa8c6f

Please sign in to comment.