435 * @return a byte array containing the address, or {@code null} if 436 * the address doesn't exist, is not accessible or a security 437 * manager is set and the caller does not have the permission 438 * NetPermission("getNetworkInformation") 439 * 440 * @exception SocketException if an I/O error occurs. 441 * @since 1.6 442 */ 443 public byte[] getHardwareAddress() throws SocketException { 444 SecurityManager sec = System.getSecurityManager(); 445 if (sec != null) { 446 try { 447 sec.checkPermission(new NetPermission("getNetworkInformation")); 448 } catch (SecurityException e) { 449 if (!getInetAddresses().hasMoreElements()) { 450 // don't have connect permission to any local address 451 return null; 452 } 453 } 454 } 455 for (InetAddress addr : addrs) { 456 if (addr instanceof Inet4Address) { 457 return getMacAddr0(((Inet4Address)addr).getAddress(), name, index); 458 } 459 } 460 return getMacAddr0(null, name, index); 461 } 462 463 /** 464 * Returns the Maximum Transmission Unit (MTU) of this interface. 465 * 466 * @return the value of the MTU for that interface. 467 * @exception SocketException if an I/O error occurs. 468 * @since 1.6 469 */ 470 public int getMTU() throws SocketException { 471 return getMTU0(name, index); 472 } 473 474 /** | 435 * @return a byte array containing the address, or {@code null} if 436 * the address doesn't exist, is not accessible or a security 437 * manager is set and the caller does not have the permission 438 * NetPermission("getNetworkInformation") 439 * 440 * @exception SocketException if an I/O error occurs. 441 * @since 1.6 442 */ 443 public byte[] getHardwareAddress() throws SocketException { 444 SecurityManager sec = System.getSecurityManager(); 445 if (sec != null) { 446 try { 447 sec.checkPermission(new NetPermission("getNetworkInformation")); 448 } catch (SecurityException e) { 449 if (!getInetAddresses().hasMoreElements()) { 450 // don't have connect permission to any local address 451 return null; 452 } 453 } 454 } 455 return getHardwareAddress0(); 456 } 457 458 // the same as getHardwareAddress(), but without security checks 459 byte[] getHardwareAddress0() throws SocketException { 460 for (InetAddress addr : addrs) { 461 if (addr instanceof Inet4Address) { 462 return getMacAddr0(((Inet4Address)addr).getAddress(), name, index); 463 } 464 } 465 return getMacAddr0(null, name, index); 466 } 467 468 /** 469 * Returns the Maximum Transmission Unit (MTU) of this interface. 470 * 471 * @return the value of the MTU for that interface. 472 * @exception SocketException if an I/O error occurs. 473 * @since 1.6 474 */ 475 public int getMTU() throws SocketException { 476 return getMTU0(name, index); 477 } 478 479 /** |