Package org.apache.sshd.common.util.net
Class SshdSocketAddress
java.lang.Object
java.net.SocketAddress
org.apache.sshd.common.util.net.SshdSocketAddress
- All Implemented Interfaces:
Serializable
A simple socket address holding the host name and port number. The reason it does not extend
InetSocketAddress is twofold:
-
The
InetSocketAddressperforms a DNS resolution on the provided host name - which we don't want do use until we want to create a connection using this address (thus thetoInetSocketAddress()call which executes this query -
If empty host name is provided we replace it with the any address of 0.0.0.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Comparator<InetAddress> ComparesInetAddress-es according to theirInetAddress.getHostAddress()value case insensitivestatic final Comparator<SocketAddress> ComparesSocketAddress-es according to their host case insensitive and if equals, then according to their port value (if any)static final Stringprivate final Stringstatic final Stringstatic final Stringstatic final Stringstatic final intMax.static final intMax.static final Stringstatic final Stringstatic final SshdSocketAddressA dummy placeholder that can be used instead ofnullsstatic final Stringstatic final Stringprivate final intstatic final Stringstatic final Stringstatic final Stringprivate static final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic <V> VfindByOptionalWildcardAddress(Map<SshdSocketAddress, ? extends V> map, SshdSocketAddress address) static <V> Map.Entry<SshdSocketAddress, ? extends V> findMatchingOptionalWildcardEntry(Map<SshdSocketAddress, ? extends V> map, SshdSocketAddress address) static List<InetAddress> static InetAddressReturns the first external network address assigned to this machine or null if one is not found.intgetPort()inthashCode()static booleanprotected booleanstatic booleanisEquivalentHostName(String h1, String h2, boolean allowWildcard) static booleanisIPv4Address(String addr) static booleanstatic booleanisIPv6Address(String address) static booleanstatic booleanisLoopback(String ip) static booleanisLoopback(InetAddress addr) static booleanisLoopbackAlias(String h1, String h2) static booleanisPrivateIPv4Address(String addr) Checks if the address is one of the allocated private blocksstatic booleanstatic booleanChecks if the provided argument is a valid IPv4 address component:static booleanisWildcardAddress(String addr) static <V> VremoveByOptionalWildcardAddress(Map<SshdSocketAddress, ? extends V> map, SshdSocketAddress address) static inttoAddressPort(SocketAddress addr) Attempts to resolve the port valuestatic StringtoAddressString(InetAddress addr) static StringtoAddressString(SocketAddress addr) static InetSocketAddresstoInetSocketAddress(SocketAddress remoteAddress) Converts aSocketAddressinto anInetSocketAddressif possible:static SshdSocketAddresstoString()
-
Field Details
-
LOCALHOST_NAME
- See Also:
-
LOCALHOST_IPV4
- See Also:
-
IPV4_ANYADDR
- See Also:
-
WELL_KNOWN_IPV4_ADDRESSES
-
PRIVATE_CLASS_A_PREFIX
- See Also:
-
PRIVATE_CLASS_B_PREFIX
- See Also:
-
PRIVATE_CLASS_C_PREFIX
- See Also:
-
CARRIER_GRADE_NAT_PREFIX
- See Also:
-
BROADCAST_ADDRESS
- See Also:
-
IPV6_MAX_HEX_GROUPS
public static final int IPV6_MAX_HEX_GROUPSMax. number of hex groups (separated by ":") in an IPV6 address- See Also:
-
IPV6_MAX_HEX_DIGITS_PER_GROUP
public static final int IPV6_MAX_HEX_DIGITS_PER_GROUPMax. hex digits in each IPv6 group- See Also:
-
IPV6_LONG_ANY_ADDRESS
- See Also:
-
IPV6_SHORT_ANY_ADDRESS
- See Also:
-
IPV6_LONG_LOCALHOST
- See Also:
-
IPV6_SHORT_LOCALHOST
- See Also:
-
WELL_KNOWN_IPV6_ADDRESSES
-
LOCALHOST_ADDRESS
A dummy placeholder that can be used instead ofnulls -
BY_HOST_ADDRESS
ComparesInetAddress-es according to theirInetAddress.getHostAddress()value case insensitive- See Also:
-
BY_HOST_AND_PORT
ComparesSocketAddress-es according to their host case insensitive and if equals, then according to their port value (if any)- See Also:
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
hostName
-
port
private final int port
-
-
Constructor Details
-
SshdSocketAddress
public SshdSocketAddress(int port) -
SshdSocketAddress
-
SshdSocketAddress
-
-
Method Details
-
getHostName
-
getPort
public int getPort() -
toInetSocketAddress
-
toString
-
isEquivalent
-
equals
-
hashCode
public int hashCode() -
getFirstExternalNetwork4Address
Returns the first external network address assigned to this machine or null if one is not found.- Returns:
- Inet4Address associated with an external interface DevNote: We actually return InetAddress here, as Inet4Addresses are final and cannot be mocked.
-
getExternalNetwork4Addresses
- Returns:
- a
Listof local network addresses which are not multicast or localhost sorted according toBY_HOST_ADDRESS
-
isValidHostAddress
- Parameters:
addr- TheInetAddressto be verified- Returns:
trueif the address is:- Not
null - An
Inet4Address - Not link local
- Not a multicast
- Not a loopback
- Not
- See Also:
-
isLoopback
- Parameters:
addr- TheInetAddressto be considered- Returns:
trueif the address is a loopback one. Note: ifInetAddress.isLoopbackAddress()returnsfalsethe address string is checked- See Also:
-
isLoopback
- Parameters:
ip- IP value to be tested- Returns:
trueif the IP is "localhost" or "127.x.x.x".
-
isIPv4LoopbackAddress
-
isIPv6LoopbackAddress
-
isEquivalentHostName
-
isLoopbackAlias
-
isWildcardAddress
-
toSshdSocketAddress
-
toAddressString
-
toAddressPort
Attempts to resolve the port value- Parameters:
addr- TheSocketAddressto examine- Returns:
- The associated port value - negative if failed to resolve
-
toInetSocketAddress
Converts a
SocketAddressinto anInetSocketAddressif possible:- If already an
InetSocketAddressthen cast it as such - If an
SshdSocketAddressthen invoketoInetSocketAddress() - Otherwise, throw an exception
- Parameters:
remoteAddress- TheSocketAddress- ignored ifnull- Returns:
- The
InetSocketAddressinstance - Throws:
ClassCastException- if argument is not already anInetSocketAddressor aSshdSocketAddress
- If already an
-
toAddressString
-
isIPv4Address
-
isPrivateIPv4Address
Checks if the address is one of the allocated private blocks- Parameters:
addr- The address string- Returns:
trueif this is one of the allocated private blocks. Note: it assumes that the address string is indeed an IPv4 address- See Also:
-
isCarrierGradeNatIPv4Address
- Parameters:
addr- The address to be checked- Returns:
trueif the address is in the 100.64.0.0/10 range- See Also:
-
isValidIPv4AddressComponent
Checks if the provided argument is a valid IPv4 address component:
- Not
null/empty - Has at most 3 digits
- Its value is ≤ 255
- Parameters:
c- TheCharSequenceto be validate- Returns:
trueif valid IPv4 address component
- Not
-
isIPv6Address
-
findByOptionalWildcardAddress
public static <V> V findByOptionalWildcardAddress(Map<SshdSocketAddress, ? extends V> map, SshdSocketAddress address) -
removeByOptionalWildcardAddress
public static <V> V removeByOptionalWildcardAddress(Map<SshdSocketAddress, ? extends V> map, SshdSocketAddress address) -
findMatchingOptionalWildcardEntry
public static <V> Map.Entry<SshdSocketAddress,? extends V> findMatchingOptionalWildcardEntry(Map<SshdSocketAddress, ? extends V> map, SshdSocketAddress address)
-