Package-level declarations

Types

Link copied to clipboard
sealed interface CidrNumber<TSelf : CidrNumber<TSelf>> : Comparable<TSelf>

Number with a byte layout and semantics optimized for CIDR/IP operations. The maximum number of addresses inside an IP address space is 2^32 for IPv4 and 2^128 for IPv6. Hence, 32/128-bit unsigned integers are not enough to represent the size of /0 networks, and an additional bit is needed. At the same time, the actual number of bytes used for addresses and netmasks is 4/16, which is why (by default) a CidrNumber's byte representation is truncated to 4/16 bytes to keep it efficient for CIDR operations.

Functions

Link copied to clipboard
infix fun ByteArray.and(other: ByteArray): ByteArray

logical AND operation returning a newly-allocated ByteArray.

Link copied to clipboard

In-place logical AND operation, modifying the receiver ByteArray. Returns the number of modified bits

Link copied to clipboard

Compares this ByteArray to other interpreted as an unsigned BE (network order)

Link copied to clipboard
operator fun ByteArray.inv(): ByteArray
Link copied to clipboard

IN-PLACE inversion

Link copied to clipboard
infix fun ByteArray.or(other: ByteArray): ByteArray

logical OR operation returning a newly-allocated ByteArray.

Link copied to clipboard
infix fun ByteArray.shl(bits: Int): ByteArray

Logical left shift (zero-fill) of a big-endian ByteArray by bits.

Link copied to clipboard
infix fun ByteArray.shr(bits: Int): ByteArray

Logical right shift (zero-fill) of a big-endian ByteArray by bits.

Link copied to clipboard

Converts the UInt value to its IPv4 address representation in the form of a 4-byte-long ByteArray. Each byte in the array corresponds to one octet of the IPv4 address, arranged in network byte order (big-endian).

Converts the UInt value to its IPv4 address representation in the form of a 4-byte-long ByteArray. Each byte in the array corresponds to one octet of the IPv4 address, arranged in network byte order (big-endian). Any values larger than UInt.MAX_VALUE will be truncated to four bytes

Link copied to clipboard

Creates a netmask from this prefix. The resulting number of octets depends on the specified family.

fun Prefix.toNetmask(octetCount: Int): Netmask

Creates a netmask from this prefix. Arbitrary octetCounts can be specified.

Link copied to clipboard

Converts a netmask into its CIDR prefix length. Validates that the mask's length and that it is contiguous (all 1-bits followed by 0-bits).

Link copied to clipboard
fun ByteArray.toShortArray(bigEndian: Boolean = true): ShortArray
Link copied to clipboard
infix fun ByteArray.xor(other: ByteArray): ByteArray

logical OR operation returning a newly-allocated ByteArray.