public static boolean treatAsBindException(SocketException se, InetAddress bindAddress) { // if bind address is not of this machine then fail if (!SocketCreator.isLocalHost(bindAddress)) { return false; } if(se instanceof BindException) { return true; } final String msg = se.getMessage(); return (msg != null && msg.contains("Invalid argument: listen failed")); }
protected void checkServerBindAddress(String value) { _checkIfModifiable(SERVER_BIND_ADDRESS_NAME); if (value != null && value.length() > 0 && !SocketCreator.isLocalHost(value)) { throw new IllegalArgumentException( LocalizedStrings.AbstractDistributionConfig_BIND_ADDRESS_0_INVALID_MUST_BE_IN_1 .toLocalizedString(new Object[]{value, SocketCreator.getMyAddresses(true) })); } } public boolean isServerBindAddressModifiable() {
protected void checkServerBindAddress(String value) { _checkIfModifiable(SERVER_BIND_ADDRESS_NAME); if (value != null && value.length() > 0 && !SocketCreator.isLocalHost(value)) { throw new IllegalArgumentException( LocalizedStrings.AbstractDistributionConfig_BIND_ADDRESS_0_INVALID_MUST_BE_IN_1 .toLocalizedString(new Object[]{value, SocketCreator.getMyAddresses() })); } } public boolean isServerBindAddressModifiable() {
protected void checkMemcachedBindAddress(String value) { _checkIfModifiable(MEMCACHED_BIND_ADDRESS_NAME); if (value != null && value.length() > 0 && !SocketCreator.isLocalHost(value)) { throw new IllegalArgumentException( LocalizedStrings.AbstractDistributionConfig_MEMCACHED_BIND_ADDRESS_0_INVALID_MUST_BE_IN_1 .toLocalizedString(new Object[]{value, SocketCreator.getMyAddresses() })); } } public boolean isMemcachedBindAddressModifiable() {
protected void checkBindAddress(String value) { _checkIfModifiable(BIND_ADDRESS_NAME); if (value != null && value.length() > 0 && !SocketCreator.isLocalHost(value)) { throw new IllegalArgumentException( LocalizedStrings.AbstractDistributionConfig_BIND_ADDRESS_0_INVALID_MUST_BE_IN_1 .toLocalizedString(new Object[]{value, SocketCreator.getMyAddresses(true) })); } } public boolean isBindAddressModifiable() {
protected void checkBindAddress(String value) { _checkIfModifiable(BIND_ADDRESS_NAME); if (value != null && value.length() > 0 && !SocketCreator.isLocalHost(value)) { throw new IllegalArgumentException( LocalizedStrings.AbstractDistributionConfig_BIND_ADDRESS_0_INVALID_MUST_BE_IN_1 .toLocalizedString(new Object[]{value, SocketCreator.getMyAddresses() })); } } public boolean isBindAddressModifiable() {
protected void checkHttpServiceBindAddress(String value) { _checkIfModifiable(HTTP_SERVICE_BIND_ADDRESS_NAME); if (value != null && value.length() > 0 && !SocketCreator.isLocalHost(value)) { throw new IllegalArgumentException( LocalizedStrings.AbstractDistributionConfig_BIND_ADDRESS_0_INVALID_MUST_BE_IN_1 .toLocalizedString(new Object[]{value, SocketCreator.getMyAddresses() })); } }
protected void checkRedisBindAddress(String value) { _checkIfModifiable(REDIS_BIND_ADDRESS_NAME); if (value != null && value.length() > 0 && !SocketCreator.isLocalHost(value)) { throw new IllegalArgumentException( LocalizedStrings.AbstractDistributionConfig_REDIS_BIND_ADDRESS_0_INVALID_MUST_BE_IN_1 .toLocalizedString(new Object[]{value, SocketCreator.getMyAddresses() })); } }
/** Returns true if host matches the LOCALHOST. */ public static boolean isLocalHost(Object host) { if (host instanceof InetAddress) { if (InetAddressUtil.LOCALHOST.equals(host)) { return true; } else { try { Enumeration en=NetworkInterface.getNetworkInterfaces(); while(en.hasMoreElements()) { NetworkInterface i=(NetworkInterface)en.nextElement(); for(Enumeration en2=i.getInetAddresses(); en2.hasMoreElements();) { InetAddress addr=(InetAddress)en2.nextElement(); if (host.equals(addr)) { return true; } } } return false; } catch (SocketException e) { throw new IllegalArgumentException(LocalizedStrings.InetAddressUtil_UNABLE_TO_QUERY_NETWORK_INTERFACE.toLocalizedString(), e); } } } else { return isLocalHost(toInetAddress(host.toString())); } }
return isLocalHost(toInetAddress(host.toString()));
!SocketCreator.isLocalHost(bindHostAddress)) {