A Network Interface is an abstraction encapsulating the characteristics of a Network Interface Controller, or Virtual Network adapter, which is a system hardware/software component connecting a computer, or host system, to a computer network. A Network Interface can be physical or virtual. A Network Interface has a name, zero or more assigned IP addresses, zero or more MAC Addresses, and may have an index. The name is highly platform specific but a name such as "le0" is typical; it may not be unique. The index is a highly platform specific number that identifies the interface. The network configuration may change during the lifetime of the JVM. For example, the set of IP addresses assigned to a network interface can be transient and dynamically allocated, and may change at any time.
When obtaining a NetworkInterface
instance, part of its
configuration (such as its name and the list of assigned IP addresses),
is reflective of its configuration at creation time.
Obtaining an updated view of the network configuration may require
looking up a network interface again in order to obtain a new instance.
Network interface instances are typically used to identify the local interface on which a multicast group is joined.
API Note
Several static methods in this class are
factory methods, returning a new instance of a NetworkInterface
,
reflecting the configuration at the time of instantiation.
The network configuration may change at any time, and as such,
these methods may need to be invoked again in order to obtain
a more up-to-date view of the network interfaces.
In particular, there is no guarantee that the same interface will be
found at the same index, or that the same network addresses will be
bound to the interface, if the network configuration of the system
has changed.
Modifier and Type | Field and Description |
---|---|
private InetAddress[] | |
private InterfaceAddress[] | |
private NetworkInterface[] | |
private static final NetworkInterface | |
private String | |
private int | |
private String | |
private NetworkInterface | |
private boolean |
Access | Constructor and Description |
---|---|
pack-priv | |
pack-priv |
Modifier and Type | Method and Description |
---|---|
private static native boolean | |
private static <T> Enumeration | |
public boolean | Returns: true if the objects are the same;
false otherwise.the object to compare against. obj)Overrides java. Compares this object against the specified object. |
private static native NetworkInterface[] | |
public static NetworkInterface | Returns: the NetworkInterface obtained from its index, ornull if
there is no interface with such an index on the systeman integer, the index of the interface index)Get a network interface given its index. |
private static native NetworkInterface | |
public static NetworkInterface | Returns: ANetworkInterface
or null if there is no network interface
with the specified IP address.The addr)InetAddress to search with.Convenience method to search for a network interface that has the specified Internet Protocol (IP) address bound to it. |
private static native NetworkInterface | |
public static NetworkInterface | |
private static native NetworkInterface | |
pack-priv static NetworkInterface | |
public String | Returns: a non-empty string representing the display name of this network interface, or null if no display name is available.Get the display name of this network interface. |
public byte[] | Returns: a byte array containing the address, ornull if
the address doesn't exist or is not accessibleReturns the hardware address (usually MAC) of the interface if it has one and if it can be accessed given the current privileges. |
public int | Returns: the index of this network interface or-1 if the index is
unknownReturns the index of this network interface. |
public Enumeration | Returns: an Enumeration object with the InetAddresses bound to this network interfaceGet an Enumeration of the InetAddresses bound to this network interface. |
public List | Returns: aList object with the InterfaceAddress of this
network interfaceGet a List of the |
private static native byte[] | |
public int | Returns: the value of the MTU for that interface.Returns the Maximum Transmission Unit (MTU) of this interface. |
private static native int | |
public String | |
public static Enumeration | Returns: an Enumeration of NetworkInterfaces found on this machineReturns an |
public NetworkInterface | Returns: TheNetworkInterface this interface is attached to.Returns the parent NetworkInterface of this interface if this is
a subinterface, or |
public Enumeration | Returns: an Enumeration object with all of the subinterfaces of this network interfaceGet an Enumeration with all the subinterfaces (also known as virtual interfaces) attached to this network interface. |
public int | |
public Stream | Returns: a Stream object with the InetAddresses bound to this network interfaceGet a Stream of the InetAddresses bound to this network interface. |
private static native void | |
pack-priv static boolean | Returns: true iff the addr parameter is currently bound to one of the interfaces on this machine.The addr)InetAddress to search with.Checks if the given address is bound to any of the interfaces on this machine. |
public boolean | Returns: true if the interface is a loopback interface.Returns whether a network interface is a loopback interface. |
private static native boolean | |
private static native boolean | |
public boolean | Returns: true if the interface is a point to point
interface.Returns whether a network interface is a point to point interface. |
public boolean | Returns: true if the interface is up and running.Returns whether a network interface is up and running. |
private static native boolean | |
public boolean | Returns: true if this interface is a virtual interface.Returns whether this interface is a virtual interface (also called subinterface). |
public static Stream | Returns: a Stream of NetworkInterfaces found on this machineReturns a |
private static <T> Stream | |
public Stream | Returns: a Stream object with all of the subinterfaces of this network interfaceGet a Stream of all subinterfaces (also known as virtual interfaces) attached to this network interface. |
public boolean | Returns: true if the interface supports Multicasting.Returns whether a network interface supports multicasting or not. |
private static native boolean | |
public String |
addrs | back to summary |
---|---|
private InetAddress[] addrs |
bindings | back to summary |
---|---|
private InterfaceAddress[] bindings |
childs | back to summary |
---|---|
private NetworkInterface[] childs |
defaultInterface | back to summary |
---|---|
private static final NetworkInterface defaultInterface |
displayName | back to summary |
---|---|
private String displayName |
index | back to summary |
---|---|
private int index |
name | back to summary |
---|---|
private String name |
parent | back to summary |
---|---|
private NetworkInterface parent |
virtual | back to summary |
---|---|
private boolean virtual |
NetworkInterface | back to summary |
---|---|
pack-priv NetworkInterface() Returns an NetworkInterface object with index set to 0 and name to null. Setting such an interface on a MulticastSocket will cause the kernel to choose one interface for sending multicast packets. |
NetworkInterface | back to summary |
---|---|
pack-priv NetworkInterface(String name, int index, InetAddress[] addrs) |
boundInetAddress0 | back to summary |
---|---|
private static native boolean boundInetAddress0(InetAddress addr) throws SocketException |
enumerationFromArray | back to summary |
---|---|
private static <T> Enumeration |
equals | back to summary |
---|---|
public boolean equals(Object obj) Overrides java. Compares this object against the specified object.
The result is
Two instances of API Note two
|
getAll | back to summary |
---|---|
private static native NetworkInterface[] getAll() throws SocketException |
getByIndex | back to summary |
---|---|
public static NetworkInterface getByIndex(int index) throws SocketException Get a network interface given its index. API Note The returned interface instance may reflect a snapshot of the configuration taken at the time the instance is created. See the general discussion of snapshots and configuration for the semantics of the returned interface.
|
getByIndex0 | back to summary |
---|---|
private static native NetworkInterface getByIndex0(int index) throws SocketException |
getByInetAddress | back to summary |
---|---|
public static NetworkInterface getByInetAddress(InetAddress addr) throws 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. API Note The returned interface instance may reflect a snapshot of the configuration taken at the time the instance is created. See the general discussion of snapshots and configuration for the semantics of the returned interface.
|
getByInetAddress0 | back to summary |
---|---|
private static native NetworkInterface getByInetAddress0(InetAddress addr) throws SocketException |
getByName | back to summary |
---|---|
public static NetworkInterface getByName(String name) throws SocketException Searches for the network interface with the specified name. API Note The returned interface instance may reflect a snapshot of the configuration taken at the time the instance is created. See the general discussion of snapshots and configuration for the semantics of the returned interface.
|
getByName0 | back to summary |
---|---|
private static native NetworkInterface getByName0(String name) throws SocketException |
getDefault | back to summary |
---|---|
pack-priv static NetworkInterface getDefault() Returns the default network interface of this system
|
getDisplayName | back to summary |
---|---|
public String getDisplayName() Get the display name of this network interface. A display name is a human readable String describing the network device.
|
getHardwareAddress | back to summary |
---|---|
public byte[] getHardwareAddress() throws SocketException Returns the hardware address (usually MAC) of the interface if it has one and if it can be accessed given the current privileges.
|
getIndex | back to summary |
---|---|
public int getIndex() Returns the index of this network interface. The index is an integer greater
or equal to zero, or
|
getInetAddresses | back to summary |
---|---|
public Enumeration Get an Enumeration of the InetAddresses bound to this network interface. Implementation Note The returned enumeration contains the InetAddresses that were bound to the interface at the time the interface configuration was read
|
getInterfaceAddresses | back to summary |
---|---|
public List Get a List of the
|
getMacAddr0 | back to summary |
---|---|
private static native byte[] getMacAddr0(byte[] inAddr, String name, int ind) throws SocketException |
getMTU | back to summary |
---|---|
public int getMTU() throws SocketException Returns the Maximum Transmission Unit (MTU) of this interface.
|
getMTU0 | back to summary |
---|---|
private static native int getMTU0(String name, int ind) throws SocketException |
getName | back to summary |
---|---|
public String getName() Get the name of this network interface.
|
getNetworkInterfaces | back to summary |
---|---|
public static Enumeration Returns an API Note This method can be used in combination with
The returned interface instances may reflect a snapshot of the configuration taken at the time the instance is created. See the general discussion of snapshots and configuration for the semantics of the returned interface.
|
getParent | back to summary |
---|---|
public NetworkInterface getParent() Returns the parent NetworkInterface of this interface if this is
a subinterface, or
|
getSubInterfaces | back to summary |
---|---|
public Enumeration Get an Enumeration with all the subinterfaces (also known as virtual interfaces) attached to this network interface. For instance eth0:1 will be a subinterface to eth0.
|
hashCode | back to summary |
---|---|
public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
|
inetAddresses | back to summary |
---|---|
public Stream Get a Stream of the InetAddresses bound to this network interface. Implementation Note The stream contains the InetAddresses that were bound to the interface at the time the interface configuration was read
|
init | back to summary |
---|---|
private static native void init() |
isBoundInetAddress | back to summary |
---|---|
pack-priv static boolean isBoundInetAddress(InetAddress addr) throws SocketException Checks if the given address is bound to any of the interfaces on this machine.
|
isLoopback | back to summary |
---|---|
public boolean isLoopback() throws SocketException Returns whether a network interface is a loopback interface.
|
isLoopback0 | back to summary |
---|---|
private static native boolean isLoopback0(String name, int ind) throws SocketException |
isP2P0 | back to summary |
---|---|
private static native boolean isP2P0(String name, int ind) throws SocketException |
isPointToPoint | back to summary |
---|---|
public boolean isPointToPoint() throws SocketException Returns whether a network interface is a point to point interface. A typical point to point interface would be a PPP connection through a modem.
|
isUp | back to summary |
---|---|
public boolean isUp() throws SocketException Returns whether a network interface is up and running.
|
isUp0 | back to summary |
---|---|
private static native boolean isUp0(String name, int ind) throws SocketException |
isVirtual | back to summary |
---|---|
public boolean isVirtual() Returns whether this interface is a virtual interface (also called subinterface). Virtual interfaces are, on some systems, interfaces created as a child of a physical interface and given different settings (like address or MTU). Usually the name of the interface will the name of the parent followed by a colon (:) and a number identifying the child since there can be several virtual interfaces attached to a single physical interface.
|
networkInterfaces | back to summary |
---|---|
public static Stream Returns a API Note This method can be used in combination with
The returned interface instances may reflect a snapshot of the configuration taken at the time the instance is created. See the general discussion of snapshots and configuration for the semantics of the returned interface.
|
streamFromArray | back to summary |
---|---|
private static <T> Stream |
subInterfaces | back to summary |
---|---|
public Stream Get a Stream of all subinterfaces (also known as virtual interfaces) attached to this network interface.
|
supportsMulticast | back to summary |
---|---|
public boolean supportsMulticast() throws SocketException Returns whether a network interface supports multicasting or not.
|
supportsMulticast0 | back to summary |
---|---|
private static native boolean supportsMulticast0(String name, int ind) throws SocketException |
toString | back to summary |
---|---|
public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non-
|