Refine search
/** Return all interfaces (and subinterfaces) on the system */ static List<NetworkInterface> getInterfaces() throws SocketException { List<NetworkInterface> all = new ArrayList<>(); addAllInterfaces(all, Collections.list(NetworkInterface.getNetworkInterfaces())); Collections.sort(all, new Comparator<NetworkInterface>() { @Override public int compare(NetworkInterface left, NetworkInterface right) { return Integer.compare(left.getIndex(), right.getIndex()); } }); return all; }
return NetworkUtils.getLoopbackAddresses(); case "local:ipv4": return NetworkUtils.filterIPV4(NetworkUtils.getLoopbackAddresses()); case "local:ipv6": return NetworkUtils.filterIPV6(NetworkUtils.getLoopbackAddresses()); case "site": return NetworkUtils.getSiteLocalAddresses(); case "site:ipv4": return NetworkUtils.filterIPV4(NetworkUtils.getSiteLocalAddresses()); case "site:ipv6": return NetworkUtils.filterIPV6(NetworkUtils.getSiteLocalAddresses()); case "global": return NetworkUtils.getGlobalAddresses(); case "global:ipv4": return NetworkUtils.filterIPV4(NetworkUtils.getGlobalAddresses()); case "global:ipv6": return NetworkUtils.filterIPV6(NetworkUtils.getGlobalAddresses()); default: return NetworkUtils.filterIPV4(NetworkUtils.getAddressesForInterface(host)); } else if (host.endsWith(":ipv6")) { host = host.substring(0, host.length() - 5); return NetworkUtils.filterIPV6(NetworkUtils.getAddressesForInterface(host)); } else { return NetworkUtils.getAddressesForInterface(host); return InetAddress.getAllByName(host);
if (addresses.length == 1 && addresses[0].isAnyLocalAddress()) { HashSet<InetAddress> all = new HashSet<>(Arrays.asList(NetworkUtils.getAllAddresses())); addresses = all.toArray(new InetAddress[all.size()]); if (address.isMulticastAddress()) { throw new IllegalArgumentException("publish address: {" + NetworkAddress.format(address) + "} is invalid: multicast address"); if (address.isAnyLocalAddress()) { throw new IllegalArgumentException("publish address: {" + NetworkAddress.format(address) + "} is wildcard, but multiple addresses specified: this makes no sense"); NetworkUtils.sortAddresses(sorted); addresses = new InetAddress[]{sorted.get(0)};
/** Returns all interface-local scope (loopback) addresses for interfaces that are up. */ static InetAddress[] getLoopbackAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { if (address.isLoopbackAddress()) { list.add(address); } } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running loopback addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
/** Returns all global scope addresses for interfaces that are up. */ static InetAddress[] getGlobalAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { if (address.isLoopbackAddress() == false && address.isSiteLocalAddress() == false && address.isLinkLocalAddress() == false) { list.add(address); } } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running global-scope (public) addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
try { hostname = InetAddress.getLocalHost().getHostName(); logger.info("detected host name by reverse IP lookup: {}", hostname); } catch (Exception e) { this.tcpNoDelay = componentSettings.getAsBoolean("tcp_no_delay", settings.getAsBoolean(TCP_NO_DELAY, true)); this.tcpKeepAlive = componentSettings.getAsBoolean("tcp_keep_alive", settings.getAsBoolean(TCP_KEEP_ALIVE, true)); this.reuseAddress = componentSettings.getAsBoolean("reuse_address", settings.getAsBoolean(TCP_REUSE_ADDRESS, NetworkUtils.defaultReuseAddress())); this.tcpSendBufferSize = componentSettings.getAsBytesSize("tcp_send_buffer_size", settings.getAsBytesSize(TCP_SEND_BUFFER_SIZE, TCP_DEFAULT_SEND_BUFFER_SIZE)); this.tcpReceiveBufferSize = componentSettings.getAsBytesSize("tcp_receive_buffer_size", settings.getAsBytesSize(TCP_RECEIVE_BUFFER_SIZE, TCP_DEFAULT_RECEIVE_BUFFER_SIZE));
/** Returns all site-local scope (private) addresses for interfaces that are up. */ static InetAddress[] getSiteLocalAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { if (address.isSiteLocalAddress()) { list.add(address); } } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running site-local (private) addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
/** Returns addresses for the given interface (it must be marked up) */ static InetAddress[] getAddressesForInterface(String name) throws SocketException { Optional<NetworkInterface> networkInterface = getInterfaces().stream().filter((netIf) -> name.equals(netIf.getName())).findFirst(); if (networkInterface.isPresent() == false) { throw new IllegalArgumentException("No interface named '" + name + "' found, got " + getInterfaces()); } if (!networkInterface.get().isUp()) { throw new IllegalArgumentException("Interface '" + name + "' is not up and running"); } List<InetAddress> list = Collections.list(networkInterface.get().getInetAddresses()); if (list.isEmpty()) { throw new IllegalArgumentException("Interface '" + name + "' has no internet addresses"); } return list.toArray(new InetAddress[list.size()]); }
/** 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 SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { list.add(address); } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
/** Returns addresses for the given interface (it must be marked up) */ static InetAddress[] getAddressesForInterface(String name) throws SocketException { NetworkInterface intf = NetworkInterface.getByName(name); if (intf == null) { throw new IllegalArgumentException("No interface named '" + name + "' found, got " + getInterfaces()); } if (!intf.isUp()) { throw new IllegalArgumentException("Interface '" + name + "' is not up and running"); } List<InetAddress> list = Collections.list(intf.getInetAddresses()); if (list.isEmpty()) { throw new IllegalArgumentException("Interface '" + name + "' has no internet addresses"); } return list.toArray(new InetAddress[list.size()]); }
for (NetworkInterface nic : NetworkUtils.getInterfaces()) { msg.append(System.lineSeparator()); msg.append(nic.getName()); msg.append(System.lineSeparator()); if (!nic.getName().equals(nic.getDisplayName())) { msg.append(INDENT); msg.append(nic.getDisplayName());
/** Helper for getInterfaces, recursively adds subinterfaces to {@code target} */ private static void addAllInterfaces(List<NetworkInterface> target, List<NetworkInterface> level) { if (!level.isEmpty()) { target.addAll(level); for (NetworkInterface intf : level) { addAllInterfaces(target, Collections.list(intf.getSubInterfaces())); } } }
try (ServerSocket serverSocket = new MockServerSocket()) { serverSocket.setReuseAddress(NetworkUtils.defaultReuseAddress()); serverSocket.bind(new InetSocketAddress(IP_ADDR, nextPort));
/** Returns all interface-local scope (loopback) addresses for interfaces that are up. */ static InetAddress[] getLoopbackAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { if (address.isLoopbackAddress()) { list.add(address); } } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running loopback addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
/** Returns all global scope addresses for interfaces that are up. */ static InetAddress[] getGlobalAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { if (address.isLoopbackAddress() == false && address.isSiteLocalAddress() == false && address.isLinkLocalAddress() == false) { list.add(address); } } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running global-scope (public) addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
/** Returns all site-local scope (private) addresses for interfaces that are up. */ static InetAddress[] getSiteLocalAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { if (address.isSiteLocalAddress()) { list.add(address); } } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running site-local (private) addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
/** Returns addresses for the given interface (it must be marked up) */ static InetAddress[] getAddressesForInterface(String name) throws SocketException { Optional<NetworkInterface> networkInterface = getInterfaces().stream().filter((netIf) -> name.equals(netIf.getName())).findFirst(); if (networkInterface.isPresent() == false) { throw new IllegalArgumentException("No interface named '" + name + "' found, got " + getInterfaces()); } if (!networkInterface.get().isUp()) { throw new IllegalArgumentException("Interface '" + name + "' is not up and running"); } List<InetAddress> list = Collections.list(networkInterface.get().getInetAddresses()); if (list.isEmpty()) { throw new IllegalArgumentException("Interface '" + name + "' has no internet addresses"); } return list.toArray(new InetAddress[list.size()]); }
/** 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 SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { list.add(address); } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
for (NetworkInterface nic : NetworkUtils.getInterfaces()) { msg.append(System.lineSeparator()); msg.append(nic.getName()); msg.append(System.lineSeparator()); if (!nic.getName().equals(nic.getDisplayName())) { msg.append(INDENT); msg.append(nic.getDisplayName());
/** Helper for getInterfaces, recursively adds subinterfaces to {@code target} */ private static void addAllInterfaces(List<NetworkInterface> target, List<NetworkInterface> level) { if (!level.isEmpty()) { target.addAll(level); for (NetworkInterface intf : level) { addAllInterfaces(target, Collections.list(intf.getSubInterfaces())); } } }