Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Bug 1419531 - Use network device description for display name on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
josejulio authored and spinder committed Sep 6, 2017
1 parent d6ef9ce commit c54ca90
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,19 @@ public List<NetworkAdapterInfo> getAllNetworkAdapters() throws SystemInfoExcepti
String[] interfaceNames = sigar.getNetInterfaceList();

if (interfaceNames != null) {
NetworkAdapterInfo.DisplayName displayName = NetworkAdapterInfo.DisplayName.FROM_NAME;
// If Sigar can't get the adapter name it just starts naming the network adapters as eth0, eth1, etc.
// This can be confusing on Windows, so we switch to their description
// All references should be the same, as we are are only changing the displayName
if (this.getOperatingSystemType() == OperatingSystemType.WINDOWS) {
displayName = NetworkAdapterInfo.DisplayName.FROM_DESCRIPTION;
}
for (String interfaceName : interfaceNames) {
if (interfaceName.indexOf(':') != -1) {
continue; //filter out virtual IPs
}

adapters.add(new NetworkAdapterInfo(sigar.getNetInterfaceConfig(interfaceName)));
adapters.add(new NetworkAdapterInfo(sigar.getNetInterfaceConfig(interfaceName), displayName));
}
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public static enum OperationState {
UP, DOWN, TESTING, UNKNOWN, DORMANT, NOTPRESENT, LOWERLAYERDOWN
}

public enum DisplayName {
FROM_NAME,
FROM_DESCRIPTION
}

public NetworkAdapterInfo(String name, String displayName, String description, String macAddress, String type,
String operationalStatus, Boolean dhcpEnabled, List<InetAddress> dnsServers,
List<InetAddress> unicastAddresses, List<InetAddress> multicastAddresses) {
Expand All @@ -72,14 +77,26 @@ public NetworkAdapterInfo(String name, String displayName, String description, S
}

public NetworkAdapterInfo(NetInterfaceConfig a) {
this(a, DisplayName.FROM_NAME);
}

public NetworkAdapterInfo(NetInterfaceConfig a, DisplayName displayName) {
long flags = a.getFlags();
NetworkAdapterInfo.OperationState state = NetworkAdapterInfo.OperationState.UP;
if ((flags & NetFlags.IFF_UP) <= 0) {
state = NetworkAdapterInfo.OperationState.DOWN;
}

this.name = a.getName();
this.displayName = a.getName();
switch(displayName) {
case FROM_DESCRIPTION:
this.displayName = a.getDescription();
break;
case FROM_NAME:
default:
this.displayName = a.getName();
break;
}
this.description = a.getDescription();
this.macAddress = a.getHwaddr();
this.type = a.getType();
Expand Down

0 comments on commit c54ca90

Please sign in to comment.