Methods Summary |
---|
public boolean | equals(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.
if ((obj == null) || !(obj instanceof NetworkInterface)) {
return false;
}
NetworkInterface netIF = (NetworkInterface)obj;
if (name != null ) {
if (netIF.getName() != null) {
if (!name.equals(netIF.getName())) {
return false;
}
} else {
return false;
}
} else {
if (netIF.getName() != null) {
return false;
}
}
Enumeration newAddrs = netIF.getInetAddresses();
int i = 0;
for (i = 0; newAddrs.hasMoreElements();newAddrs.nextElement(), i++);
if (addrs == null) {
if (i != 0) {
return false;
}
} else {
/*
* Compare number of addresses (in the checked subset)
*/
int count = 0;
Enumeration e = getInetAddresses();
for (; e.hasMoreElements(); count++) {
e.nextElement();
}
if (i != count) {
return false;
}
}
newAddrs = netIF.getInetAddresses();
for (; newAddrs.hasMoreElements();) {
boolean equal = false;
Enumeration thisAddrs = getInetAddresses();
InetAddress newAddr = (InetAddress)newAddrs.nextElement();
for (; thisAddrs.hasMoreElements();) {
InetAddress thisAddr = (InetAddress)thisAddrs.nextElement();
if (thisAddr.equals(newAddr)) {
equal = true;
}
}
if (!equal) {
return false;
}
}
return true;
|
private static native java.net.NetworkInterface[] | getAll()
|
static native java.net.NetworkInterface | getByIndex(int index)Get a network interface given its index.
|
public static java.net.NetworkInterface | getByInetAddress(java.net.InetAddress addr)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.
if (addr == null)
throw new NullPointerException();
return getByInetAddress0(addr);
|
private static native java.net.NetworkInterface | getByInetAddress0(java.net.InetAddress addr)
|
public static java.net.NetworkInterface | getByName(java.lang.String name)Searches for the network interface with the specified name.
if (name == null)
throw new NullPointerException();
return getByName0(name);
|
private static native java.net.NetworkInterface | getByName0(java.lang.String name)
|
public java.lang.String | getDisplayName()Get the display name of this network interface.
A display name is a human readable String describing the network
device.
return displayName;
|
int | getIndex()Get the index of this network interface.
return index;
|
public java.util.Enumeration | 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.
class checkedAddresses implements Enumeration<InetAddress> {
private int i=0, count=0;
private InetAddress local_addrs[];
checkedAddresses() {
local_addrs = new InetAddress[addrs.length];
SecurityManager sec = System.getSecurityManager();
for (int j=0; j<addrs.length; j++) {
try {
if (sec != null) {
sec.checkConnect(addrs[j].getHostAddress(), -1);
}
local_addrs[count++] = addrs[j];
} catch (SecurityException e) { }
}
}
public InetAddress nextElement() {
if (i < count) {
return local_addrs[i++];
} else {
throw new NoSuchElementException();
}
}
public boolean hasMoreElements() {
return (i < count);
}
}
return new checkedAddresses();
|
public java.lang.String | getName()Get the name of this network interface.
return name;
|
public static java.util.Enumeration | getNetworkInterfaces()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
final NetworkInterface[] netifs = getAll();
// specified to return null if no network interfaces
if (netifs == null)
return null;
return new Enumeration<NetworkInterface>() {
private int i = 0;
public NetworkInterface nextElement() {
if (netifs != null && i < netifs.length) {
NetworkInterface netif = netifs[i++];
return netif;
} else {
throw new NoSuchElementException();
}
}
public boolean hasMoreElements() {
return (netifs != null && i < netifs.length);
}
};
|
public int | hashCode()
int count = 0;
if (addrs != null) {
for (int i = 0; i < addrs.length; i++) {
count += addrs[i].hashCode();
}
}
return count;
|
private static native void | init()
|
public java.lang.String | toString()
String result = "name:";
result += name == null? "null": name;
if (displayName != null) {
result += " (" + displayName + ")";
}
result += " index: "+index+" addresses:\n";
for (Enumeration e = getInetAddresses(); e.hasMoreElements(); ) {
InetAddress addr = (InetAddress)e.nextElement();
result += addr+";\n";
}
return result;
|