java.lang.Object
java.net.SocketAddress
java.net.InetSocketAddress
org.newsclub.net.unix.AFSocketAddress
org.newsclub.net.unix.AFVSOCKSocketAddress
- All Implemented Interfaces:
Serializable
An
AFSocketAddress for VSOCK sockets.- Author:
- Christian Kohlschütter
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.newsclub.net.unix.AFSocketAddress
AFSocketAddress.AFSocketAddressConstructor<T extends AFSocketAddress> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int"Any address for binding".static final intThe well-known address of the host.static final intReserved for services built into the hypervisor.static final intThe well-known address for local communication (loopback).static final intAny port number for binding. -
Method Summary
Modifier and TypeMethodDescriptionstatic AFAddressFamily<AFVSOCKSocketAddress> Returns the correspondingAFAddressFamily.booleancovers(AFSocketAddress covered) Checks if the given address could cover another address.getFile()Returns theFilecorresponding with this address, if possible.intReturns the "VSOCK CID" part of this address.intReturns the "VSOCK port" part of this address.intReturns the "VSOCK reserved1" part of this address.booleanChecks if the address can be resolved to aFile.static booleanChecks if anInetAddresscan be unwrapped to anAFVSOCKSocketAddress.static booleanChecks if aSocketAddresscan be unwrapped to anAFVSOCKSocketAddress.static AFVSOCKSocketAddressReturns anAFVSOCKSocketAddressfor the given URI, if possible.static AFVSOCKSocketAddressReturns anAFVSOCKSocketAddressfor the given URI, if possible.static AFVSOCKSocketAddressReturns anAFVSOCKSocketAddress, especially useful for binding, that refers to "any" port on the host; the "java port" is set to -1.static AFVSOCKSocketAddressReturns anAFVSOCKSocketAddress, especially useful for binding, that refers to "any" port on the hypervisor; the "java port" is set to -1.static AFVSOCKSocketAddressReturns anAFVSOCKSocketAddress, especially useful for binding, that refers to "any" port with the local/loopback CID; the "java port" is set to -1.static AFVSOCKSocketAddressReturns anAFVSOCKSocketAddress, especially useful for binding, that refers to "any" port and CID; the "java port" is set to -1.static AFVSOCKSocketAddressofHostPort(int port) Returns anAFVSOCKSocketAddressthat refers to a given VSOCK port on the host; the "java port" is set to -1.static AFVSOCKSocketAddressofHypervisorPort(int port) Returns anAFVSOCKSocketAddressthat refers to a given VSOCK port on the hypervisor; the "java port" is set to -1.static AFVSOCKSocketAddressofLocalPort(int port) Returns anAFVSOCKSocketAddressthat refers to the given port with the local/loopback CID; the "java port" is set to -1.static AFVSOCKSocketAddressofPortAndCID(int port, int cid) Returns anAFVSOCKSocketAddressthat refers to a given VSOCK port and CID; the "java port" is set to -1.static AFVSOCKSocketAddressofPortAndCID(int javaPort, int vsockPort, int cid) Returns anAFVSOCKSocketAddressthat refers to a given port and CID.static AFVSOCKSocketAddressofPortWithAnyCID(int port) Returns anAFVSOCKSocketAddress, especially useful for binding, that refers to the given port with "any CID"; the "java port" is set to -1.toString()Tries to create a URI based on thisAFSocketAddress.static AFVSOCKSocketAddressReturns anAFVSOCKSocketAddressgiven a specialInetAddresshostname that encodes the byte sequence of an AF_VSOCK socket address, like those returned byAFSocketAddress.wrapAddress().static AFVSOCKSocketAddressunwrap(InetAddress address, int port) Returns anAFVSOCKSocketAddressgiven a specialInetAddressthat encodes the byte sequence of an AF_VSOCK socket address, like those returned byAFSocketAddress.wrapAddress().static AFVSOCKSocketAddressunwrap(SocketAddress address) Returns anAFVSOCKSocketAddressgiven a genericSocketAddress.Methods inherited from class org.newsclub.net.unix.AFSocketAddress
canMap, canMap, getAddressFamily, getBytes, getInetAddress, getInetAddress, getInetAddress, getSocketAddress, isSupportedAddress, isUseDeserializationForInit, mapOrFail, mapOrFail, newBoundServerSocket, newConnectedSocket, newDeserializedAFSocketAddress, newForceBoundServerSocket, parseUnsignedInt, resolveAddress, toSocatAddressString, unwrap, unwrap, wrapAddress, writeNativeAddressToMethods inherited from class java.net.InetSocketAddress
createUnresolved, equals, getAddress, getHostName, getHostString, getPort, hashCode, isUnresolved
-
Field Details
-
VMADDR_CID_ANY
public static final int VMADDR_CID_ANY"Any address for binding".- See Also:
-
VMADDR_CID_HYPERVISOR
public static final int VMADDR_CID_HYPERVISORReserved for services built into the hypervisor.- See Also:
-
VMADDR_CID_LOCAL
public static final int VMADDR_CID_LOCALThe well-known address for local communication (loopback).- See Also:
-
VMADDR_CID_HOST
public static final int VMADDR_CID_HOSTThe well-known address of the host.- See Also:
-
VMADDR_PORT_ANY
public static final int VMADDR_PORT_ANYAny port number for binding.- See Also:
-
-
Method Details
-
ofPortAndCID
Returns anAFVSOCKSocketAddressthat refers to a given VSOCK port and CID; the "java port" is set to -1.- Parameters:
port- The VSOCK portcid- The CID.- Returns:
- A corresponding
AFVSOCKSocketAddressinstance. - Throws:
SocketException- if the operation fails.
-
ofHypervisorPort
Returns anAFVSOCKSocketAddressthat refers to a given VSOCK port on the hypervisor; the "java port" is set to -1.- Parameters:
port- The VSOCK port- Returns:
- A corresponding
AFVSOCKSocketAddressinstance. - Throws:
SocketException- if the operation fails.
-
ofAnyHypervisorPort
Returns anAFVSOCKSocketAddress, especially useful for binding, that refers to "any" port on the hypervisor; the "java port" is set to -1.- Returns:
- A corresponding
AFVSOCKSocketAddressinstance. - Throws:
SocketException- if the operation fails.
-
ofLocalPort
Returns anAFVSOCKSocketAddressthat refers to the given port with the local/loopback CID; the "java port" is set to -1.- Parameters:
port- The VSOCK port.- Returns:
- A corresponding
AFVSOCKSocketAddressinstance. - Throws:
SocketException- if the operation fails.
-
ofAnyLocalPort
Returns anAFVSOCKSocketAddress, especially useful for binding, that refers to "any" port with the local/loopback CID; the "java port" is set to -1.- Returns:
- A corresponding
AFVSOCKSocketAddressinstance. - Throws:
SocketException- if the operation fails.
-
ofHostPort
Returns anAFVSOCKSocketAddressthat refers to a given VSOCK port on the host; the "java port" is set to -1.- Parameters:
port- The VSOCK port- Returns:
- A corresponding
AFVSOCKSocketAddressinstance. - Throws:
SocketException- if the operation fails.
-
ofAnyHostPort
Returns anAFVSOCKSocketAddress, especially useful for binding, that refers to "any" port on the host; the "java port" is set to -1.- Returns:
- A corresponding
AFVSOCKSocketAddressinstance. - Throws:
SocketException- if the operation fails.
-
ofAnyPort
Returns anAFVSOCKSocketAddress, especially useful for binding, that refers to "any" port and CID; the "java port" is set to -1.- Returns:
- A corresponding
AFVSOCKSocketAddressinstance. - Throws:
SocketException- if the operation fails.
-
ofPortWithAnyCID
Returns anAFVSOCKSocketAddress, especially useful for binding, that refers to the given port with "any CID"; the "java port" is set to -1.- Parameters:
port- The VSOCK port.- Returns:
- A corresponding
AFVSOCKSocketAddressinstance. - Throws:
SocketException- if the operation fails.
-
ofPortAndCID
public static AFVSOCKSocketAddress ofPortAndCID(int javaPort, int vsockPort, int cid) throws SocketException Returns anAFVSOCKSocketAddressthat refers to a given port and CID.- Parameters:
javaPort- The Java port number.vsockPort- The vsock port.cid- The CID.- Returns:
- A corresponding
AFVSOCKSocketAddressinstance. - Throws:
SocketException- if the operation fails.
-
unwrap
Returns anAFVSOCKSocketAddressgiven a specialInetAddressthat encodes the byte sequence of an AF_VSOCK socket address, like those returned byAFSocketAddress.wrapAddress().- Parameters:
address- The "special"InetAddress.port- The port (use 0 for "none").- Returns:
- The
AFVSOCKSocketAddressinstance. - Throws:
SocketException- if the operation fails, for example when an unsupported address is specified.
-
unwrap
Returns anAFVSOCKSocketAddressgiven a specialInetAddresshostname that encodes the byte sequence of an AF_VSOCK socket address, like those returned byAFSocketAddress.wrapAddress().- Parameters:
hostname- The "special" hostname, as provided byInetAddress.getHostName().port- The port (use 0 for "none").- Returns:
- The
AFVSOCKSocketAddressinstance. - Throws:
SocketException- if the operation fails, for example when an unsupported address is specified.
-
unwrap
Returns anAFVSOCKSocketAddressgiven a genericSocketAddress.- Parameters:
address- The address to unwrap.- Returns:
- The
AFVSOCKSocketAddressinstance. - Throws:
SocketException- if the operation fails, for example when an unsupported address is specified.
-
getVSOCKPort
public int getVSOCKPort()Returns the "VSOCK port" part of this address.- Returns:
- The VSOCK port identifier
- See Also:
-
getVSOCKCID
public int getVSOCKCID()Returns the "VSOCK CID" part of this address.- Returns:
- The VSOCK CID identifier.
-
getVSOCKReserved1
public int getVSOCKReserved1()Returns the "VSOCK reserved1" part of this address.- Returns:
- The "reserved1" identifier, which should be 0.
-
toString
- Overrides:
toStringin classInetSocketAddress
-
hasFilename
public boolean hasFilename()Description copied from class:AFSocketAddressChecks if the address can be resolved to aFile.- Specified by:
hasFilenamein classAFSocketAddress- Returns:
trueif the address has a filename.
-
getFile
Description copied from class:AFSocketAddressReturns theFilecorresponding with this address, if possible. AFileNotFoundExceptionis thrown if there is no filename associated with the address, which applies to addresses in the abstract namespace, for example.- Specified by:
getFilein classAFSocketAddress- Returns:
- The filename.
- Throws:
FileNotFoundException- if the address is not associated with a filename.
-
isSupportedAddress
Checks if anInetAddresscan be unwrapped to anAFVSOCKSocketAddress.- Parameters:
addr- The instance to check.- Returns:
trueif so.- See Also:
-
isSupportedAddress
Checks if aSocketAddresscan be unwrapped to anAFVSOCKSocketAddress.- Parameters:
addr- The instance to check.- Returns:
trueif so.- See Also:
-
addressFamily
Returns the correspondingAFAddressFamily.- Returns:
- The address family instance.
-
of
Returns anAFVSOCKSocketAddressfor the given URI, if possible.- Parameters:
uri- The URI.- Returns:
- The address.
- Throws:
SocketException- if the operation fails.
-
of
Returns anAFVSOCKSocketAddressfor the given URI, if possible.- Parameters:
uri- The URI.overridePort- The port to forcibly use, or-1for "don't override".- Returns:
- The address.
- Throws:
SocketException- if the operation fails.
-
toURI
Description copied from class:AFSocketAddressTries to create a URI based on thisAFSocketAddress.- Overrides:
toURIin classAFSocketAddress- Parameters:
scheme- The target scheme.template- An optional template to reuse certain parameters (e.g., the "path" component for anhttprequest), ornull.- Returns:
- The URI.
- Throws:
IOException- on error.
-
covers
Checks if the given address could cover another address. By default, this is only true if both addresses are regarded equal usingInetSocketAddress.equals(Object). However, implementations may support "wildcard" addresses, and this method would compare a wildcard address against some non-wildcard address, for example.- Overrides:
coversin classAFSocketAddress- Parameters:
covered- The other address that could be covered by this address.- Returns:
trueif the other address could be covered.
-