/** * Previous to network interface syntax support, only InetAddress.getByName(hostAddress) was used for when * returning IPs based on host name. This basically did a InetAddress.getAllByName(hostAddress)[0] * Consequently, only the first IP address was returned * A similar approach has been used with added NetworkIntrfaceSyntax support, where only the first IP * is returned for a localInterface * Same approach is used also for cluster members * Method returning resolved addresses from host * @param hostAddress * @return * @throws UnknownHostException */ private InetAddress getResolvedAddressFromHost(String hostAddress) throws UnknownHostException { // TODO: Previous to network interface syntax support, only InetAddress.getByName(hostAddress) was used for when // returning IPs based on host name. This basically did a InetAddress.getAllByName(hostAddress)[0] // Consequently, only the first IP address was returned // A similar approach has been used with added NetworkIntrfaceSyntax support, where only the first IP // is returned for a localInterface // Same approach is used also for cluster members InetAddress address; Collection<InetAddress> addresses = ResolutionUtils.getAllByName(hostAddress, false); if (addresses.isEmpty()) { address = InetAddress.getByName(hostAddress); } else { address = addresses.iterator().next(); } return address; }
private InetSocketAddress parseBindAddress(Object bindAddress) { if (bindAddress instanceof InetSocketAddress) { return (InetSocketAddress) bindAddress; } else if (bindAddress instanceof String) { return ResolutionUtils.parseBindAddress((String) bindAddress); } throw new IllegalArgumentException(BIND_ADDRESS.name()); }
/** * Method resolving host to InetAddresses * @param host * @return */ public static Collection<InetAddress> getAllByName(String host, boolean allowIPv6) { Enumeration<NetworkInterface> networkInterfaces = cloneInterfaces(ResolutionUtils.networkInterfaces); List<String> resolvedAddresses = resolveDeviceAddress(host, networkInterfaces, allowIPv6); List<InetAddress> resolvedDeviceURIs = new ArrayList<>(); List<InetAddress> resolvedHosts = resolvedDeviceURIs; for (String resolvedAddress : resolvedAddresses) { try { resolvedHosts.addAll(asList(InetAddress.getAllByName(resolvedAddress))); } catch (UnknownHostException e) { e.printStackTrace(); } } return resolvedHosts; }
resolvedAddresses.addAll(resolveDeviceAddress(deviceName, subInterfaces, allowIPv6));
Collection<InetAddress> addresses = ResolutionUtils.getAllByName(host, true);
private InetSocketAddress parseBindAddress(Object bindAddress) { if (bindAddress instanceof InetSocketAddress) { return (InetSocketAddress) bindAddress; } else if (bindAddress instanceof String) { return ResolutionUtils.parseBindAddress((String) bindAddress); } throw new IllegalArgumentException(BIND_ADDRESS.name()); }
Collection<InetAddress> addresses = ResolutionUtils.getAllByName(host, true);