Use loopback when localhost is not resolved

we use the "local host" address in sevearl places in our networking layer, if local host is not resolved for some reason, still continue and operate but using the loopback interface
This commit is contained in:
Shay Banon 2014-04-08 00:42:32 +02:00
parent f26e9e784f
commit aa86a51070
1 changed files with 4 additions and 3 deletions

View File

@ -49,11 +49,12 @@ public abstract class NetworkUtils {
private final static InetAddress localAddress;
static {
InetAddress localAddressX = null;
InetAddress localAddressX;
try {
localAddressX = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
logger.trace("Failed to find local host", e);
} catch (Throwable e) {
logger.warn("failed to resolve local host, fallback to loopback", e);
localAddressX = InetAddress.getLoopbackAddress();
}
localAddress = localAddressX;
}