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
public class SshdSocketAddress extends SocketAddress
A simple socket address holding the host name and port number. The reason it does not extend
InetSocketAddressis 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
- Author:
- Apache MINA SSHD Project
- See Also:
- Serialized Form
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description SshdSocketAddress(int port)SshdSocketAddress(String hostName, int port)SshdSocketAddress(InetSocketAddress addr)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)static <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>getExternalNetwork4Addresses()static InetAddressgetFirstExternalNetwork4Address()Returns the first external network address assigned to this machine or null if one is not found.StringgetHostName()intgetPort()inthashCode()static booleanisCarrierGradeNatIPv4Address(String addr)protected booleanisEquivalent(SshdSocketAddress that)static booleanisEquivalentHostName(String h1, String h2, boolean allowWildcard)static booleanisIPv4Address(String addr)static booleanisIPv4LoopbackAddress(String ip)static booleanisIPv6Address(String address)static booleanisIPv6LoopbackAddress(String ip)static 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 booleanisValidHostAddress(InetAddress addr)static booleanisValidIPv4AddressComponent(CharSequence c)Checks 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)InetSocketAddresstoInetSocketAddress()static InetSocketAddresstoInetSocketAddress(SocketAddress remoteAddress)Converts aSocketAddressinto anInetSocketAddressif possible:static SshdSocketAddresstoSshdSocketAddress(SocketAddress addr)StringtoString()
-
-
-
Field Detail
-
LOCALHOST_NAME
public static final String LOCALHOST_NAME
- See Also:
- Constant Field Values
-
LOCALHOST_IPV4
public static final String LOCALHOST_IPV4
- See Also:
- Constant Field Values
-
IPV4_ANYADDR
public static final String IPV4_ANYADDR
- See Also:
- Constant Field Values
-
PRIVATE_CLASS_A_PREFIX
public static final String PRIVATE_CLASS_A_PREFIX
- See Also:
- Constant Field Values
-
PRIVATE_CLASS_B_PREFIX
public static final String PRIVATE_CLASS_B_PREFIX
- See Also:
- Constant Field Values
-
PRIVATE_CLASS_C_PREFIX
public static final String PRIVATE_CLASS_C_PREFIX
- See Also:
- Constant Field Values
-
CARRIER_GRADE_NAT_PREFIX
public static final String CARRIER_GRADE_NAT_PREFIX
- See Also:
- Constant Field Values
-
BROADCAST_ADDRESS
public static final String BROADCAST_ADDRESS
- See Also:
- Constant Field Values
-
IPV6_MAX_HEX_GROUPS
public static final int IPV6_MAX_HEX_GROUPS
Max. number of hex groups (separated by ":") in an IPV6 address- See Also:
- Constant Field Values
-
IPV6_MAX_HEX_DIGITS_PER_GROUP
public static final int IPV6_MAX_HEX_DIGITS_PER_GROUP
Max. hex digits in each IPv6 group- See Also:
- Constant Field Values
-
IPV6_LONG_ANY_ADDRESS
public static final String IPV6_LONG_ANY_ADDRESS
- See Also:
- Constant Field Values
-
IPV6_SHORT_ANY_ADDRESS
public static final String IPV6_SHORT_ANY_ADDRESS
- See Also:
- Constant Field Values
-
IPV6_LONG_LOCALHOST
public static final String IPV6_LONG_LOCALHOST
- See Also:
- Constant Field Values
-
IPV6_SHORT_LOCALHOST
public static final String IPV6_SHORT_LOCALHOST
- See Also:
- Constant Field Values
-
LOCALHOST_ADDRESS
public static final SshdSocketAddress LOCALHOST_ADDRESS
A dummy placeholder that can be used instead ofnulls
-
BY_HOST_ADDRESS
public static final Comparator<InetAddress> BY_HOST_ADDRESS
ComparesInetAddress-es according to theirInetAddress.getHostAddress()value case insensitive- See Also:
toAddressString(InetAddress)
-
BY_HOST_AND_PORT
public static final Comparator<SocketAddress> BY_HOST_AND_PORT
ComparesSocketAddress-es according to their host case insensitive and if equals, then according to their port value (if any)
-
-
Constructor Detail
-
SshdSocketAddress
public SshdSocketAddress(int port)
-
SshdSocketAddress
public SshdSocketAddress(InetSocketAddress addr)
-
SshdSocketAddress
public SshdSocketAddress(String hostName, int port)
-
-
Method Detail
-
getHostName
public String getHostName()
-
getPort
public int getPort()
-
toInetSocketAddress
public InetSocketAddress toInetSocketAddress()
-
isEquivalent
protected boolean isEquivalent(SshdSocketAddress that)
-
getFirstExternalNetwork4Address
public static InetAddress 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
public static List<InetAddress> getExternalNetwork4Addresses()
- Returns:
- a
Listof local network addresses which are not multicast or localhost sorted according toBY_HOST_ADDRESS
-
isValidHostAddress
public static boolean isValidHostAddress(InetAddress addr)
- 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:
InetAddress.isLinkLocalAddress(),InetAddress.isMulticastAddress(),InetAddress.isMulticastAddress()
-
isLoopback
public static boolean isLoopback(InetAddress addr)
- Parameters:
addr- TheInetAddressto be considered- Returns:
trueif the address is a loopback one. Note: ifInetAddress.isLoopbackAddress()returnsfalsethe address string is checked- See Also:
toAddressString(InetAddress),isLoopback(String)
-
isLoopback
public static boolean isLoopback(String ip)
- Parameters:
ip- IP value to be tested- Returns:
trueif the IP is "localhost" or "127.x.x.x".
-
isIPv4LoopbackAddress
public static boolean isIPv4LoopbackAddress(String ip)
-
isIPv6LoopbackAddress
public static boolean isIPv6LoopbackAddress(String ip)
-
isEquivalentHostName
public static boolean isEquivalentHostName(String h1, String h2, boolean allowWildcard)
-
isWildcardAddress
public static boolean isWildcardAddress(String addr)
-
toSshdSocketAddress
public static SshdSocketAddress toSshdSocketAddress(SocketAddress addr)
-
toAddressString
public static String toAddressString(SocketAddress addr)
-
toAddressPort
public static int toAddressPort(SocketAddress addr)
Attempts to resolve the port value- Parameters:
addr- TheSocketAddressto examine- Returns:
- The associated port value - negative if failed to resolve
-
toInetSocketAddress
public static InetSocketAddress toInetSocketAddress(SocketAddress remoteAddress)
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
public static String toAddressString(InetAddress addr)
-
isIPv4Address
public static boolean isIPv4Address(String addr)
-
isPrivateIPv4Address
public static boolean isPrivateIPv4Address(String addr)
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:
isIPv4Address(String),PRIVATE_CLASS_A_PREFIX,PRIVATE_CLASS_B_PREFIX,PRIVATE_CLASS_C_PREFIX, Wiki page
-
isCarrierGradeNatIPv4Address
public static boolean isCarrierGradeNatIPv4Address(String addr)
- Parameters:
addr- The address to be checked- Returns:
trueif the address is in the 100.64.0.0/10 range- See Also:
- RFC6598
-
isValidIPv4AddressComponent
public static boolean isValidIPv4AddressComponent(CharSequence c)
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
public static boolean isIPv6Address(String address)
-
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)
-
-