diff --git a/src/share/classes/java/net/NetworkInterface.java b/src/share/classes/java/net/NetworkInterface.java
index 51ebf23917bb6afdf863e05232371b67e3e2ac23..2dd0e96a390c6e7e20392bba8a4816408d5bf957 100644
--- a/src/share/classes/java/net/NetworkInterface.java
+++ b/src/share/classes/java/net/NetworkInterface.java
@@ -86,7 +86,9 @@ public final class NetworkInterface {
* 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.
+ * will be returned in the Enumeration. However, if the caller has the
+ * {@link NetPermission}("getNetworkInformation") permission, then all
+ * InetAddresses are returned.
* @return an Enumeration object with all or a subset of the InetAddresses
* bound to this network interface
*/
@@ -99,11 +101,19 @@ public final class NetworkInterface {
checkedAddresses() {
local_addrs = new InetAddress[addrs.length];
+ boolean trusted = true;
SecurityManager sec = System.getSecurityManager();
+ if (sec != null) {
+ try {
+ sec.checkPermission(new NetPermission("getNetworkInformation"));
+ } catch (SecurityException e) {
+ trusted = false;
+ }
+ }
for (int j=0; jnull if
+ * the address doesn't exist, is not accessible or a security
+ * manager is set and the caller does not have the permission
+ * NetPermission("getNetworkInformation")
*
- * @return a byte array containing the address or null if
- * the address doesn't exist or is not accessible.
* @exception SocketException if an I/O error occurs.
* @since 1.6
*/
public byte[] getHardwareAddress() throws SocketException {
+ SecurityManager sec = System.getSecurityManager();
+ if (sec != null) {
+ try {
+ sec.checkPermission(new NetPermission("getNetworkInformation"));
+ } catch (SecurityException e) {
+ if (!getInetAddresses().hasMoreElements()) {
+ // don't have connect permission to any local address
+ return null;
+ }
+ }
+ }
for (InetAddress addr : addrs) {
if (addr instanceof Inet4Address) {
return getMacAddr0(((Inet4Address)addr).getAddress(), name, index);
@@ -523,11 +549,10 @@ public final class NetworkInterface {
}
public int hashCode() {
- int count = 0;
- if (addrs != null) {
- for (int i = 0; i < addrs.length; i++) {
- count += addrs[i].hashCode();
- }
+ int count = name == null? 0: name.hashCode();
+ Enumeration addrs = getInetAddresses();
+ while (addrs.hasMoreElements()) {
+ count += addrs.nextElement().hashCode();
}
return count;
}