com.neeve.util
Class UtlNet

java.lang.Object
  extended by com.neeve.util.UtlNet

public final class UtlNet
extends Object

Utility class containing methods to manipulate network addresses.

This class MAY be used by end users, however it is not supported.


Nested Class Summary
static interface UtlNet.DebugTracer
           
 
Constructor Summary
UtlNet()
           
 
Method Summary
static String formatNetworkInterfaceDescriptor(NetworkInterface nif)
          Returns a string describing a network interface (name + all bound addresses)
static NetworkInterface getFirstActiveNetworkInterface(boolean multicastRequired)
          Find an active, non-virtual, non-loopback network device that might be appropriate as a primary device for general network communication and/or discovery.
static NetworkInterface getFirstActiveNetworkInterface(UtlNet.DebugTracer tracer, boolean multicastRequired)
          Find an active, non-virtual, non-loopback network device that might be appropriate as a primary device for general network communication and/or discovery.
static InetAddress getFirstInetAddress(NetworkInterface networkInterface)
          Given a NetworkInterface, returns the first InetAddress associated with the interface (prioritizing IPv4 over IPv6).
static String inetAddrToName(String addr)
          Get a host name corresponding to a inet network address.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UtlNet

public UtlNet()
Method Detail

inetAddrToName

public static final String inetAddrToName(String addr)
Get a host name corresponding to a inet network address.

Parameters:
addr - The textual representation of the inet network address.
Throws:
IllegalArgumentException - Thrown in case the user has either supplied an inet address in the incorrect format or has provided a host name that cannot be resolved to an IP address.

Thjis method resolves a textual representation of an inet address to its host name. In case a host name is provided in the addr parameter, this method will attempt to resolve the name to an IP address and then resolve it back to the host name.

Threading:
This method is safe for concurrent access by multiple threads

getFirstActiveNetworkInterface

public static final NetworkInterface getFirstActiveNetworkInterface(boolean multicastRequired)
                                                             throws SocketException
Find an active, non-virtual, non-loopback network device that might be appropriate as a primary device for general network communication and/or discovery. This is useful when we need to determine a local IP address or hostname when one is not explicitly specified.

Parameters:
multicastRequired - indicates whether the returned network interface must support multicast
Returns:
the network device, or null if no suitable network device could be found
Throws:
SocketException - if there is an error getting the list of candidate network devices
Threading:
This method is safe for concurrent access by multiple threads

getFirstActiveNetworkInterface

public static final NetworkInterface getFirstActiveNetworkInterface(UtlNet.DebugTracer tracer,
                                                                    boolean multicastRequired)
                                                             throws SocketException
Find an active, non-virtual, non-loopback network device that might be appropriate as a primary device for general network communication and/or discovery. This is useful when we need to determine a local IP address or hostname when one is not explicitly specified.

Parameters:
multicastRequired - indicates whether the returned network interface must support multicast
tracer - the tracer to use for logging, may be null if no logging is required
Returns:
the network device, or null if no suitable network device could be found
Throws:
SocketException - if there is an error getting the list of candidate network devices
Threading:
This method is safe for concurrent access by multiple threads

getFirstInetAddress

public static final InetAddress getFirstInetAddress(NetworkInterface networkInterface)
Given a NetworkInterface, returns the first InetAddress associated with the interface (prioritizing IPv4 over IPv6).

Parameters:
networkInterface - The network interface to inspect
Returns:
The first matching InetAddress, or null if no appropriate address is found

formatNetworkInterfaceDescriptor

public static final String formatNetworkInterfaceDescriptor(NetworkInterface nif)
Returns a string describing a network interface (name + all bound addresses)



Copyright © 2016 Neeve Research, LLC. All Rights Reserved.