From 8d5c5d09791fccf57713ae97ca55ebd140c51bbd Mon Sep 17 00:00:00 2001 From: lsiepel Date: Sun, 13 Oct 2024 13:40:02 +0200 Subject: [PATCH] Remove apache (#17409) Signed-off-by: Leo Siepel --- .../discovery/RioSystemDiscovery.java | 55 +++---------------- 1 file changed, 8 insertions(+), 47 deletions(-) diff --git a/bundles/org.openhab.binding.russound/src/main/java/org/openhab/binding/russound/internal/discovery/RioSystemDiscovery.java b/bundles/org.openhab.binding.russound/src/main/java/org/openhab/binding/russound/internal/discovery/RioSystemDiscovery.java index 16818119d7dd7..c400389b63d74 100644 --- a/bundles/org.openhab.binding.russound/src/main/java/org/openhab/binding/russound/internal/discovery/RioSystemDiscovery.java +++ b/bundles/org.openhab.binding.russound/src/main/java/org/openhab/binding/russound/internal/discovery/RioSystemDiscovery.java @@ -13,13 +13,8 @@ package org.openhab.binding.russound.internal.discovery; import java.io.IOException; -import java.net.Inet6Address; -import java.net.InterfaceAddress; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.util.Collections; +import java.net.InetAddress; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -27,7 +22,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import org.apache.commons.net.util.SubnetUtils; import org.openhab.binding.russound.internal.net.SocketChannelSession; import org.openhab.binding.russound.internal.net.SocketSession; import org.openhab.binding.russound.internal.net.WaitingSessionListener; @@ -37,6 +31,7 @@ import org.openhab.core.config.discovery.DiscoveryResult; import org.openhab.core.config.discovery.DiscoveryResultBuilder; import org.openhab.core.config.discovery.DiscoveryService; +import org.openhab.core.net.NetUtil; import org.openhab.core.thing.ThingUID; import org.osgi.service.component.annotations.Component; import org.slf4j.Logger; @@ -78,48 +73,14 @@ public RioSystemDiscovery() { */ @Override protected void startScan() { - final List interfaces; - try { - interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); - } catch (SocketException e1) { - logger.debug("Exception getting network interfaces: {}", e1.getMessage(), e1); - return; - } - - nbrNetworkInterfacesScanning = interfaces.size(); + List addressesToScan = NetUtil.getFullRangeOfAddressesToScan(); + logger.debug("Performing discovery on {} ip addresses", addressesToScan.size()); executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 10); - for (final NetworkInterface networkInterface : interfaces) { - try { - if (networkInterface.isLoopback() || !networkInterface.isUp()) { - continue; - } - } catch (SocketException e) { - continue; - } - - for (Iterator it = networkInterface.getInterfaceAddresses().iterator(); it.hasNext();) { - final InterfaceAddress interfaceAddress = it.next(); - - // don't bother with ipv6 addresses (russound doesn't support) - if (interfaceAddress.getAddress() instanceof Inet6Address) { - continue; - } - - final String subnetRange = interfaceAddress.getAddress().getHostAddress() + "/" - + interfaceAddress.getNetworkPrefixLength(); - - logger.debug("Scanning subnet: {}", subnetRange); - final SubnetUtils utils = new SubnetUtils(subnetRange); - - final String[] addresses = utils.getInfo().getAllAddresses(); - - for (final String address : addresses) { - executorService.execute(() -> { - scanAddress(address); - }); - } - } + for (final InetAddress address : addressesToScan) { + executorService.execute(() -> { + scanAddress(address.getHostAddress()); + }); } // Finishes the scan and cleans up