Skip to content

Commit ffebc45

Browse files
committed
Fix Linux behavior
1 parent a926952 commit ffebc45

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

photon-core/src/main/java/org/photonvision/common/networking/NetworkUtils.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,14 @@ public static String getMacAddress() {
244244
}
245245
}
246246
// Connected to a localhost server or we are the server? Try resolving ourselves. Only
247-
// returns a localhost address when there's no other interface available
248-
byte[] mac =
249-
NetworkInterface.getByInetAddress(InetAddress.getLocalHost()).getHardwareAddress();
250-
if (mac != null) {
251-
return formatMacAddress(mac);
247+
// returns a localhost address when there's no other interface available on Windows, but
248+
// like to return a localhost address on Linux
249+
var localIface = NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
250+
if (localIface != null) {
251+
byte[] mac = localIface.getHardwareAddress();
252+
if (mac != null) {
253+
return formatMacAddress(mac);
254+
}
252255
}
253256
// Fine. Just find something with a MAC address
254257
for (var iface : NetworkInterface.networkInterfaces().toList()) {

0 commit comments

Comments
 (0)