InterfaceAddress
Stay organized with collections
Save and categorize content based on your preferences.
This class represents a Network Interface address. In short it's an
IP address, a subnet mask and a broadcast address when the address is
an IPv4 one. An IP address and a network prefix length in the case
of IPv6 address.
Inherited Method Summary
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this Object .
|
boolean
|
equals( Object obj)
Compares this instance with the specified object and indicates if they
are equal.
|
void
|
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
final
Class<?>
|
getClass()
Returns the unique instance of Class that represents this
object's class.
|
int
|
hashCode()
Returns an integer hash code for this object.
|
final
void
|
notify()
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
|
final
void
|
notifyAll()
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
final
void
|
wait(long timeout, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait(long timeout)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
|
Public Methods
public
boolean
equals
(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 interface address as
this object.
Two instances of InterfaceAddress
represent the same
address if the InetAddress, the prefix length and the broadcast are
the same for both.
Parameters
obj |
the object to compare against. |
Returns
true
if the objects are the same;
false
otherwise.
Returns an InetAddress
for this address.
Returns
- the
InetAddress
for this address.
public
InetAddress
getBroadcast
()
Returns an InetAddress
for the broadcast address
for this InterfaceAddress.
Only IPv4 networks have broadcast address therefore, in the case
of an IPv6 network, null
will be returned.
Returns
- the
InetAddress
representing the broadcast
address or null
if there is no broadcast address.
public
short
getNetworkPrefixLength
()
Returns the network prefix length for this address. This is also known
as the subnet mask in the context of IPv4 addresses.
Typical IPv4 values would be 8 (255.0.0.0), 16 (255.255.0.0)
or 24 (255.255.255.0).
Typical IPv6 values would be 128 (::1/128) or 10 (fe80::203:baff:fe27:1243/10)
Returns
- a
short
representing the prefix length for the
subnet of that address.
public
int
hashCode
()
Returns a hashcode for this Interface address.
Returns
- a hash code value for this Interface address.
public
String
toString
()
Converts this Interface address to a String
. The
string returned is of the form: InetAddress / prefix length [ broadcast address ].
Returns
- a string representation of this Interface address.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eInterfaceAddress\u003c/code\u003e class in Java represents a network interface address, including IP address, subnet mask (or network prefix length), and broadcast address (for IPv4).\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods to retrieve the IP address (\u003ccode\u003egetAddress()\u003c/code\u003e), broadcast address (\u003ccode\u003egetBroadcast()\u003c/code\u003e), and network prefix length (\u003ccode\u003egetNetworkPrefixLength()\u003c/code\u003e).\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eequals()\u003c/code\u003e method compares two \u003ccode\u003eInterfaceAddress\u003c/code\u003e instances based on their IP address, prefix length, and broadcast address.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003etoString()\u003c/code\u003e method provides a string representation of the interface address in the format: "InetAddress/prefix length[broadcast address]".\u003c/p\u003e\n"],["\u003cp\u003eFor IPv6 addresses, the broadcast address is typically null, as IPv6 networks generally do not utilize broadcast addresses.\u003c/p\u003e\n"]]],["The `InterfaceAddress` class represents a network interface address, encompassing an IP address, subnet mask, and broadcast address (for IPv4) or IP address and network prefix length (for IPv6). Key actions include: retrieving the `InetAddress` or broadcast address, getting the network prefix length, comparing instances for equality, generating a hashcode, and converting the address to a string representation. The class can also determine if two object represent the same interface address.\n"],null,["# InterfaceAddress\n\npublic class **InterfaceAddress** extends [Object](../../../reference/java/lang/Object.html) \nThis class represents a Network Interface address. In short it's an\nIP address, a subnet mask and a broadcast address when the address is\nan IPv4 one. An IP address and a network prefix length in the case\nof IPv6 address. \n\n##### See Also\n\n- [NetworkInterface](../../../reference/java/net/NetworkInterface.html) \n\n### Public Method Summary\n\n|-------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| boolean | [equals](../../../reference/java/net/InterfaceAddress.html#equals(java.lang.Object))([Object](../../../reference/java/lang/Object.html) obj) Compares this object against the specified object. |\n| [InetAddress](../../../reference/java/net/InetAddress.html) | [getAddress](../../../reference/java/net/InterfaceAddress.html#getAddress())() Returns an `InetAddress` for this address. |\n| [InetAddress](../../../reference/java/net/InetAddress.html) | [getBroadcast](../../../reference/java/net/InterfaceAddress.html#getBroadcast())() Returns an `InetAddress` for the broadcast address for this InterfaceAddress. |\n| short | [getNetworkPrefixLength](../../../reference/java/net/InterfaceAddress.html#getNetworkPrefixLength())() Returns the network prefix length for this address. |\n| int | [hashCode](../../../reference/java/net/InterfaceAddress.html#hashCode())() Returns a hashcode for this Interface address. |\n| [String](../../../reference/java/lang/String.html) | [toString](../../../reference/java/net/InterfaceAddress.html#toString())() Converts this Interface address to a `String`. |\n\n### Inherited Method Summary\n\nFrom class [java.lang.Object](../../../reference/java/lang/Object.html) \n\n|-------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Object](../../../reference/java/lang/Object.html) | [clone](../../../reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |\n| boolean | [equals](../../../reference/java/lang/Object.html#equals(java.lang.Object))([Object](../../../reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |\n| void | [finalize](../../../reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |\n| final [Class](../../../reference/java/lang/Class.html)\\\u003c?\\\u003e | [getClass](../../../reference/java/lang/Object.html#getClass())() Returns the unique instance of [Class](../../../reference/java/lang/Class.html) that represents this object's class. |\n| int | [hashCode](../../../reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |\n| final void | [notify](../../../reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |\n| final void | [notifyAll](../../../reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |\n| [String](../../../reference/java/lang/String.html) | [toString](../../../reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |\n| final void | [wait](../../../reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |\n| final void | [wait](../../../reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |\n| final void | [wait](../../../reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |\n\nPublic Methods\n--------------\n\n#### public boolean\n**equals**\n([Object](../../../reference/java/lang/Object.html) obj)\n\nCompares this object against the specified object.\nThe result is `true` if and only if the argument is\nnot `null` and it represents the same interface address as\nthis object.\n\n\nTwo instances of `InterfaceAddress` represent the same\naddress if the InetAddress, the prefix length and the broadcast are\nthe same for both. \n\n##### Parameters\n\n| obj | the object to compare against. |\n|-----|--------------------------------|\n\n##### Returns\n\n- `true` if the objects are the same; `false` otherwise. \n\n##### See Also\n\n- [hashCode()](../../../reference/java/net/InterfaceAddress.html#hashCode()) \n\n#### public [InetAddress](../../../reference/java/net/InetAddress.html)\n**getAddress**\n()\n\nReturns an `InetAddress` for this address. \n\n##### Returns\n\n- the `InetAddress` for this address. \n\n#### public [InetAddress](../../../reference/java/net/InetAddress.html)\n**getBroadcast**\n()\n\nReturns an `InetAddress` for the broadcast address\nfor this InterfaceAddress.\n\n\nOnly IPv4 networks have broadcast address therefore, in the case\nof an IPv6 network, `null` will be returned. \n\n##### Returns\n\n- the `InetAddress` representing the broadcast address or `null` if there is no broadcast address. \n\n#### public short\n**getNetworkPrefixLength**\n()\n\nReturns the network prefix length for this address. This is also known\nas the subnet mask in the context of IPv4 addresses.\nTypical IPv4 values would be 8 (255.0.0.0), 16 (255.255.0.0)\nor 24 (255.255.255.0).\n\n\nTypical IPv6 values would be 128 (::1/128) or 10 (fe80::203:baff:fe27:1243/10) \n\n##### Returns\n\n- a `short` representing the prefix length for the subnet of that address. \n\n#### public int\n**hashCode**\n()\n\nReturns a hashcode for this Interface address. \n\n##### Returns\n\n- a hash code value for this Interface address. \n\n#### public [String](../../../reference/java/lang/String.html)\n**toString**\n()\n\nConverts this Interface address to a `String`. The\nstring returned is of the form: InetAddress / prefix length \\[ broadcast address \\]. \n\n##### Returns\n\n- a string representation of this Interface address."]]