public class SshdSocketAddress extends SocketAddress
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 the toInetSocketAddress()
call which executes this query
If empty host name is provided we replace it with the any address of 0.0.0.0
Constructor and Description |
---|
SshdSocketAddress(InetSocketAddress addr) |
SshdSocketAddress(int port) |
SshdSocketAddress(String hostName,
int port) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
static List<InetAddress> |
getExternalNetwork4Addresses() |
static InetAddress |
getFirstExternalNetwork4Address()
Returns the first external network address assigned to this
machine or null if one is not found.
|
String |
getHostName() |
int |
getPort() |
int |
hashCode() |
static boolean |
isCarrierGradeNatIPv4Address(String addr) |
protected boolean |
isEquivalent(SshdSocketAddress that) |
static boolean |
isIPv4Address(String addr) |
static boolean |
isIPv6Address(String address) |
static boolean |
isLoopback(InetAddress addr) |
static boolean |
isLoopback(String ip) |
static boolean |
isPrivateIPv4Address(String addr)
Checks if the address is one of the allocated private blocks
|
static boolean |
isValidHostAddress(InetAddress addr) |
static boolean |
isValidIPv4AddressComponent(CharSequence c)
Checks if the provided argument is a valid IPv4 address component:
|
static int |
toAddressPort(SocketAddress addr)
Attempts to resolve the port value
|
static String |
toAddressString(InetAddress addr) |
static String |
toAddressString(SocketAddress addr) |
InetSocketAddress |
toInetSocketAddress() |
static InetSocketAddress |
toInetSocketAddress(SocketAddress remoteAddress)
Converts a
SocketAddress into an InetSocketAddress if possible: |
static SshdSocketAddress |
toSshdSocketAddress(SocketAddress addr) |
String |
toString() |
public static final String LOCALHOST_NAME
public static final String LOCALHOST_IPV4
public static final String IPV4_ANYADDR
public static final String PRIVATE_CLASS_A_PREFIX
public static final String PRIVATE_CLASS_B_PREFIX
public static final String PRIVATE_CLASS_C_PREFIX
public static final String CARRIER_GRADE_NAT_PREFIX
public static final String BROADCAST_ADDRESS
public static final int IPV6_MAX_HEX_GROUPS
public static final int IPV6_MAX_HEX_DIGITS_PER_GROUP
public static final String IPV6_LONG_ANY_ADDRESS
public static final String IPV6_SHORT_ANY_ADDRESS
public static final String IPV6_LONG_LOCALHOST
public static final String IPV6_SHORT_LOCALHOST
public static final SshdSocketAddress LOCALHOST_ADDRESS
null
spublic static final Comparator<InetAddress> BY_HOST_ADDRESS
InetAddress
-es according to their InetAddress.getHostAddress()
value case insensitivetoAddressString(InetAddress)
public static final Comparator<SocketAddress> BY_HOST_AND_PORT
SocketAddress
-es according to their host case insensitive
and if equals, then according to their port value (if any)public SshdSocketAddress(int port)
public SshdSocketAddress(InetSocketAddress addr)
public SshdSocketAddress(String hostName, int port)
public String getHostName()
public int getPort()
public InetSocketAddress toInetSocketAddress()
protected boolean isEquivalent(SshdSocketAddress that)
public static InetAddress getFirstExternalNetwork4Address()
public static List<InetAddress> getExternalNetwork4Addresses()
List
of local network addresses which are not multicast
or localhost sorted according to BY_HOST_ADDRESS
public static boolean isValidHostAddress(InetAddress addr)
addr
- The InetAddress
to be verifiedtrue
if the address is:
null
Inet4Address
InetAddress.isLinkLocalAddress()
,
InetAddress.isMulticastAddress()
,
InetAddress.isMulticastAddress()
public static boolean isLoopback(InetAddress addr)
addr
- The InetAddress
to be consideredtrue
if the address is a loopback one.
Note: if InetAddress.isLoopbackAddress()
returns false
the address string is checkedtoAddressString(InetAddress)
,
isLoopback(String)
public static boolean isLoopback(String ip)
ip
- IP value to be testedtrue
if the IP is "localhost" or
"127.x.x.x".public static SshdSocketAddress toSshdSocketAddress(SocketAddress addr)
public static String toAddressString(SocketAddress addr)
public static int toAddressPort(SocketAddress addr)
addr
- The SocketAddress
to examinepublic static InetSocketAddress toInetSocketAddress(SocketAddress remoteAddress)
Converts a SocketAddress
into an InetSocketAddress
if possible:
InetSocketAddress
then cast it as suchSshdSocketAddress
then invoke toInetSocketAddress()
remoteAddress
- The SocketAddress
- ignored if null
InetSocketAddress
instanceClassCastException
- if argument is not already an InetSocketAddress
or a SshdSocketAddress
public static String toAddressString(InetAddress addr)
public static boolean isIPv4Address(String addr)
public static boolean isPrivateIPv4Address(String addr)
addr
- The address stringtrue
if this is one of the allocated private
blocks. Note: it assumes that the address string is
indeed an IPv4 addressisIPv4Address(String)
,
PRIVATE_CLASS_A_PREFIX
,
PRIVATE_CLASS_B_PREFIX
,
PRIVATE_CLASS_C_PREFIX
,
Wiki pagepublic static boolean isCarrierGradeNatIPv4Address(String addr)
addr
- The address to be checkedtrue
if the address is in the 100.64.0.0/10 rangepublic static boolean isValidIPv4AddressComponent(CharSequence c)
Checks if the provided argument is a valid IPv4 address component:
null
/emptyc
- The CharSequence
to be validatetrue
if valid IPv4 address componentpublic static boolean isIPv6Address(String address)
Copyright © 2008–2022 The Apache Software Foundation. All rights reserved.