Top Description Fields Constructors Methods
org.newsclub.net.unix

pack-priv Class AFInetAddress

extends Object
Class Inheritance
Imports
java.io.UnsupportedEncodingException, java.net.DatagramPacket, .Inet4Address, .InetAddress, .InetSocketAddress, .SocketAddress, .SocketException, .URLDecoder, .URLEncoder, .UnknownHostException, java.nio.charset.StandardCharsets, java.util.Locale, .Objects

A workaround to create an InetAddress for an AFSocketAddress. DatagramPacket internally requires InetAddress compatibility. Even if it pretends to accept SocketAddresses, it refuses anything other than InetSocketAddress and then even stores host and port separately. This implementation deserializes a specially crafted InetAddress with a hostname that encodes the raw bytes of an AFSocketAddress. We do this because the deserialization code path does not attempt DNS resolution (which would fail one way or another). The hostnames we use end with ".junixsocket", to distinguish them from regular hostnames.
Author
Christian Kohlschütter

Field Summary

Modifier and TypeField and Description
pack-priv static final String
private static final byte[]
private static final String
private static final char

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv static final String

Returns:

A string, to be used when calling InetSocketAddress#InetSocketAddress(String, int), etc.
createUnresolvedHostname
(byte[]
The socket address.
socketAddress
,
AFAddressFamily<?> af)

Encodes a junixsocket socketAddress into a string that is (somewhat) guaranteed to not be resolved by java.net code.

pack-priv static boolean
pack-priv static final byte[]
pack-priv static final byte[]
pack-priv static final InetAddress

Returns:

The InetAddress.
wrapAddress
(byte[]
The socket address.
socketAddress
,
AFAddressFamily<?> af)

Creates an InetAddress that is considered "resolved" internally (using a static loopback address), without actually having to resolve the address via DNS, thus still carrying the "hostname" field containing a hostname as returned by createUnresolvedHostname(byte[], AFAddressFamily).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INETADDR_SUFFIXback to summary
pack-priv static final String INETADDR_SUFFIX
LOCAL_AFback to summary
private static final byte[] LOCAL_AF
MARKER_HEX_ENCODINGback to summary
private static final String MARKER_HEX_ENCODING
PREFIXback to summary
private static final char PREFIX

Constructor Detail

AFInetAddressback to summary
pack-priv AFInetAddress()

Method Detail

createUnresolvedHostnameback to summary
pack-priv static final String createUnresolvedHostname(byte[] socketAddress, AFAddressFamily<?> af)

Encodes a junixsocket socketAddress into a string that is (somewhat) guaranteed to not be resolved by java.net code. Implementation detail: The "[" prefix (with the corresponding "]" suffix missing from the input) should cause an early UnknownHostException be thrown, which is caught within InetSocketAddress#InetSocketAddress(String, int), causing the hostname be marked as "unresolved" (without an address set).

Parameters
socketAddress:byte[]

The socket address.

Returns:String

A string, to be used when calling InetSocketAddress#InetSocketAddress(String, int), etc.

isSupportedAddressback to summary
pack-priv static boolean isSupportedAddress(InetAddress addr, AFAddressFamily<?> af)
unwrapAddressback to summary
pack-priv static final byte[] unwrapAddress(InetAddress addr, AFAddressFamily<?> af) throws SocketException
unwrapAddressback to summary
pack-priv static final byte[] unwrapAddress(String hostname, AFAddressFamily<?> af) throws SocketException
wrapAddressback to summary
pack-priv static final InetAddress wrapAddress(byte[] socketAddress, AFAddressFamily<?> af)

Creates an InetAddress that is considered "resolved" internally (using a static loopback address), without actually having to resolve the address via DNS, thus still carrying the "hostname" field containing a hostname as returned by createUnresolvedHostname(byte[], AFAddressFamily).

Parameters
socketAddress:byte[]

The socket address.

Returns:InetAddress

The InetAddress.