1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-03-13 10:29:35 +01:00

Some configuration may totally miss network interfaces, even localhost. Fixes #4249

This commit is contained in:
Federico Fissore 2015-12-04 09:55:17 +01:00
parent a2848716a0
commit 9a39e5e6ac

View File

@ -31,6 +31,8 @@ package cc.arduino.packages.discoverers.network;
import javax.jmdns.NetworkTopologyDiscovery;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.*;
public class NetworkChecker extends TimerTask {
@ -53,6 +55,9 @@ public class NetworkChecker extends TimerTask {
@Override
public void run() {
if (!hasNetworkInterfaces()) {
return;
}
try {
InetAddress[] curentAddresses = topology.getInetAddresses();
Set<InetAddress> current = new HashSet<>(curentAddresses.length);
@ -68,4 +73,12 @@ public class NetworkChecker extends TimerTask {
e.printStackTrace();
}
}
private boolean hasNetworkInterfaces() {
try {
return NetworkInterface.getNetworkInterfaces() != null;
} catch (SocketException e) {
return false;
}
}
}