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
InetSocketAddress
performs 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 String
static 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 String
private final String
static final String
static final String
static final String
static final int
Max.static final int
Max.static final String
static final String
static final SshdSocketAddress
A dummy placeholder that can be used instead ofnull
sstatic final String
static final String
private final int
static final String
static final String
static final String
private static final long
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
static <V> V
findByOptionalWildcardAddress
(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 InetAddress
Returns the first external network address assigned to this machine or null if one is not found.int
getPort()
int
hashCode()
static boolean
protected boolean
static boolean
isEquivalentHostName
(String h1, String h2, boolean allowWildcard) static boolean
isIPv4Address
(String addr) static boolean
static boolean
isIPv6Address
(String address) static boolean
static boolean
isLoopback
(String ip) static boolean
isLoopback
(InetAddress addr) static boolean
isLoopbackAlias
(String h1, String h2) static boolean
isPrivateIPv4Address
(String addr) Checks if the address is one of the allocated private blocksstatic boolean
static boolean
Checks if the provided argument is a valid IPv4 address component:static boolean
isWildcardAddress
(String addr) static <V> V
removeByOptionalWildcardAddress
(Map<SshdSocketAddress, ? extends V> map, SshdSocketAddress address) static int
toAddressPort
(SocketAddress addr) Attempts to resolve the port valuestatic String
toAddressString
(InetAddress addr) static String
toAddressString
(SocketAddress addr) static InetSocketAddress
toInetSocketAddress
(SocketAddress remoteAddress) Converts aSocketAddress
into anInetSocketAddress
if possible:static SshdSocketAddress
toString()
-
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 ofnull
s -
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) -
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
List
of local network addresses which are not multicast or localhost sorted according toBY_HOST_ADDRESS
-
isValidHostAddress
- Parameters:
addr
- TheInetAddress
to be verified- Returns:
true
if the address is:- Not
null
- An
Inet4Address
- Not link local
- Not a multicast
- Not a loopback
- Not
- See Also:
-
isLoopback
- Parameters:
addr
- TheInetAddress
to be considered- Returns:
true
if the address is a loopback one. Note: ifInetAddress.isLoopbackAddress()
returnsfalse
the address string is checked- See Also:
-
isLoopback
- Parameters:
ip
- IP value to be tested- Returns:
true
if 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
- TheSocketAddress
to examine- Returns:
- The associated port value - negative if failed to resolve
-
toInetSocketAddress
Converts a
SocketAddress
into anInetSocketAddress
if possible:- If already an
InetSocketAddress
then cast it as such - If an
SshdSocketAddress
then invoketoInetSocketAddress()
- Otherwise, throw an exception
- Parameters:
remoteAddress
- TheSocketAddress
- ignored ifnull
- Returns:
- The
InetSocketAddress
instance - Throws:
ClassCastException
- if argument is not already anInetSocketAddress
or aSshdSocketAddress
- If already an
-
toAddressString
-
isIPv4Address
-
isPrivateIPv4Address
Checks if the address is one of the allocated private blocks- Parameters:
addr
- The address string- Returns:
true
if 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:
true
if 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
- TheCharSequence
to be validate- Returns:
true
if 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)
-