diff --git a/bramble-core/src/main/java/org/briarproject/bramble/plugin/tcp/TcpPlugin.java b/bramble-core/src/main/java/org/briarproject/bramble/plugin/tcp/TcpPlugin.java index 0dc0235a4..5646abff6 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/plugin/tcp/TcpPlugin.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/plugin/tcp/TcpPlugin.java @@ -24,7 +24,7 @@ import java.net.SocketException; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; +import java.util.Enumeration; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -35,6 +35,9 @@ import java.util.regex.Pattern; import javax.annotation.Nullable; +import static java.net.NetworkInterface.getNetworkInterfaces; +import static java.util.Collections.emptyList; +import static java.util.Collections.list; import static java.util.logging.Level.INFO; import static java.util.logging.Level.WARNING; import static org.briarproject.bramble.util.LogUtils.logException; @@ -303,16 +306,16 @@ abstract class TcpPlugin implements DuplexPlugin { } Collection getLocalIpAddresses() { - List ifaces; try { - ifaces = Collections.list(NetworkInterface.getNetworkInterfaces()); + Enumeration ifaces = getNetworkInterfaces(); + if (ifaces == null) return emptyList(); + List addrs = new ArrayList<>(); + for (NetworkInterface iface : list(ifaces)) + addrs.addAll(list(iface.getInetAddresses())); + return addrs; } catch (SocketException e) { logException(LOG, WARNING, e); - return Collections.emptyList(); + return emptyList(); } - List addrs = new ArrayList<>(); - for (NetworkInterface iface : ifaces) - addrs.addAll(Collections.list(iface.getInetAddresses())); - return addrs; } } diff --git a/bramble-core/src/main/java/org/briarproject/bramble/system/AbstractSecureRandomProvider.java b/bramble-core/src/main/java/org/briarproject/bramble/system/AbstractSecureRandomProvider.java index c442895a2..d7691ea73 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/system/AbstractSecureRandomProvider.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/system/AbstractSecureRandomProvider.java @@ -7,13 +7,15 @@ import java.io.DataOutputStream; import java.io.IOException; import java.net.InetAddress; import java.net.NetworkInterface; -import java.util.Collections; -import java.util.List; +import java.util.Enumeration; import java.util.Map.Entry; import java.util.Properties; import javax.annotation.concurrent.Immutable; +import static java.net.NetworkInterface.getNetworkInterfaces; +import static java.util.Collections.list; + @Immutable @NotNullByDefault abstract class AbstractSecureRandomProvider implements SecureRandomProvider { @@ -23,13 +25,14 @@ abstract class AbstractSecureRandomProvider implements SecureRandomProvider { out.writeLong(System.currentTimeMillis()); out.writeLong(System.nanoTime()); out.writeLong(Runtime.getRuntime().freeMemory()); - List ifaces = - Collections.list(NetworkInterface.getNetworkInterfaces()); - for (NetworkInterface i : ifaces) { - List addrs = Collections.list(i.getInetAddresses()); - for (InetAddress a : addrs) out.write(a.getAddress()); - byte[] hardware = i.getHardwareAddress(); - if (hardware != null) out.write(hardware); + Enumeration ifaces = getNetworkInterfaces(); + if (ifaces != null) { + for (NetworkInterface i : list(ifaces)) { + for (InetAddress a : list(i.getInetAddresses())) + out.write(a.getAddress()); + byte[] hardware = i.getHardwareAddress(); + if (hardware != null) out.write(hardware); + } } for (Entry e : System.getenv().entrySet()) { out.writeUTF(e.getKey());