IpLiteral

The one textual form of an IP address, which Endpoint.Udp and Endpoint.Tcp keep their host in, so that one address is one endpoint: dotted decimal for IPv4, RFC 5952 canonical text for IPv6 (lower case, no leading zeros, the longest run of two or more zero groups compressed to ::). IPv4-mapped IPv6 addresses are written as IPv4, as a dual-stack socket reports such peers.

Transports format received addresses with format; endpoints and clients normalize literals with canonical.

Functions

Link copied to clipboard
fun canonical(text: String): String?

The canonical text of an IPv4 or IPv6 literal (without brackets or zone), or null if text is none, by the grammar of parse.

Link copied to clipboard
fun format(address: ByteArray): String

The text of a 4- or 16-byte address.

Link copied to clipboard
fun parse(text: String): ByteArray?

The bytes of an IPv4 or IPv6 literal, or null if text is none. The grammar is RFC 3986 §3.2.2's IPv4address and IPv6address: a decimal octet has no leading zero and a group is one to four hex digits, without a sign. Other text is a name, not an address: 010.0.0.1 is no literal, since RFC 3986 §7.4 warns that resolvers may read it as octal, an address other than 10.0.0.1.