std/ip/address
std/ip/src/address.trb
IP addresses and socket addresses: values like any other, parsed from text and shown as text (docs/design/OS.md section 5.5, docs/design/NETWORK.md section 4, docs/design/URI.md section 8a). Nothing here touches the network.
type AddressError
type AddressError with Show, Error
Text that is not an address of the kind it was read as, and why.
type Ipv4Address
type Ipv4Address with Show, Equals, Hash, Compare, TryFrom<String, AddressError>
An IPv4 address: four octets, held as one number from 0 to 4294967295.
const loopback
static loopback = Ipv4Address 2130706433
127.0.0.1.
const unspecified
static unspecified = Ipv4Address 0
0.0.0.0, which a listener binds to for every interface.
fn of
static fn of(first: UInt8, second: UInt8, third: UInt8, fourth: UInt8): Ipv4Address
The address of four octets, most significant first: Ipv4Address.of(127, 0, 0, 1).
fn number
fn number(): Int
The address as the number it is, from 0 to 4294967295: what the runtime is handed.
fn octets
fn octets(): List<Int>
The four octets, most significant first.
fn isLoopback
fn isLoopback(): Bool
Inside 127.0.0.0/8.
fn isUnspecified
fn isUnspecified(): Bool
0.0.0.0.
fn isPrivate
fn isPrivate(): Bool
Inside 10.0.0.0/8, 172.16.0.0/12 or 192.168.0.0/16 (RFC 1918).
fn isLinkLocal
fn isLinkLocal(): Bool
Inside 169.254.0.0/16.
fn isMulticast
fn isMulticast(): Bool
Inside 224.0.0.0/4.
fn show
fn show(): String
192.168.1.23.
fn compare
fn compare(other: Ipv4Address): Ordering
In the order of their numbers.
fn tryFrom
static fn tryFrom(text: String): Result<Ipv4Address, AddressError>
Four decimal parts from 0 to 255, separated by dots. A part with a leading zero is refused, because some systems
read 010 as octal and some as decimal, and an address two readers disagree on is no address.
type Ipv6Address
type Ipv6Address with Show, Equals, Hash, Compare, TryFrom<String, AddressError>
An IPv6 address: eight 16-bit segments, held as two 64-bit halves. show() is the RFC 5952 form: lower case, no
leading zeros, the longest run of zero segments collapsed to ::.
const loopback
static loopback = Ipv6Address 0, 1
::1.
const unspecified
static unspecified = Ipv6Address 0, 0
::, which a listener binds to for every interface.
fn of
static fn of(segments: List<Int>): Result<Ipv6Address, AddressError>
The address of eight segments, most significant first. Each is taken modulo 65536.
fn ofHalves
static fn ofHalves(high: Int, low: Int): Ipv6Address
The address of its two halves, as the runtime hands them over.
fn high
fn high(): Int
Segments 0 to 3 as the bits of an Int: what the runtime is handed.
fn low
fn low(): Int
Segments 4 to 7 as the bits of an Int.
fn segments
fn segments(): List<Int>
The eight segments, most significant first, each from 0 to 65535.
fn isLoopback
fn isLoopback(): Bool
::1.
fn isUnspecified
fn isUnspecified(): Bool
::.
fn isLinkLocal
fn isLinkLocal(): Bool
Inside fe80::/10.
fn isUniqueLocal
fn isUniqueLocal(): Bool
Inside fc00::/7.
fn isMulticast
fn isMulticast(): Bool
Inside ff00::/8.
fn mappedVersion4
fn mappedVersion4(): Ipv4Address?
The IPv4 address inside an IPv4-mapped one: ::ffff:192.0.2.1.
fn show
fn show(): String
The RFC 5952 form: 2001:db8::1, ::1, ::ffff:192.0.2.1.
fn compare
fn compare(other: Ipv6Address): Ordering
Half by half, as the numbers they are without a sign.
fn tryFrom
static fn tryFrom(text: String): Result<Ipv6Address, AddressError>
RFC 4291 section 2.2: up to eight segments of one to four hexadecimal digits, one :: for a run of zeros, and an
IPv4 address in place of the last two. A zone (fe80::1%eth0) is not part of an address and is refused.
type IpAddress
type IpAddress with Show, Equals, Hash, Compare, TryFrom<String, AddressError>
Either version. Reading tells them apart by the text: a colon is IPv6.
case Version4
case Version4(address: Ipv4Address)
Not documented.
case Version6
case Version6(address: Ipv6Address)
Not documented.
const loopback
static loopback = IpAddress.Version4 Ipv4Address.loopback
127.0.0.1.
fn isLoopback
fn isLoopback(): Bool
The loopback address of either version.
fn isUnspecified
fn isUnspecified(): Bool
The unspecified address of either version, which a listener binds to for every interface.
fn version
fn version(): Int
4 or 6.
fn show
fn show(): String
Not documented.
fn compare
fn compare(other: IpAddress): Ordering
Every IPv4 address before every IPv6 address, and each version in the order of its numbers.
fn tryFrom
static fn tryFrom(text: String): Result<IpAddress, AddressError>
Not documented.
type SocketAddress
type SocketAddress with Show, Equals, Hash, TryFrom<String, AddressError>
An IP address and a port: where a listener listens and where a connection goes.
field address
address: IpAddress
Not documented.
field port
port: Int
From 0 to 65535; 0 asks the system to choose a free port where a listener binds.
fn show
fn show(): String
127.0.0.1:8080, or [::1]:8080 - the brackets tell the port from the address.
fn tryFrom
static fn tryFrom(text: String): Result<SocketAddress, AddressError>
host:port with an IPv4 address, [host]:port with an IPv6 one.