Skip to content
Snippets Groups Projects
Commit d02c9244 authored by Lucas Chiesa's avatar Lucas Chiesa Committed by Daniel Stonier
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 d48c49a2
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,7 @@ import java.net.InetAddress; ...@@ -25,6 +25,7 @@ import java.net.InetAddress;
import java.net.NetworkInterface; import java.net.NetworkInterface;
import java.net.SocketException; import java.net.SocketException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
...@@ -43,13 +44,7 @@ public class InetAddressFactory { ...@@ -43,13 +44,7 @@ public class InetAddressFactory {
return address.getAddress().length == 4; return address.getAddress().length == 4;
} }
private static Collection<InetAddress> getAllInetAddresses() { private static List<InetAddress> listAllInetAddress (Collection<NetworkInterface> networkInterfaces) {
List<NetworkInterface> networkInterfaces;
try {
networkInterfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
} catch (SocketException e) {
throw new RosRuntimeException(e);
}
List<InetAddress> inetAddresses = Lists.newArrayList(); List<InetAddress> inetAddresses = Lists.newArrayList();
for (NetworkInterface networkInterface : networkInterfaces) { for (NetworkInterface networkInterface : networkInterfaces) {
try { try {
...@@ -63,8 +58,18 @@ public class InetAddressFactory { ...@@ -63,8 +58,18 @@ public class InetAddressFactory {
return inetAddresses; return inetAddresses;
} }
public static InetAddress newNonLoopback() { private static Collection<InetAddress> getAllInetAddresses() {
for (InetAddress address : 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. // IPv4 only for now.
if (!address.isLoopbackAddress() && isIpv4(address)) { if (!address.isLoopbackAddress() && isIpv4(address)) {
return address; return address;
...@@ -73,6 +78,14 @@ public class InetAddressFactory { ...@@ -73,6 +78,14 @@ public class InetAddressFactory {
throw new RosRuntimeException("No non-loopback interface found."); 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) { private static Collection<InetAddress> getAllInetAddressByName(String host) {
InetAddress[] allAddressesByName; InetAddress[] allAddressesByName;
try { try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment