|
@@ -45,7 +45,7 @@ public abstract class NetworkUtils {
|
|
|
|
|
|
/** no instantiation */
|
|
|
private NetworkUtils() {}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* By default we bind to any addresses on an interface/name, unless restricted by :ipv4 etc.
|
|
|
* This property is unrelated to that, this is about what we *publish*. Today the code pretty much
|
|
@@ -79,14 +79,14 @@ public abstract class NetworkUtils {
|
|
|
}
|
|
|
SUPPORTS_V6 = v;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/** Sorts an address by preference. This way code like publishing can just pick the first one */
|
|
|
static int sortKey(InetAddress address, boolean prefer_v6) {
|
|
|
int key = address.getAddress().length;
|
|
|
if (prefer_v6) {
|
|
|
key = -key;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (address.isAnyLocalAddress()) {
|
|
|
key += 5;
|
|
|
}
|
|
@@ -106,7 +106,7 @@ public abstract class NetworkUtils {
|
|
|
return key;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
+ /**
|
|
|
* Sorts addresses by order of preference. This is used to pick the first one for publishing
|
|
|
* @deprecated remove this when multihoming is really correct
|
|
|
*/
|
|
@@ -124,7 +124,7 @@ public abstract class NetworkUtils {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/** Return all interfaces (and subinterfaces) on the system */
|
|
|
static List<NetworkInterface> getInterfaces() throws SocketException {
|
|
|
List<NetworkInterface> all = new ArrayList<>();
|
|
@@ -137,17 +137,17 @@ public abstract class NetworkUtils {
|
|
|
});
|
|
|
return all;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/** Helper for getInterfaces, recursively adds subinterfaces to {@code target} */
|
|
|
private static void addAllInterfaces(List<NetworkInterface> target, List<NetworkInterface> level) {
|
|
|
- if (!level.isEmpty()) {
|
|
|
+ if (level.isEmpty() == false) {
|
|
|
target.addAll(level);
|
|
|
for (NetworkInterface intf : level) {
|
|
|
addAllInterfaces(target, Collections.list(intf.getSubInterfaces()));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/** Returns system default for SO_REUSEADDR */
|
|
|
public static boolean defaultReuseAddress() {
|
|
|
return Constants.WINDOWS ? false : true;
|
|
@@ -185,12 +185,12 @@ public abstract class NetworkUtils {
|
|
|
static InetAddress[] getLoopbackAddresses() throws IOException {
|
|
|
return filterAllAddresses(InetAddress::isLoopbackAddress, "no up-and-running loopback addresses found");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/** Returns all site-local scope (private) addresses for interfaces that are up. */
|
|
|
static InetAddress[] getSiteLocalAddresses() throws IOException {
|
|
|
return filterAllAddresses(InetAddress::isSiteLocalAddress, "No up-and-running site-local (private) addresses found");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/** Returns all global scope addresses for interfaces that are up. */
|
|
|
static InetAddress[] getGlobalAddresses() throws IOException {
|
|
|
return filterAllAddresses(
|
|
@@ -199,8 +199,8 @@ public abstract class NetworkUtils {
|
|
|
&& address.isLinkLocalAddress() == false,
|
|
|
"no up-and-running global-scope (public) addresses found");
|
|
|
}
|
|
|
-
|
|
|
- /** Returns all addresses (any scope) for interfaces that are up.
|
|
|
+
|
|
|
+ /** Returns all addresses (any scope) for interfaces that are up.
|
|
|
* This is only used to pick a publish address, when the user set network.host to a wildcard */
|
|
|
static InetAddress[] getAllAddresses() throws IOException {
|
|
|
return filterAllAddresses(address -> true, "no up-and-running addresses found");
|
|
@@ -219,7 +219,7 @@ public abstract class NetworkUtils {
|
|
|
getInterfaces().stream().map(otherInterface -> "_" + otherInterface.getName() + suffix + "_")
|
|
|
.collect(Collectors.joining(", ")) + "]");
|
|
|
}
|
|
|
- if (!networkInterface.get().isUp()) {
|
|
|
+ if (networkInterface.get().isUp() == false) {
|
|
|
throw new IllegalArgumentException("setting [" + settingValue + "] matched network interface [" +
|
|
|
networkInterface.get().getName() + "] but this interface is not up and running");
|
|
|
}
|
|
@@ -230,7 +230,7 @@ public abstract class NetworkUtils {
|
|
|
}
|
|
|
return list.toArray(new InetAddress[list.size()]);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/** Returns only the IPV4 addresses in {@code addresses} */
|
|
|
static InetAddress[] filterIPV4(InetAddress addresses[]) {
|
|
|
List<InetAddress> list = new ArrayList<>();
|
|
@@ -244,7 +244,7 @@ public abstract class NetworkUtils {
|
|
|
}
|
|
|
return list.toArray(new InetAddress[list.size()]);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/** Returns only the IPV6 addresses in {@code addresses} */
|
|
|
static InetAddress[] filterIPV6(InetAddress addresses[]) {
|
|
|
List<InetAddress> list = new ArrayList<>();
|