java.net
Class NetworkInterface

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.net.NetworkInterface

public final class NetworkInterface
extends Object sample code for java.lang.Object definition code for java.lang.Object

This class represents a Network Interface made up of a name, and a list of IP addresses assigned to this interface. It is used to identify the local interface on which a multicast group is joined. Interfaces are normally known by names such as "le0".

Since:
1.4

Method Summary
 boolean equals sample code for java.net.NetworkInterface.equals(java.lang.Object) definition code for java.net.NetworkInterface.equals(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  obj)
          Compares this object against the specified object.
static NetworkInterface sample code for java.net.NetworkInterface definition code for java.net.NetworkInterface getByInetAddress sample code for java.net.NetworkInterface.getByInetAddress(java.net.InetAddress) definition code for java.net.NetworkInterface.getByInetAddress(java.net.InetAddress) (InetAddress sample code for java.net.InetAddress definition code for java.net.InetAddress  addr)
          Convenience method to search for a network interface that has the specified Internet Protocol (IP) address bound to it.
static NetworkInterface sample code for java.net.NetworkInterface definition code for java.net.NetworkInterface getByName sample code for java.net.NetworkInterface.getByName(java.lang.String) definition code for java.net.NetworkInterface.getByName(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  name)
          Searches for the network interface with the specified name.
 String sample code for java.lang.String definition code for java.lang.String getDisplayName sample code for java.net.NetworkInterface.getDisplayName() definition code for java.net.NetworkInterface.getDisplayName() ()
          Get the display name of this network interface.
 Enumeration sample code for java.util.Enumeration definition code for java.util.Enumeration <InetAddress sample code for java.net.InetAddress definition code for java.net.InetAddress > getInetAddresses sample code for java.net.NetworkInterface.getInetAddresses() definition code for java.net.NetworkInterface.getInetAddresses() ()
          Convenience method to return an Enumeration with all or a subset of the InetAddresses bound to this network interface.
 String sample code for java.lang.String definition code for java.lang.String getName sample code for java.net.NetworkInterface.getName() definition code for java.net.NetworkInterface.getName() ()
          Get the name of this network interface.
static Enumeration sample code for java.util.Enumeration definition code for java.util.Enumeration <NetworkInterface sample code for java.net.NetworkInterface definition code for java.net.NetworkInterface > getNetworkInterfaces sample code for java.net.NetworkInterface.getNetworkInterfaces() definition code for java.net.NetworkInterface.getNetworkInterfaces() ()
          Returns all the interfaces on this machine.
 int hashCode sample code for java.net.NetworkInterface.hashCode() definition code for java.net.NetworkInterface.hashCode() ()
          Returns a hash code value for the object.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.net.NetworkInterface.toString() definition code for java.net.NetworkInterface.toString() ()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Method Detail

getName sample code for java.net.NetworkInterface.getName() definition code for java.net.NetworkInterface.getName()

public String sample code for java.lang.String definition code for java.lang.String  getName()
Get the name of this network interface.

Returns:
the name of this network interface

getInetAddresses sample code for java.net.NetworkInterface.getInetAddresses() definition code for java.net.NetworkInterface.getInetAddresses()

public Enumeration sample code for java.util.Enumeration definition code for java.util.Enumeration <InetAddress sample code for java.net.InetAddress definition code for java.net.InetAddress > getInetAddresses()
Convenience method to return an Enumeration with all or a subset of the InetAddresses bound to this network interface.

If there is a security manager, its checkConnect method is called for each InetAddress. Only InetAddresses where the checkConnect doesn't throw a SecurityException will be returned in the Enumeration.

Returns:
an Enumeration object with all or a subset of the InetAddresses bound to this network interface

getDisplayName sample code for java.net.NetworkInterface.getDisplayName() definition code for java.net.NetworkInterface.getDisplayName()

public String sample code for java.lang.String definition code for java.lang.String  getDisplayName()
Get the display name of this network interface. A display name is a human readable String describing the network device.

Returns:
the display name of this network interface, or null if no display name is available.

getByName sample code for java.net.NetworkInterface.getByName(java.lang.String) definition code for java.net.NetworkInterface.getByName(java.lang.String)

public static NetworkInterface sample code for java.net.NetworkInterface definition code for java.net.NetworkInterface  getByName(String sample code for java.lang.String definition code for java.lang.String  name)
                                  throws SocketException sample code for java.net.SocketException definition code for java.net.SocketException 
Searches for the network interface with the specified name.

Parameters:
name - The name of the network interface.
Returns:
A NetworkInterface with the specified name, or null if there is no network interface with the specified name.
Throws:
SocketException sample code for java.net.SocketException definition code for java.net.SocketException - If an I/O error occurs.
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - If the specified name is null.

getByInetAddress sample code for java.net.NetworkInterface.getByInetAddress(java.net.InetAddress) definition code for java.net.NetworkInterface.getByInetAddress(java.net.InetAddress)

public static NetworkInterface sample code for java.net.NetworkInterface definition code for java.net.NetworkInterface  getByInetAddress(InetAddress sample code for java.net.InetAddress definition code for java.net.InetAddress  addr)
                                         throws SocketException sample code for java.net.SocketException definition code for java.net.SocketException 
Convenience method to search for a network interface that has the specified Internet Protocol (IP) address bound to it.

If the specified IP address is bound to multiple network interfaces it is not defined which network interface is returned.

Parameters:
addr - The InetAddress to search with.
Returns:
A NetworkInterface or null if there is no network interface with the specified IP address.
Throws:
SocketException sample code for java.net.SocketException definition code for java.net.SocketException - If an I/O error occurs.
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - If the specified address is null.

getNetworkInterfaces sample code for java.net.NetworkInterface.getNetworkInterfaces() definition code for java.net.NetworkInterface.getNetworkInterfaces()

public static Enumeration sample code for java.util.Enumeration definition code for java.util.Enumeration <NetworkInterface sample code for java.net.NetworkInterface definition code for java.net.NetworkInterface > getNetworkInterfaces()
                                                          throws SocketException sample code for java.net.SocketException definition code for java.net.SocketException 
Returns all the interfaces on this machine. Returns null if no network interfaces could be found on this machine. NOTE: can use getNetworkInterfaces()+getInetAddresses() to obtain all IP addresses for this node

Returns:
an Enumeration of NetworkInterfaces found on this machine
Throws:
SocketException sample code for java.net.SocketException definition code for java.net.SocketException - if an I/O error occurs.

equals sample code for java.net.NetworkInterface.equals(java.lang.Object) definition code for java.net.NetworkInterface.equals(java.lang.Object)

public boolean equals(Object sample code for java.lang.Object definition code for java.lang.Object  obj)
Compares this object against the specified object. The result is true if and only if the argument is not null and it represents the same NetworkInterface as this object.

Two instances of NetworkInterface represent the same NetworkInterface if both name and addrs are the same for both.

Overrides:
equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) in class Object sample code for java.lang.Object definition code for java.lang.Object
Parameters:
obj - the object to compare against.
Returns:
true if the objects are the same; false otherwise.
See Also:
InetAddress.getAddress() sample code for java.net.InetAddress.getAddress() definition code for java.net.InetAddress.getAddress()

hashCode sample code for java.net.NetworkInterface.hashCode() definition code for java.net.NetworkInterface.hashCode()

public int hashCode()
Description copied from class: Object sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.

The general contract of hashCode is:

As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

Overrides:
hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
a hash code value for this object.
See Also:
Object.equals(java.lang.Object) sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , Hashtable sample code for java.util.Hashtable definition code for java.util.Hashtable

toString sample code for java.net.NetworkInterface.toString() definition code for java.net.NetworkInterface.toString()

public String sample code for java.lang.String definition code for java.lang.String  toString()
Description copied from class: Object sample code for java.lang.Object.toString() definition code for java.lang.Object.toString()
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Overrides:
toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
a string representation of the object.