Fix getting outbound route from inbound address

This commit is contained in:
BWS Systems
2020-03-26 13:34:27 -04:00
parent a3fd2ca722
commit c376253488
2 changed files with 13 additions and 2 deletions

View File

@@ -98,6 +98,7 @@ public class UpnpSettingsResource {
if(theSettings.isUseupnpiface()) {
httpLocationAddr = theSettings.getUpnpConfigAddress();
} else {
log.debug("Get Outbound address for ip:" + request.ip() + " and port:" + request.port());
httpLocationAddr = AddressUtil.getOutboundAddress(request.ip(), request.port()).getHostAddress();
}
hueTemplate = hueTemplate_pre + hueTemplate_post;

View File

@@ -15,9 +15,11 @@ public class AddressUtil {
// in the LOCATION header in replies
public static InetAddress getOutboundAddress(String remoteAddress, int remotePort) {
InetAddress localAddress = null;
log.debug("Entering getOutboundAddress with args.");
try {
getOutboundAddress(new InetSocketAddress(remoteAddress, remotePort));
localAddress = getOutboundAddress(new InetSocketAddress(remoteAddress, remotePort));
} catch (Exception e) {
log.debug("getOutboundAddress(SocketAddress) Threw an Exception: " + e.getMessage());
ParseRoute theRoute = ParseRoute.getInstance();
try {
localAddress = InetAddress.getByName(theRoute.getLocalIPAddress());
@@ -29,7 +31,9 @@ public class AddressUtil {
}
if(localAddress != null)
log.debug("getOutbountAddress returning IP Address of " + localAddress.getHostAddress());
log.debug("localAddress is IP Address of " + localAddress.getHostAddress());
else
log.debug("localAddress returning NULL");
return localAddress;
}
@@ -42,11 +46,17 @@ public class AddressUtil {
DatagramSocket sock = new DatagramSocket();
// connect is needed to bind the socket and retrieve the local address
// later (it would return 0.0.0.0 otherwise)
log.debug("Entering getOutboundAddress with socket arg.");
sock.connect(remoteAddress);
log.debug("getOutboundAddress(SocketAddress) getLocalAddress.");
final InetAddress localAddress = sock.getLocalAddress();
sock.disconnect();
sock.close();
sock = null;
if(localAddress != null)
log.debug("getOutbountAddress(SocketAddress) returning IP Address of " + localAddress.getHostAddress());
else
log.debug("getOutboundAddress(SocketAddress) returning NULL");
return localAddress;
}
}