Class AFVSOCKSocketAddress
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 AFSocketAddress
AFSocketAddress.AFSocketAddressConstructor<T>Modifier and TypeClassDescriptionprotected static interfaceA reference to the constructor of an AFSocketAddress subclass. -
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 AFSocketAddress
canMap, canMap, getAddressFamily, getBytes, getInetAddress, getInetAddress, getInetAddress, getSocketAddress, isSupportedAddress, isUseDeserializationForInit, mapOrFail, mapOrFail, newBoundServerSocket, newConnectedSocket, newDeserializedAFSocketAddress, newForceBoundServerSocket, parseUnsignedInt, resolveAddress, toSocatAddressString, unwrap, unwrap, wrapAddress, writeNativeAddressToModifier and TypeMethodDescriptionstatic booleancanMap(SocketAddress addr) Checks if the givenSocketAddresscan be mapped to anAFSocketAddress.static booleancanMap(SocketAddress addr, Class<? extends AFSocketAddress> targetAddressClass) Checks if the givenSocketAddresscan be mapped to a specificAFSocketAddresssubclass.final AFAddressFamily<?> Returns the correspondingAFAddressFamily.protected final byte[]getBytes()Returns the (non-native) byte-level representation of this address.protected final InetAddressWraps this address as anInetAddress.protected static final InetAddressgetInetAddress(FileDescriptor fdesc, boolean peerName, AFAddressFamily<?> af) Wraps the socket name/peer name of a file descriptor as anInetAddress.protected final InetAddressgetInetAddress(AFAddressFamily<?> af) Wraps an address as anInetAddress.protected static final <A extends AFSocketAddress>
@Nullable AgetSocketAddress(FileDescriptor fdesc, boolean requestPeerName, int port, AFAddressFamily<A> af) Gets the socket name/peer name of a file descriptor as anAFSocketAddress.protected static final booleanisSupportedAddress(InetAddress addr, AFAddressFamily<?> af) Checks if the given address is supported by this address family.protected static booleanChecks ifAFSocketAddressinstantiation should be performed via deserialization.static AFSocketAddressmapOrFail(SocketAddress addr) Maps the given address to anAFSocketAddress.static <A extends AFSocketAddress>
AmapOrFail(SocketAddress addr, Class<A> targetAddressClass) Maps the given address to a specificAFSocketAddresstype.Creates a new server socket bound to this address.AFSocket<?> Creates a new socket connected to this address.protected static <A extends AFSocketAddress>
AnewDeserializedAFSocketAddress(int port, byte[] socketAddress, ObjectPool.Lease<ByteBuffer> nativeAddress, AFAddressFamily<A> af, AFSocketAddress.AFSocketAddressConstructor<A> constructor) Returns a newAFSocketAddressinstance via deserialization.Creates a new server socket force-bound to this address (i.e., any additional call toServerSocket.bind(SocketAddress)will ignore the passed address and use this one instead.protected static intparseUnsignedInt(String s, int radix) Parses the string argument as an unsigned integer in the radix specified by the second argument.protected static final <A extends AFSocketAddress>
AresolveAddress(byte[] socketAddress, int port, AFAddressFamily<A> af) Resolves a junixsocket-specific byte-array representation of anAFSocketAddressto an actualAFSocketAddressinstance, possibly reusing a cached instance.@Nullable StringtoSocatAddressString(AFSocketType socketType, AFSocketProtocol socketProtocol) Returns a address string that can be used withsocat'sSOCKET-CONNECT,SOCKET-LISTEN,SOCKET-DATAGRAM, etc., address types, ornullif the address type is not natively supported by this platform.protected static final <A extends AFSocketAddress>
@NonNull Aunwrap(String hostname, int port, AFAddressFamily<A> af) Returns anAFSocketAddressgiven a specialInetAddresshostname that encodes the byte sequence of an AF_UNIX etc. socket address, like those returned byAFSocketAddress.wrapAddress().protected static final <A extends AFSocketAddress>
@NonNull Aunwrap(InetAddress address, int port, AFAddressFamily<A> af) Returns anAFSocketAddressgiven a specialInetAddressthat encodes the byte sequence of an AF_UNIX etc. socket address, like those returned byAFSocketAddress.wrapAddress().final InetAddressReturns a "special"InetAddressthat contains information about thisAFSocketAddress.final voidWrites the native (system-level) representation of this address to the given buffer.Methods inherited from class 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.
-