diff options
-rw-r--r-- | third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SimpleServer.java | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SimpleServer.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SimpleServer.java index db7255a..40c32e7 100644 --- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SimpleServer.java +++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SimpleServer.java @@ -138,17 +138,19 @@ public abstract class SimpleServer { InetAddress candidate = null; Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); - for (NetworkInterface netint : Collections.list(nets)) { - if (!netint.isLoopback() || !netint.isUp()) { // Ignore if localhost or not active - continue; - } - Enumeration<InetAddress> addresses = netint.getInetAddresses(); - for (InetAddress address : Collections.list(addresses)) { - if (address instanceof Inet4Address) { - Log.d("local address " + address); - return address; // Prefer ipv4 + if (nets != null) { + for (NetworkInterface netint : Collections.list(nets)) { + if (!netint.isLoopback() || !netint.isUp()) { // Ignore if localhost or not active + continue; + } + Enumeration<InetAddress> addresses = netint.getInetAddresses(); + for (InetAddress address : Collections.list(addresses)) { + if (address instanceof Inet4Address) { + Log.d("local address " + address); + return address; // Prefer ipv4 + } + candidate = address; // Probably an ipv6 } - candidate = address; // Probably an ipv6 } } if (candidate != null) { |