From 79db2ed5847f2971217466b1ed1cadf1cbdbc3f5 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 14 Nov 2013 17:30:40 -0500 Subject: [PATCH] Fix a bug with MAC address selection that caused it to always select the first adapter --- src/com/limelight/nvstream/NvConnection.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/com/limelight/nvstream/NvConnection.java b/src/com/limelight/nvstream/NvConnection.java index 894f52ed..4e1b94f8 100644 --- a/src/com/limelight/nvstream/NvConnection.java +++ b/src/com/limelight/nvstream/NvConnection.java @@ -49,7 +49,8 @@ public class NvConnection { while (selectedIface == null && ifaceList.hasMoreElements()) { NetworkInterface iface = ifaceList.nextElement(); - if (iface.getName().startsWith("wlan")) { + if (iface.getName().startsWith("wlan") && + iface.getHardwareAddress() != null) { selectedIface = iface; } } @@ -59,15 +60,21 @@ public class NvConnection { while (selectedIface == null && ifaceList.hasMoreElements()) { NetworkInterface iface = ifaceList.nextElement(); - if (iface.getName().startsWith("eth")) { + if (iface.getName().startsWith("eth") && + iface.getHardwareAddress() != null) { selectedIface = iface; } } - // Now just find something + // Now just find something with a MAC address ifaceList = NetworkInterface.getNetworkInterfaces(); - if (ifaceList.hasMoreElements()) { + while (selectedIface == null && ifaceList.hasMoreElements()) { + NetworkInterface iface = ifaceList.nextElement(); + + if (iface.getHardwareAddress() != null) { selectedIface = ifaceList.nextElement(); + break; + } } if (selectedIface == null) { @@ -75,7 +82,7 @@ public class NvConnection { } byte[] macAddress = selectedIface.getHardwareAddress(); - if (macAddress != null && macAddress.length == 6) { + if (macAddress != null) { StringBuilder addrStr = new StringBuilder(); for (int i = 0; i < macAddress.length; i++) { addrStr.append(String.format("%02x", macAddress[i]));