mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-16 18:24:36 +00:00
Fix getting outbound route from inbound address
This commit is contained in:
@@ -98,6 +98,7 @@ public class UpnpSettingsResource {
|
|||||||
if(theSettings.isUseupnpiface()) {
|
if(theSettings.isUseupnpiface()) {
|
||||||
httpLocationAddr = theSettings.getUpnpConfigAddress();
|
httpLocationAddr = theSettings.getUpnpConfigAddress();
|
||||||
} else {
|
} else {
|
||||||
|
log.debug("Get Outbound address for ip:" + request.ip() + " and port:" + request.port());
|
||||||
httpLocationAddr = AddressUtil.getOutboundAddress(request.ip(), request.port()).getHostAddress();
|
httpLocationAddr = AddressUtil.getOutboundAddress(request.ip(), request.port()).getHostAddress();
|
||||||
}
|
}
|
||||||
hueTemplate = hueTemplate_pre + hueTemplate_post;
|
hueTemplate = hueTemplate_pre + hueTemplate_post;
|
||||||
|
|||||||
@@ -15,9 +15,11 @@ public class AddressUtil {
|
|||||||
// in the LOCATION header in replies
|
// in the LOCATION header in replies
|
||||||
public static InetAddress getOutboundAddress(String remoteAddress, int remotePort) {
|
public static InetAddress getOutboundAddress(String remoteAddress, int remotePort) {
|
||||||
InetAddress localAddress = null;
|
InetAddress localAddress = null;
|
||||||
|
log.debug("Entering getOutboundAddress with args.");
|
||||||
try {
|
try {
|
||||||
getOutboundAddress(new InetSocketAddress(remoteAddress, remotePort));
|
localAddress = getOutboundAddress(new InetSocketAddress(remoteAddress, remotePort));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
log.debug("getOutboundAddress(SocketAddress) Threw an Exception: " + e.getMessage());
|
||||||
ParseRoute theRoute = ParseRoute.getInstance();
|
ParseRoute theRoute = ParseRoute.getInstance();
|
||||||
try {
|
try {
|
||||||
localAddress = InetAddress.getByName(theRoute.getLocalIPAddress());
|
localAddress = InetAddress.getByName(theRoute.getLocalIPAddress());
|
||||||
@@ -29,7 +31,9 @@ public class AddressUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(localAddress != null)
|
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;
|
return localAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,11 +46,17 @@ public class AddressUtil {
|
|||||||
DatagramSocket sock = new DatagramSocket();
|
DatagramSocket sock = new DatagramSocket();
|
||||||
// connect is needed to bind the socket and retrieve the local address
|
// connect is needed to bind the socket and retrieve the local address
|
||||||
// later (it would return 0.0.0.0 otherwise)
|
// later (it would return 0.0.0.0 otherwise)
|
||||||
|
log.debug("Entering getOutboundAddress with socket arg.");
|
||||||
sock.connect(remoteAddress);
|
sock.connect(remoteAddress);
|
||||||
|
log.debug("getOutboundAddress(SocketAddress) getLocalAddress.");
|
||||||
final InetAddress localAddress = sock.getLocalAddress();
|
final InetAddress localAddress = sock.getLocalAddress();
|
||||||
sock.disconnect();
|
sock.disconnect();
|
||||||
sock.close();
|
sock.close();
|
||||||
sock = null;
|
sock = null;
|
||||||
|
if(localAddress != null)
|
||||||
|
log.debug("getOutbountAddress(SocketAddress) returning IP Address of " + localAddress.getHostAddress());
|
||||||
|
else
|
||||||
|
log.debug("getOutboundAddress(SocketAddress) returning NULL");
|
||||||
return localAddress;
|
return localAddress;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user