For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
Ipv6Addr
struct Ipv6Addr
Represents an IPv6 address.
The address is stored as sixteen octets in network byte order.
Implemented traits
AnyType,
Copyable,
Deinitable,
Equatable,
ImplicitlyCopyable,
Movable,
Writable
comptime members
localhost
comptime localhost = Ipv6Addr(UInt16(0), UInt16(0), UInt16(0), UInt16(0), UInt16(0), UInt16(0), UInt16(0), UInt16(1))
The loopback address, ::1.
unspecified
comptime unspecified = Ipv6Addr(UInt16(0), UInt16(0), UInt16(0), UInt16(0), UInt16(0), UInt16(0), UInt16(0), UInt16(0))
The unspecified address, ::.
Methods
__init__
def __init__(out self, a: UInt16, b: UInt16, c: UInt16, d: UInt16, e: UInt16, f: UInt16, g: UInt16, h: UInt16, /)
Constructs an address from its eight 16-bit segments, first segment first.
Args:
def __init__(out self, *, bits: UInt128)
Constructs an address from its 128-bit numeric value.
The most significant byte of bits becomes the first octet, so
Ipv6Addr(bits=1) is ::1.
Args:
- bits (
UInt128): The address as an integer in host byte order.
def __init__(out self, *, segments: Array[UInt16, Int(8)])
Constructs an address from an array of its eight 16-bit segments.
Args:
- segments (
Array[UInt16, Int(8)]): The segments in host byte order, first segment first.
def __init__(out self, *, var octets: Array[UInt8, Int(16)])
Constructs an address from its octets in network byte order.
Args:
- octets (
Array[UInt8, Int(16)]): The sixteen octets, first octet first.
def __init__(out self, *, copy: Self)
Copies an address.
Args:
- copy (
Self): The address to copy.
bits
def bits(self) -> UInt128
Returns the address as a 128-bit integer.
This is the inverse of the bits initializer: the first octet
becomes the most significant byte.
Returns:
UInt128: The address as an integer in host byte order.
write_to
def write_to(self, mut writer: T)
Writes the address in RFC 5952 notation, such as 2001:db8::1.
Each segment is lowercase hexadecimal without leading zeros, and the
longest run of two or more zero segments (the first, on a tie) becomes
::. An IPv4-mapped address keeps its IPv4 part in dotted-decimal
notation, such as ::ffff:192.0.2.1.
Args:
- writer (
T): The writer to write to.