Skip to content

Commit

Permalink
make sure we process PhysicalAddress on Linux (dotnet#42878)
Browse files Browse the repository at this point in the history
  • Loading branch information
wfurt authored Sep 30, 2020
1 parent f63b0c1 commit d52ee3a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public static unsafe NetworkInterface[] GetLinuxNetworkInterfaces()
lni._mtu = nii->Mtu;
lni._supportsMulticast = nii->SupportsMulticast != 0;

if (nii->NumAddressBytes > 0)
{
lni._physicalAddress = new PhysicalAddress(new ReadOnlySpan<byte>(nii->AddressBytes, nii->NumAddressBytes).ToArray());
}

interfaces[i] = lni;
interfacesByIndex.Add(nii->InterfaceIndex, lni);
nii++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public void BasicTest_AccessInstanceProperties_NoExceptions()

_log.WriteLine("SupportsMulticast: " + nic.SupportsMulticast);
_log.WriteLine("GetPhysicalAddress(): " + nic.GetPhysicalAddress());

if (nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
{
Assert.Equal(6, nic.GetPhysicalAddress().GetAddressBytes().Length);
}
}
}

Expand Down Expand Up @@ -81,6 +86,11 @@ public void BasicTest_AccessInstanceProperties_NoExceptions_Linux()

_log.WriteLine("SupportsMulticast: " + nic.SupportsMulticast);
_log.WriteLine("GetPhysicalAddress(): " + nic.GetPhysicalAddress());

if (nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
{
Assert.Equal(6, nic.GetPhysicalAddress().GetAddressBytes().Length);
}
}
}

Expand Down Expand Up @@ -112,6 +122,11 @@ public void BasicTest_AccessInstanceProperties_NoExceptions_Bsd()
// Ethernet, WIFI and loopback should have known status.
Assert.True((nic.OperationalStatus == OperationalStatus.Up) || (nic.OperationalStatus == OperationalStatus.Down));
}

if (nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
{
Assert.Equal(6, nic.GetPhysicalAddress().GetAddressBytes().Length);
}
}
}

Expand Down

0 comments on commit d52ee3a

Please sign in to comment.