mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-23 05:15:04 +00:00
Network: Allow to specify sub interfaces (virtual) in network configuration, closes #1667.
This commit is contained in:
parent
44a6040293
commit
437eda6b5b
@ -232,12 +232,21 @@ public abstract class NetworkUtils {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all the available interfaces, including first level sub interfaces.
|
||||
*/
|
||||
public static List<NetworkInterface> getAllAvailableInterfaces() throws SocketException {
|
||||
List<NetworkInterface> allInterfaces = new ArrayList<NetworkInterface>(10);
|
||||
NetworkInterface intf;
|
||||
for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
|
||||
intf = (NetworkInterface) en.nextElement();
|
||||
allInterfaces.add(intf);
|
||||
List<NetworkInterface> allInterfaces = new ArrayList<NetworkInterface>();
|
||||
for (Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); interfaces.hasMoreElements(); ) {
|
||||
NetworkInterface intf = interfaces.nextElement();
|
||||
allInterfaces.add(interfaces.nextElement());
|
||||
|
||||
Enumeration<NetworkInterface> subInterfaces = intf.getSubInterfaces();
|
||||
if (subInterfaces != null && subInterfaces.hasMoreElements()) {
|
||||
while (subInterfaces.hasMoreElements()) {
|
||||
allInterfaces.add(subInterfaces.nextElement());
|
||||
}
|
||||
}
|
||||
}
|
||||
return allInterfaces;
|
||||
}
|
||||
|
@ -57,11 +57,11 @@ public class NetworkService extends AbstractComponent {
|
||||
if (logger.isDebugEnabled()) {
|
||||
StringBuilder netDebug = new StringBuilder("net_info");
|
||||
try {
|
||||
Enumeration<NetworkInterface> enum_ = NetworkInterface.getNetworkInterfaces();
|
||||
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
|
||||
String hostName = InetAddress.getLocalHost().getHostName();
|
||||
netDebug.append("\nhost [").append(hostName).append("]\n");
|
||||
while (enum_.hasMoreElements()) {
|
||||
NetworkInterface net = enum_.nextElement();
|
||||
while (interfaces.hasMoreElements()) {
|
||||
NetworkInterface net = interfaces.nextElement();
|
||||
|
||||
netDebug.append(net.getName()).append('\t').append("display_name [").append(net.getDisplayName()).append("]\n");
|
||||
Enumeration<InetAddress> addresses = net.getInetAddresses();
|
||||
@ -73,9 +73,30 @@ public class NetworkService extends AbstractComponent {
|
||||
netDebug.append("\t\tmtu [").append(net.getMTU()).append("] multicast [").append(net.supportsMulticast()).append("] ptp [").append(net.isPointToPoint())
|
||||
.append("] loopback [").append(net.isLoopback()).append("] up [").append(net.isUp()).append("] virtual [").append(net.isVirtual()).append("]")
|
||||
.append('\n');
|
||||
|
||||
Enumeration<NetworkInterface> subInterfaces = net.getSubInterfaces();
|
||||
if (subInterfaces != null && subInterfaces.hasMoreElements()) {
|
||||
netDebug.append("\t\t\tsub interfaces:\n");
|
||||
|
||||
while (subInterfaces.hasMoreElements()) {
|
||||
|
||||
net = subInterfaces.nextElement();
|
||||
|
||||
netDebug.append("\t\t\t").append(net.getName()).append("\t").append("display_name [").append(net.getDisplayName()).append("]\n");
|
||||
addresses = net.getInetAddresses();
|
||||
netDebug.append("\t\t\t\t\taddress ");
|
||||
while (addresses.hasMoreElements()) {
|
||||
netDebug.append("[").append(addresses.nextElement()).append("] ");
|
||||
}
|
||||
netDebug.append('\n');
|
||||
netDebug.append("\t\t\t\t\tmtu [").append(net.getMTU()).append("] multicast [").append(net.supportsMulticast()).append("] ptp [").append(net.isPointToPoint())
|
||||
.append("] loopback [").append(net.isLoopback()).append("] up [").append(net.isUp()).append("] virtual [").append(net.isVirtual()).append("]")
|
||||
.append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
netDebug.append("Failed to get Network Interface Info [" + ex.getMessage() + "]");
|
||||
netDebug.append("failed to get Network Interface Info [" + ex.getMessage() + "]");
|
||||
}
|
||||
logger.debug(netDebug.toString());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user