IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
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:

  • ​a (UInt16): The first segment.
  • ​b (UInt16): The second segment.
  • ​c (UInt16): The third segment.
  • ​d (UInt16): The fourth segment.
  • ​e (UInt16): The fifth segment.
  • ​f (UInt16): The sixth segment.
  • ​g (UInt16): The seventh segment.
  • ​h (UInt16): The eighth segment.

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:

def __init__(out self, *, var octets: Array[UInt8, Int(16)])

Constructs an address from its octets in network byte order.

Args:

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.