Skip to content
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

Win32_NetworkAdapter: use PhysicalAdapter to check whether the NIC IsVirtual #292

Merged
merged 1 commit into from
Nov 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Win32_NetworkAdapter: use PhysicalAdapter to check whether the NIC Is…
…Virtual

Signed-off-by: Lukas Hartl <60550303+lukashartl@users.noreply.github.com>
  • Loading branch information
lukashartl committed Nov 27, 2021
commit 63794b90c3b3237d755f22e3ade562dd8ee54efe
13 changes: 11 additions & 2 deletions pkg/net/net_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/StackExchange/wmi"
)

const wqlNetworkAdapter = "SELECT Description, DeviceID, Index, InterfaceIndex, MACAddress, Manufacturer, Name, NetConnectionID, ProductName, ServiceName FROM Win32_NetworkAdapter"
const wqlNetworkAdapter = "SELECT Description, DeviceID, Index, InterfaceIndex, MACAddress, Manufacturer, Name, NetConnectionID, ProductName, ServiceName, PhysicalAdapter FROM Win32_NetworkAdapter"

type win32NetworkAdapter struct {
Description *string
Expand All @@ -24,6 +24,7 @@ type win32NetworkAdapter struct {
NetConnectionID *string
ProductName *string
ServiceName *string
PhysicalAdapter *bool
}

func (i *Info) load() error {
Expand All @@ -44,7 +45,7 @@ func nics(win32NetDescriptions []win32NetworkAdapter) []*NIC {
nic := &NIC{
Name: netDeviceName(nicDescription),
MacAddress: *nicDescription.MACAddress,
IsVirtual: false,
IsVirtual: netIsVirtual(nicDescription),
Capabilities: []*NICCapability{},
}
// Appenging NIC to NICs
Expand All @@ -63,3 +64,11 @@ func netDeviceName(description win32NetworkAdapter) string {
}
return name
}

func netIsVirtual(description win32NetworkAdapter) bool {
if description.PhysicalAdapter == nil {
return false
}

return !(*description.PhysicalAdapter)
}