Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
kurento-test: rewrite getter for Network Interface address
Browse files Browse the repository at this point in the history
Previous code was buggy because it used toString().

address.toString() returns "Hostname/IpAddress", which for the Docker
case it turned out to end up as "/IpAddress". Then this would be
inserted into the test page URL, with the extra slash, causing errors.
  • Loading branch information
j1elo committed Mar 26, 2020
1 parent 16746bb commit 6b05fff
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
Expand All @@ -36,6 +37,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -640,15 +642,13 @@ public String getContainerFirstNetworkName() {

public String getHostIpForContainers() {
try {
Enumeration<NetworkInterface> b = NetworkInterface.getNetworkInterfaces();
while (b.hasMoreElements()) {
NetworkInterface iface = b.nextElement();
if (iface.getName().contains("docker")) {
for (InterfaceAddress f : iface.getInterfaceAddresses()) {
if (f.getAddress().isSiteLocalAddress()) {
String addr = f.getAddress().toString();
log.debug("Host IP for container is {}", addr);
return addr;
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface netint : Collections.list(nets)) {
if (netint.getName().contains("docker")) {
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
for (InetAddress inetAddress : Collections.list(inetAddresses)) {
if (inetAddress.isSiteLocalAddress()) {
return inetAddress.getHostAddress();
}
}
}
Expand Down

0 comments on commit 6b05fff

Please sign in to comment.