mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-29 02:21:41 +00:00
Fix exception thrown when isUp() is called on an unavailable network interface (#1679)
This commit is contained in:
@@ -274,9 +274,8 @@ public class NetworkManager {
|
||||
logger.warn("Interface " + devName + " is disconnected, check Ethernet!");
|
||||
}
|
||||
}
|
||||
NetworkInterface iFace;
|
||||
iFace = NetworkInterface.getByName(devName);
|
||||
if (iFace.isUp()) {
|
||||
var iFace = NetworkInterface.getByName(devName);
|
||||
if (iFace != null && iFace.isUp()) {
|
||||
String tmpAddresses = "";
|
||||
tmpAddresses = iFace.getInterfaceAddresses().toString();
|
||||
if (!last.addresses.equals(tmpAddresses)) {
|
||||
|
||||
@@ -188,16 +188,16 @@ public class NetworkUtils {
|
||||
List<String> addresses = new ArrayList<String>();
|
||||
try {
|
||||
var iFace = NetworkInterface.getByName(iFaceName);
|
||||
for (var addr : iFace.getInterfaceAddresses()) {
|
||||
var addrStr = addr.getAddress().toString();
|
||||
if (addrStr.startsWith("/")) {
|
||||
addrStr = addrStr.substring(1);
|
||||
if (iFace != null && iFace.isUp()) {
|
||||
for (var addr : iFace.getInterfaceAddresses()) {
|
||||
var addrStr = addr.getAddress().toString();
|
||||
if (addrStr.startsWith("/")) {
|
||||
addrStr = addrStr.substring(1);
|
||||
}
|
||||
addrStr = addrStr + "/" + addr.getNetworkPrefixLength();
|
||||
addresses.add(addrStr);
|
||||
}
|
||||
addrStr = addrStr + "/" + addr.getNetworkPrefixLength();
|
||||
addresses.add(addrStr);
|
||||
}
|
||||
// addresses = iFace.inetAddresses().map(a ->
|
||||
// a.getAddress().toString()).collect(Collectors.joining(","));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user