Class AbstractNetworkIF
- java.lang.Object
-
- oshi.hardware.common.AbstractNetworkIF
-
- All Implemented Interfaces:
NetworkIF
- Direct Known Subclasses:
AixNetworkIF
,BsdNetworkIF
,LinuxNetworkIF
,MacNetworkIF
,SolarisNetworkIF
,WindowsNetworkIF
@ThreadSafe public abstract class AbstractNetworkIF extends java.lang.Object implements NetworkIF
Network interfaces implementation.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface oshi.hardware.NetworkIF
NetworkIF.IfOperStatus
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
displayName
private int
index
private java.lang.String[]
ipv4
private java.lang.String[]
ipv6
private static org.slf4j.Logger
LOG
private java.lang.String
mac
private long
mtu
private java.lang.String
name
private java.net.NetworkInterface
networkInterface
private static java.lang.String
OSHI_VM_MAC_ADDR_PROPERTIES
private java.lang.Short[]
prefixLengths
private java.lang.Short[]
subnetMasks
private java.util.function.Supplier<java.util.Properties>
vmMacAddrProps
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractNetworkIF(java.net.NetworkInterface netint)
Construct aNetworkIF
object backed by the specifiedNetworkInterface
.protected
AbstractNetworkIF(java.net.NetworkInterface netint, java.lang.String displayName)
Construct aNetworkIF
object backed by the specifiedNetworkInterface
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.util.List<java.net.NetworkInterface>
getAllNetworkInterfaces()
Returns all network interfaces.java.lang.String
getDisplayName()
Interface description.int
getIndex()
Interface index.java.lang.String[]
getIPv4addr()
The Internet Protocol (IP) v4 address.java.lang.String[]
getIPv6addr()
The Internet Protocol (IP) v6 address.java.lang.String
getMacaddr()
The Media Access Control (MAC) address.long
getMTU()
The interface Maximum Transmission Unit (MTU).java.lang.String
getName()
Interface name.protected static java.util.List<java.net.NetworkInterface>
getNetworkInterfaces(boolean includeLocalInterfaces)
Returns network interfaces on this machine.java.lang.Short[]
getPrefixLengths()
The Internet Protocol (IP) v6 address.java.lang.Short[]
getSubnetMasks()
The Internet Protocol (IP) v4 subnet masks.boolean
isKnownVmMacAddr()
Determines if the MAC address on this interface corresponds to a known Virtual Machine.private static boolean
isLocalInterface(java.net.NetworkInterface networkInterface)
java.net.NetworkInterface
queryNetworkInterface()
Gets theNetworkInterface
object.private static java.util.Properties
queryVmMacAddrProps()
java.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface oshi.hardware.NetworkIF
getBytesRecv, getBytesSent, getCollisions, getIfAlias, getIfOperStatus, getIfType, getInDrops, getInErrors, getNdisPhysicalMediumType, getOutErrors, getPacketsRecv, getPacketsSent, getSpeed, getTimeStamp, isConnectorPresent, updateAttributes
-
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
OSHI_VM_MAC_ADDR_PROPERTIES
private static final java.lang.String OSHI_VM_MAC_ADDR_PROPERTIES
- See Also:
- Constant Field Values
-
networkInterface
private java.net.NetworkInterface networkInterface
-
name
private java.lang.String name
-
displayName
private java.lang.String displayName
-
index
private int index
-
mtu
private long mtu
-
mac
private java.lang.String mac
-
ipv4
private java.lang.String[] ipv4
-
subnetMasks
private java.lang.Short[] subnetMasks
-
ipv6
private java.lang.String[] ipv6
-
prefixLengths
private java.lang.Short[] prefixLengths
-
vmMacAddrProps
private final java.util.function.Supplier<java.util.Properties> vmMacAddrProps
-
-
Constructor Detail
-
AbstractNetworkIF
protected AbstractNetworkIF(java.net.NetworkInterface netint) throws java.lang.InstantiationException
Construct aNetworkIF
object backed by the specifiedNetworkInterface
.- Parameters:
netint
- The core javaNetworkInterface
backing this object.- Throws:
java.lang.InstantiationException
- If a socket exception prevents access to the backing interface.
-
AbstractNetworkIF
protected AbstractNetworkIF(java.net.NetworkInterface netint, java.lang.String displayName) throws java.lang.InstantiationException
Construct aNetworkIF
object backed by the specifiedNetworkInterface
.- Parameters:
netint
- The core javaNetworkInterface
backing this object.displayName
- A string to use for the display name in preference to theNetworkInterface
value.- Throws:
java.lang.InstantiationException
- If a socket exception prevents access to the backing interface.
-
-
Method Detail
-
getNetworkInterfaces
protected static java.util.List<java.net.NetworkInterface> getNetworkInterfaces(boolean includeLocalInterfaces)
Returns network interfaces on this machine.- Parameters:
includeLocalInterfaces
- include local interfaces in the result- Returns:
- A list of network interfaces
-
getAllNetworkInterfaces
private static java.util.List<java.net.NetworkInterface> getAllNetworkInterfaces()
Returns all network interfaces.- Returns:
- A list of network interfaces
-
isLocalInterface
private static boolean isLocalInterface(java.net.NetworkInterface networkInterface)
-
queryNetworkInterface
public java.net.NetworkInterface queryNetworkInterface()
Description copied from interface:NetworkIF
Gets theNetworkInterface
object.- Specified by:
queryNetworkInterface
in interfaceNetworkIF
- Returns:
- the network interface, an instance of
NetworkInterface
.
-
getName
public java.lang.String getName()
Description copied from interface:NetworkIF
Interface name.
-
getIndex
public int getIndex()
Description copied from interface:NetworkIF
Interface index.
-
getDisplayName
public java.lang.String getDisplayName()
Description copied from interface:NetworkIF
Interface description.- Specified by:
getDisplayName
in interfaceNetworkIF
- Returns:
- The description of the network interface. On some platforms, this is identical to the name.
-
getMTU
public long getMTU()
Description copied from interface:NetworkIF
The interface Maximum Transmission Unit (MTU).- Specified by:
getMTU
in interfaceNetworkIF
- Returns:
- The MTU of the network interface.
The value is a 32-bit integer which may be unsigned on some operating systems. On Windows, some non-physical interfaces (e.g., loopback) may return a value of -1 which is equivalent to the maximum unsigned integer value.
This value is set when the
NetworkIF
is instantiated and may not be up to date.
-
getMacaddr
public java.lang.String getMacaddr()
Description copied from interface:NetworkIF
The Media Access Control (MAC) address.- Specified by:
getMacaddr
in interfaceNetworkIF
- Returns:
- The MAC Address.
This value is set when the
NetworkIF
is instantiated and may not be up to date.
-
getIPv4addr
public java.lang.String[] getIPv4addr()
Description copied from interface:NetworkIF
The Internet Protocol (IP) v4 address.- Specified by:
getIPv4addr
in interfaceNetworkIF
- Returns:
- An array of IPv4 Addresses.
This value is set when the
NetworkIF
is instantiated and may not be up to date.
-
getSubnetMasks
public java.lang.Short[] getSubnetMasks()
Description copied from interface:NetworkIF
The Internet Protocol (IP) v4 subnet masks.- Specified by:
getSubnetMasks
in interfaceNetworkIF
- Returns:
- An array of IPv4 subnet mask lengths, corresponding to the IPv4 addresses from
NetworkIF.getIPv4addr()
. Ranges between 0-32.This value is set when the
NetworkIF
is instantiated and may not be up to date.
-
getIPv6addr
public java.lang.String[] getIPv6addr()
Description copied from interface:NetworkIF
The Internet Protocol (IP) v6 address.- Specified by:
getIPv6addr
in interfaceNetworkIF
- Returns:
- An array of IPv6 Addresses.
This value is set when the
NetworkIF
is instantiated and may not be up to date.
-
getPrefixLengths
public java.lang.Short[] getPrefixLengths()
Description copied from interface:NetworkIF
The Internet Protocol (IP) v6 address.- Specified by:
getPrefixLengths
in interfaceNetworkIF
- Returns:
- The IPv6 address prefix lengths, corresponding to the IPv6 addresses from
NetworkIF.getIPv6addr()
. Ranges between 0-128.This value is set when the
NetworkIF
is instantiated and may not be up to date.
-
isKnownVmMacAddr
public boolean isKnownVmMacAddr()
Description copied from interface:NetworkIF
Determines if the MAC address on this interface corresponds to a known Virtual Machine.- Specified by:
isKnownVmMacAddr
in interfaceNetworkIF
- Returns:
true
if the MAC address corresponds to a known virtual machine.
-
queryVmMacAddrProps
private static java.util.Properties queryVmMacAddrProps()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-