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
| Modifier and Type | Field and Description |
|---|---|
static String |
BROADCAST_ADDRESS |
static Comparator<InetAddress> |
BY_HOST_ADDRESS
Compares
InetAddress-es according to their InetAddress.getHostAddress()
value case insensitive |
static Comparator<SocketAddress> |
BY_HOST_AND_PORT
Compares
SocketAddress-es according to their host case insensitive
and if equals, then according to their port value (if any) |
static String |
CARRIER_GRADE_NAT_PREFIX |
static String |
IP_ANYADDR |
static SshdSocketAddress |
LOCALHOST_ADDRESS
A dummy placeholder that can be used instead of
nulls |
static String |
LOCALHOST_IP |
static String |
LOCALHOST_NAME |
static String |
PRIVATE_CLASS_A_PREFIX |
static String |
PRIVATE_CLASS_B_PREFIX |
static String |
PRIVATE_CLASS_C_PREFIX |
| Constructor and Description |
|---|
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 |
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:
Not
null/empty
Has at most 3 digits
Its value is ≤ 255
|
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:
If already an InetSocketAddress then cast it as such
If an SshdSocketAddress then invoke toInetSocketAddress()
Otherwise, throw an exception
|
static SshdSocketAddress |
toSshdSocketAddress(SocketAddress addr) |
String |
toString() |
public static final String LOCALHOST_NAME
public static final String LOCALHOST_IP
public static final String IP_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 SshdSocketAddress LOCALHOST_ADDRESS
nullspublic 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(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_ADDRESSpublic static boolean isValidHostAddress(InetAddress addr)
addr - The InetAddress to be verifiedtrue if the address is:
nullInet4AddressInetAddress.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 nullInetSocketAddress instanceClassCastException - if argument is not already an InetSocketAddress
or a SshdSocketAddresspublic 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 componentCopyright © 2008–2017 The Apache Software Foundation. All rights reserved.