diff --git a/core/src/main/java/org/fourthline/cling/android/AndroidNetworkAddressFactory.java b/core/src/main/java/org/fourthline/cling/android/AndroidNetworkAddressFactory.java index 74d8bd479..d4dcb7b63 100644 --- a/core/src/main/java/org/fourthline/cling/android/AndroidNetworkAddressFactory.java +++ b/core/src/main/java/org/fourthline/cling/android/AndroidNetworkAddressFactory.java @@ -23,6 +23,7 @@ import java.net.Inet6Address; import java.net.InetAddress; import java.net.NetworkInterface; +import java.util.Enumeration; import java.util.logging.Level; import java.util.logging.Logger; @@ -110,4 +111,23 @@ protected void discoverNetworkInterfaces() throws InitializationException { super.discoverNetworkInterfaces(); } } + + public byte[] getHardwareAddress(InetAddress inetAddress) { + try { + if (inetAddress == null) { + throw new NullPointerException("inetAddress == null"); + } + for (NetworkInterface networkInterface : networkInterfaces) { + Enumeration e = networkInterface.getInetAddresses(); + while(e.hasMoreElements()) { + e.nextElement().equals(inetAddress); + return networkInterface.getHardwareAddress(); + } + } + return null; + } catch (Throwable ex) { + log.log(Level.WARNING, "Cannot get hardware address for: " + inetAddress, ex); + return null; + } + } }