in common/src/main/java/org/apache/omid/NetworkUtils.java [41:76]
public static String getDefaultNetworkInterface() {
try (DatagramSocket s=new DatagramSocket()) {
s.connect(InetAddress.getByAddress(new byte[]{1,1,1,1}), 53);
return NetworkInterface.getByInetAddress(s.getLocalAddress()).getName();
} catch (Exception e) {
//fall through
}
//Fall back to old logic
try {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
String fallBackName = null;
while (networkInterfaces.hasMoreElements()) {
NetworkInterface nextElement = networkInterfaces.nextElement();
String name = nextElement.getDisplayName();
LOG.info("Iterating over network interfaces, found '{}'", name);
boolean hasInet = Collections.list(nextElement.getInetAddresses()).size() > 0; // Checking that inet exists, to avoid taking iBridge
if (hasInet && fallBackName == null) {
fallBackName = name;
}
if ((name.startsWith(MAC_TSO_NET_IFACE_PREFIX) && hasInet ) ||
name.startsWith(LINUX_TSO_NET_IFACE_PREFIX)) {
return name;
}
}
if (fallBackName != null) {
return fallBackName;
}
} catch (SocketException ignored) {
throw new RuntimeException("Failed to find any network interfaces", ignored);
}
throw new IllegalArgumentException(String.format("No network '%s*'/'%s*' interfaces found",
MAC_TSO_NET_IFACE_PREFIX, LINUX_TSO_NET_IFACE_PREFIX));
}