Package java.net

Class InterfaceAddress

java.lang.Object
java.net.InterfaceAddress

public class InterfaceAddress
extends Object
Identifies one of a network interface's addresses. These are passed back from the JNI behind NetworkInterface.getNetworkInterfaces. Multiple addresses for the same interface are collected together on the Java side.
Since:
1.6
  • Method Details

    • equals

      public boolean equals​(Object obj)
      Tests whether this object is equal to another one. Returns true if the address, broadcast address and prefix length are all equal.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to be compared.
      Returns:
      true if 'obj' is equal to this InterfaceAddress, false otherwise.
      See Also:
      Object.hashCode()
    • hashCode

      public int hashCode()
      Description copied from class: Object
      Returns an integer hash code for this object. By contract, any two objects for which Object.equals(java.lang.Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

      Note that hash values must not change over time unless information used in equals comparisons also changes.

      See Writing a correct hashCode method if you intend implementing your own hashCode method.

      Overrides:
      hashCode in class Object
      Returns:
      this object's hash code.
      See Also:
      Object.equals(java.lang.Object)
    • toString

      public String toString()
      Returns a string containing this interface's address, prefix length, and broadcast address. For example: "/172.18.103.112/23 [/172.18.103.255]" or "/0:0:0:0:0:0:0:1%1/128 [null]".
      Overrides:
      toString in class Object
      Returns:
      a printable representation of this object.
    • getAddress

      public InetAddress getAddress()
      Returns the InetAddress for this address.
    • getBroadcast

      public InetAddress getBroadcast()
      Returns the subnet-directed broadcast address if this is an IPv4 interface, null otherwise.
    • getNetworkPrefixLength

      public short getNetworkPrefixLength()
      Returns the network prefix length in bits. (In IPv4 parlance, this is known as the subnet mask, but this method applies to IPv6 addresses too.)