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
Modifier and TypeFieldDescriptionstatic final int
"Any address for binding".static final int
The well-known address of the host.static final int
Reserved for services built into the hypervisor.static final int
The well-known address for local communication (loopback).static final int
Any port number for binding. -
Method Summary
Modifier and TypeMethodDescriptionstatic AFAddressFamily
<AFVSOCKSocketAddress> Returns the correspondingAFAddressFamily
.boolean
covers
(AFSocketAddress covered) Checks if the given address could cover another address.getFile()
Returns theFile
corresponding with this address, if possible.int
Returns the "VSOCK CID" part of this address.int
Returns the "VSOCK port" part of this address.int
Returns the "VSOCK reserved1" part of this address.boolean
Checks if the address can be resolved to aFile
.static boolean
Checks if anInetAddress
can be unwrapped to anAFVSOCKSocketAddress
.static boolean
Checks if aSocketAddress
can be unwrapped to anAFVSOCKSocketAddress
.static AFVSOCKSocketAddress
Returns anAFVSOCKSocketAddress
for the given URI, if possible.static AFVSOCKSocketAddress
Returns anAFVSOCKSocketAddress
for the given URI, if possible.static AFVSOCKSocketAddress
Returns anAFVSOCKSocketAddress
, especially useful for binding, that refers to "any" port on the host; the "java port" is set to -1.static AFVSOCKSocketAddress
Returns anAFVSOCKSocketAddress
, especially useful for binding, that refers to "any" port on the hypervisor; the "java port" is set to -1.static AFVSOCKSocketAddress
Returns anAFVSOCKSocketAddress
, especially useful for binding, that refers to "any" port with the local/loopback CID; the "java port" is set to -1.static AFVSOCKSocketAddress
Returns anAFVSOCKSocketAddress
, especially useful for binding, that refers to "any" port and CID; the "java port" is set to -1.static AFVSOCKSocketAddress
ofHostPort
(int port) Returns anAFVSOCKSocketAddress
that refers to a given VSOCK port on the host; the "java port" is set to -1.static AFVSOCKSocketAddress
ofHypervisorPort
(int port) Returns anAFVSOCKSocketAddress
that refers to a given VSOCK port on the hypervisor; the "java port" is set to -1.static AFVSOCKSocketAddress
ofLocalPort
(int port) Returns anAFVSOCKSocketAddress
that refers to the given port with the local/loopback CID; the "java port" is set to -1.static AFVSOCKSocketAddress
ofPortAndCID
(int port, int cid) Returns anAFVSOCKSocketAddress
that refers to a given VSOCK port and CID; the "java port" is set to -1.static AFVSOCKSocketAddress
ofPortAndCID
(int javaPort, int vsockPort, int cid) Returns anAFVSOCKSocketAddress
that refers to a given port and CID.static AFVSOCKSocketAddress
ofPortWithAnyCID
(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 AFVSOCKSocketAddress
Returns anAFVSOCKSocketAddress
given a specialInetAddress
hostname that encodes the byte sequence of an AF_VSOCK socket address, like those returned byAFSocketAddress.wrapAddress()
.static AFVSOCKSocketAddress
unwrap
(InetAddress address, int port) Returns anAFVSOCKSocketAddress
given a specialInetAddress
that encodes the byte sequence of an AF_VSOCK socket address, like those returned byAFSocketAddress.wrapAddress()
.static AFVSOCKSocketAddress
unwrap
(SocketAddress address) Returns anAFVSOCKSocketAddress
given 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, writeNativeAddressTo
Methods 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 anAFVSOCKSocketAddress
that 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
AFVSOCKSocketAddress
instance. - Throws:
SocketException
- if the operation fails.
-
ofHypervisorPort
Returns anAFVSOCKSocketAddress
that refers to a given VSOCK port on the hypervisor; the "java port" is set to -1.- Parameters:
port
- The VSOCK port- Returns:
- A corresponding
AFVSOCKSocketAddress
instance. - 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
AFVSOCKSocketAddress
instance. - Throws:
SocketException
- if the operation fails.
-
ofLocalPort
Returns anAFVSOCKSocketAddress
that 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
AFVSOCKSocketAddress
instance. - 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
AFVSOCKSocketAddress
instance. - Throws:
SocketException
- if the operation fails.
-
ofHostPort
Returns anAFVSOCKSocketAddress
that refers to a given VSOCK port on the host; the "java port" is set to -1.- Parameters:
port
- The VSOCK port- Returns:
- A corresponding
AFVSOCKSocketAddress
instance. - 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
AFVSOCKSocketAddress
instance. - 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
AFVSOCKSocketAddress
instance. - 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
AFVSOCKSocketAddress
instance. - Throws:
SocketException
- if the operation fails.
-
ofPortAndCID
public static AFVSOCKSocketAddress ofPortAndCID(int javaPort, int vsockPort, int cid) throws SocketException Returns anAFVSOCKSocketAddress
that refers to a given port and CID.- Parameters:
javaPort
- The Java port number.vsockPort
- The vsock port.cid
- The CID.- Returns:
- A corresponding
AFVSOCKSocketAddress
instance. - Throws:
SocketException
- if the operation fails.
-
unwrap
Returns anAFVSOCKSocketAddress
given a specialInetAddress
that 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
AFVSOCKSocketAddress
instance. - Throws:
SocketException
- if the operation fails, for example when an unsupported address is specified.
-
unwrap
Returns anAFVSOCKSocketAddress
given a specialInetAddress
hostname 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
AFVSOCKSocketAddress
instance. - Throws:
SocketException
- if the operation fails, for example when an unsupported address is specified.
-
unwrap
Returns anAFVSOCKSocketAddress
given a genericSocketAddress
.- Parameters:
address
- The address to unwrap.- Returns:
- The
AFVSOCKSocketAddress
instance. - 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:
toString
in classInetSocketAddress
-
hasFilename
public boolean hasFilename()Description copied from class:AFSocketAddress
Checks if the address can be resolved to aFile
.- Specified by:
hasFilename
in classAFSocketAddress
- Returns:
true
if the address has a filename.
-
getFile
Description copied from class:AFSocketAddress
Returns theFile
corresponding with this address, if possible. AFileNotFoundException
is thrown if there is no filename associated with the address, which applies to addresses in the abstract namespace, for example.- Specified by:
getFile
in classAFSocketAddress
- Returns:
- The filename.
- Throws:
FileNotFoundException
- if the address is not associated with a filename.
-
isSupportedAddress
Checks if anInetAddress
can be unwrapped to anAFVSOCKSocketAddress
.- Parameters:
addr
- The instance to check.- Returns:
true
if so.- See Also:
-
isSupportedAddress
Checks if aSocketAddress
can be unwrapped to anAFVSOCKSocketAddress
.- Parameters:
addr
- The instance to check.- Returns:
true
if so.- See Also:
-
addressFamily
Returns the correspondingAFAddressFamily
.- Returns:
- The address family instance.
-
of
Returns anAFVSOCKSocketAddress
for the given URI, if possible.- Parameters:
uri
- The URI.- Returns:
- The address.
- Throws:
SocketException
- if the operation fails.
-
of
Returns anAFVSOCKSocketAddress
for the given URI, if possible.- Parameters:
uri
- The URI.overridePort
- The port to forcibly use, or-1
for "don't override".- Returns:
- The address.
- Throws:
SocketException
- if the operation fails.
-
toURI
Description copied from class:AFSocketAddress
Tries to create a URI based on thisAFSocketAddress
.- Overrides:
toURI
in classAFSocketAddress
- Parameters:
scheme
- The target scheme.template
- An optional template to reuse certain parameters (e.g., the "path" component for anhttp
request), 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:
covers
in classAFSocketAddress
- Parameters:
covered
- The other address that could be covered by this address.- Returns:
true
if the other address could be covered.
-