mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
You can't step in the same Enumeration twice.
This commit is contained in:
@@ -12,6 +12,7 @@ import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Level;
|
||||
@@ -136,28 +137,28 @@ public class LanSocketPlugin extends SimpleSocketPlugin {
|
||||
|
||||
private InetAddress chooseMulticastInterface() throws IOException {
|
||||
// Try to find a LAN interface that supports multicast
|
||||
Enumeration<NetworkInterface> ifaces =
|
||||
NetworkInterface.getNetworkInterfaces();
|
||||
for(NetworkInterface iface : Collections.list(ifaces)) {
|
||||
List<NetworkInterface> ifaces =
|
||||
Collections.list(NetworkInterface.getNetworkInterfaces());
|
||||
for(NetworkInterface iface : ifaces) {
|
||||
if(iface.supportsMulticast()) {
|
||||
Enumeration<InetAddress> addrs = iface.getInetAddresses();
|
||||
for(InetAddress addr : Collections.list(addrs)) {
|
||||
if(addr.isLinkLocalAddress() || addr.isSiteLocalAddress()) {
|
||||
if(LOG.isLoggable(Level.INFO))
|
||||
LOG.info("Binding to " + addr.getHostAddress());
|
||||
LOG.info("Preferring " + addr.getHostAddress());
|
||||
return addr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Settle for a WAN interface that supports multicast
|
||||
for(NetworkInterface iface : Collections.list(ifaces)) {
|
||||
for(NetworkInterface iface : ifaces) {
|
||||
if(iface.supportsMulticast()) {
|
||||
Enumeration<InetAddress> addrs = iface.getInetAddresses();
|
||||
for(InetAddress addr : Collections.list(addrs)) {
|
||||
if(!addr.isLoopbackAddress()) {
|
||||
if(LOG.isLoggable(Level.INFO))
|
||||
LOG.info("Binding to " + addr.getHostAddress());
|
||||
LOG.info("Accepting " + addr.getHostAddress());
|
||||
return addr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -74,30 +74,28 @@ class SimpleSocketPlugin extends SocketPlugin {
|
||||
}
|
||||
|
||||
protected InetAddress chooseTcpInterface(boolean lan) throws IOException {
|
||||
Enumeration<NetworkInterface> ifaces =
|
||||
NetworkInterface.getNetworkInterfaces();
|
||||
List<NetworkInterface> ifaces =
|
||||
Collections.list(NetworkInterface.getNetworkInterfaces());
|
||||
// Try to find an interface of the preferred type (LAN or WAN)
|
||||
for(NetworkInterface iface : Collections.list(ifaces)) {
|
||||
Enumeration<InetAddress> addrs = iface.getInetAddresses();
|
||||
for(InetAddress addr : Collections.list(addrs)) {
|
||||
for(NetworkInterface iface : ifaces) {
|
||||
for(InetAddress addr : Collections.list(iface.getInetAddresses())) {
|
||||
if(!addr.isLoopbackAddress()) {
|
||||
boolean link = addr.isLinkLocalAddress();
|
||||
boolean site = addr.isSiteLocalAddress();
|
||||
if(lan == (link || site)) {
|
||||
if(LOG.isLoggable(Level.INFO))
|
||||
LOG.info("Binding to " + addr.getHostAddress());
|
||||
LOG.info("Preferring " + addr.getHostAddress());
|
||||
return addr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Settle for an interface that's not of the preferred type
|
||||
for(NetworkInterface iface : Collections.list(ifaces)) {
|
||||
Enumeration<InetAddress> addrs = iface.getInetAddresses();
|
||||
for(InetAddress addr : Collections.list(addrs)) {
|
||||
for(NetworkInterface iface : ifaces) {
|
||||
for(InetAddress addr : Collections.list(iface.getInetAddresses())) {
|
||||
if(!addr.isLoopbackAddress()) {
|
||||
if(LOG.isLoggable(Level.INFO))
|
||||
LOG.info("Binding to " + addr.getHostAddress());
|
||||
LOG.info("Accepting " + addr.getHostAddress());
|
||||
return addr;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user