Example usage for org.apache.hadoop.net DNS getIPs

List of usage examples for org.apache.hadoop.net DNS getIPs

Introduction

In this page you can find the example usage for org.apache.hadoop.net DNS getIPs.

Prototype

public static String[] getIPs(String strInterface, boolean returnSubinterfaces) throws UnknownHostException 

Source Link

Document

Returns all the IPs associated with the provided interface, if any, in textual form.

Usage

From source file:com.mellanox.r4h.DFSClient.java

License:Apache License

/**
 * Return the socket addresses to use with each configured
 * local interface. Local interfaces may be specified by IP
 * address, IP address range using CIDR notation, interface
 * name (e.g. eth0) or sub-interface name (e.g. eth0:0).
 * The socket addresses consist of the IPs for the interfaces
 * and the ephemeral port (port 0). If an IP, IP range, or
 * interface name matches an interface with sub-interfaces
 * only the IP of the interface is used. Sub-interfaces can
 * be used by specifying them explicitly (by IP or name).
 * /* w ww .j  a v a 2 s.c  o m*/
 * @return SocketAddresses for the configured local interfaces,
 *         or an empty array if none are configured
 * @throws UnknownHostException
 *             if a given interface name is invalid
 */
private static SocketAddress[] getLocalInterfaceAddrs(String interfaceNames[]) throws UnknownHostException {
    List<SocketAddress> localAddrs = new ArrayList<SocketAddress>();
    for (String interfaceName : interfaceNames) {
        if (InetAddresses.isInetAddress(interfaceName)) {
            localAddrs.add(new InetSocketAddress(interfaceName, 0));
        } else if (NetUtils.isValidSubnet(interfaceName)) {
            for (InetAddress addr : NetUtils.getIPs(interfaceName, false)) {
                localAddrs.add(new InetSocketAddress(addr, 0));
            }
        } else {
            for (String ip : DNS.getIPs(interfaceName, false)) {
                localAddrs.add(new InetSocketAddress(ip, 0));
            }
        }
    }
    return localAddrs.toArray(new SocketAddress[localAddrs.size()]);
}