Skip to content

Commit a165520

Browse files
author
Ravi Nadahar
committed
Fix network interface configuration option enumeration
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
1 parent b7c742f commit a165520

1 file changed

Lines changed: 7 additions & 16 deletions

File tree

bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/net/NetworkConfigOptionProvider.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
package org.openhab.core.config.core.internal.net;
1414

1515
import java.net.Inet4Address;
16-
import java.net.InetAddress;
1716
import java.net.NetworkInterface;
1817
import java.net.SocketException;
1918
import java.net.URI;
@@ -22,6 +21,7 @@
2221
import java.util.Enumeration;
2322
import java.util.List;
2423
import java.util.Locale;
24+
import java.util.Objects;
2525
import java.util.stream.Stream;
2626

2727
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -30,6 +30,7 @@
3030
import org.openhab.core.config.core.ParameterOption;
3131
import org.openhab.core.net.CidrAddress;
3232
import org.openhab.core.net.NetUtil;
33+
import org.openhab.core.util.StringUtils;
3334
import org.osgi.service.component.annotations.Component;
3435

3536
/**
@@ -67,8 +68,10 @@ public class NetworkConfigOptionProvider implements ConfigOptionProvider {
6768
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
6869
while (networkInterfaces.hasMoreElements()) {
6970
NetworkInterface networkInterface = networkInterfaces.nextElement();
70-
options.add(new ParameterOption(networkInterface.getName(),
71-
getNetworkInterfaceLabel(networkInterface)));
71+
if (networkInterface.isUp()) {
72+
options.add(new ParameterOption(networkInterface.getName(),
73+
getNetworkInterfaceLabel(networkInterface)));
74+
}
7275
}
7376
return options;
7477
} catch (SocketException e) {
@@ -80,18 +83,6 @@ public class NetworkConfigOptionProvider implements ConfigOptionProvider {
8083
}
8184

8285
private String getNetworkInterfaceLabel(NetworkInterface networkInterface) {
83-
Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
84-
String hostName = null;
85-
while (inetAddresses.hasMoreElements()) {
86-
InetAddress inetAddress = inetAddresses.nextElement();
87-
if (inetAddress instanceof Inet4Address) {
88-
hostName = inetAddress.getHostName();
89-
break;
90-
} else if (hostName == null) {
91-
hostName = inetAddress.getHostName();
92-
}
93-
}
94-
return hostName == null ? networkInterface.getName()
95-
: String.format("%s (%s)", networkInterface.getName(), hostName);
86+
return Objects.requireNonNull(StringUtils.capitalizeByWhitespace(networkInterface.getName().replace('_', ' ')));
9687
}
9788
}

0 commit comments

Comments
 (0)