std/netip
On this page
Index
- type
Addr- method
Addr.is_4 - method
Addr.is_6 - method
Addr.is_4in6 - method
Addr.unmap - method
Addr.is_loopback - method
Addr.is_private - method
Addr.is_unspecified - method
Addr.is_link_local_unicast - method
Addr.is_multicast - method
Addr.bytes - method
Addr.display
- method
- type
Prefix- method
Prefix.contains - method
Prefix.masked - method
Prefix.display
- method
- type
ParseErr- method
ParseErr.display
- method
- fn
parse_addr - fn
lookup - fn
parse_prefix - fn
addr_from_bytes
Types
Addr
struct Addr {
bits: Int
hi: Int
lo: Int
zone: Str
} derive OrdAn IP address: bits is 32 for IPv4, 128 for IPv6, 0 for the zero
value; hi and lo its 16 bytes as two words (an IPv4 address as
::ffff:a.b.c.d); zone an IPv6 zone. The order is Go’s Addr.Compare.
Addr.is_4
fn (a: Addr) is_4() -> BoolAddr.is_6
fn (a: Addr) is_6() -> BoolAddr.is_4in6
fn (a: Addr) is_4in6() -> BoolAddr.unmap
fn (a: Addr) unmap() -> AddrAn IPv4 in IPv6 address as IPv4 (its zone dropped), others as they are.
Addr.is_loopback
fn (a: Addr) is_loopback() -> BoolAddr.is_private
fn (a: Addr) is_private() -> BoolAddr.is_unspecified
fn (a: Addr) is_unspecified() -> BoolAddr.is_link_local_unicast
fn (a: Addr) is_link_local_unicast() -> BoolAddr.is_multicast
fn (a: Addr) is_multicast() -> BoolAddr.bytes
fn (a: Addr) bytes() -> Bytes4 bytes for IPv4, 16 for IPv6 (Go’s AsSlice).
Addr.display
fn (a: Addr) display() -> StrGo’s String: 1.2.3.4, 2001:db8::1, ::ffff:1.2.3.4, fe80::1%eth0.
Prefix
struct Prefix {
addr: Addr
len: Int
}An address and a prefix length.
Prefix.contains
fn (p: Prefix) contains(a: Addr) -> BoolPrefix.masked
fn (p: Prefix) masked() -> PrefixPrefix.display
fn (p: Prefix) display() -> StrParseErr
struct ParseErr {
msg: Str
}Go’s texts: ParseAddr("1.2.3"): IPv4 address too short.
ParseErr.display
fn (e: ParseErr) display() -> StrFunctions
parse_addr
fn parse_addr(s: Str) -> Addr ! ParseErrGo’s ParseAddr: IPv4 (no leading zeros), IPv6, IPv4 in IPv6, zones.
lookup
fn lookup(n: Net, host: Str) -> List[Addr] ! NetErr uses net.dialThe addresses of host, in the order Net.dial tries them (Go’s net.LookupIP through Net.lookup_host; decision 0406).
parse_prefix
fn parse_prefix(s: Str) -> Prefix ! ParseErrGo’s ParsePrefix: 10.0.0.0/8, 2001:db8::/32.
addr_from_bytes
fn addr_from_bytes(b: Bytes) -> Addr?The address of 4 or 16 bytes (AddrFrom4, AddrFrom16); None for another length.
↑ index