Skip to content
Snippets Groups Projects
Commit 78d36842 authored by Lucas Chiesa's avatar Lucas Chiesa
Browse files

Adds newNonLoopbackForNetworkInterface

This is needed to allow the user to specify the ROS Hostname.
An example application can: Run the ROS application through a VPN
connection. The user would like to use the tunnel interface
to creates the nodes and master.
parent 6858711d
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,7 @@ import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
......@@ -43,13 +44,7 @@ public class InetAddressFactory {
return address.getAddress().length == 4;
}
private static Collection<InetAddress> getAllInetAddresses() {
List<NetworkInterface> networkInterfaces;
try {
networkInterfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
} catch (SocketException e) {
throw new RosRuntimeException(e);
}
private static List<InetAddress> listAllInetAddress (Collection<NetworkInterface> networkInterfaces) {
List<InetAddress> inetAddresses = Lists.newArrayList();
for (NetworkInterface networkInterface : networkInterfaces) {
try {
......@@ -63,8 +58,18 @@ public class InetAddressFactory {
return inetAddresses;
}
public static InetAddress newNonLoopback() {
for (InetAddress address : getAllInetAddresses()) {
private static Collection<InetAddress> getAllInetAddresses() {
List<NetworkInterface> networkInterfaces;
try {
networkInterfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
} catch (SocketException e) {
throw new RosRuntimeException(e);
}
return listAllInetAddress(networkInterfaces);
}
private static InetAddress filterInetAddresses (Collection<InetAddress> inetAddresses) {
for (InetAddress address : inetAddresses) {
// IPv4 only for now.
if (!address.isLoopbackAddress() && isIpv4(address)) {
return address;
......@@ -73,6 +78,14 @@ public class InetAddressFactory {
throw new RosRuntimeException("No non-loopback interface found.");
}
public static InetAddress newNonLoopback() {
return filterInetAddresses(getAllInetAddresses());
}
public static InetAddress newNonLoopbackForNetworkInterface(NetworkInterface networkInterface) {
return filterInetAddresses(Collections.list(networkInterface.getInetAddresses()));
}
private static Collection<InetAddress> getAllInetAddressByName(String host) {
InetAddress[] allAddressesByName;
try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment