libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
Ipv6Address Class Reference

IPv6 network address. More...

#include <ipv6address.h>

Public Types

using DataFormat = Array< uint8_t, 16 >
 Raw 16-byte storage format for an IPv6 address.
 

Public Member Functions

 Ipv6Address ()
 Default constructor. Creates a null (all-zero) address.
 
 Ipv6Address (const DataFormat &bytes)
 Constructs from raw 16-byte data.
 
 Ipv6Address (const uint8_t *bytes)
 Constructs from a raw byte pointer (copies 16 bytes).
 
bool isNull () const
 Returns true if all bytes are zero and scope ID is zero.
 
bool isLoopback () const
 Returns true if this is the loopback address (::1).
 
bool isMulticast () const
 Returns true if this is a multicast address (ff00::/8).
 
bool isLinkLocal () const
 Returns true if this is a link-local address (fe80::/10).
 
bool isV4Mapped () const
 Returns true if this is an IPv4-mapped address (::%ffff:0:0/96).
 
bool isSiteLocal () const
 Returns true if this is a site-local address (fec0::/10, deprecated).
 
uint32_t scopeId () const
 Returns the scope ID.
 
void setScopeId (uint32_t id)
 Sets the scope ID.
 
const DataFormatdata () const
 Returns a const reference to the raw 16-byte data.
 
const uint8_traw () const
 Returns a pointer to the raw byte data.
 
String toString () const
 Returns a canonical string representation.
 
Ipv4Address toIpv4 () const
 Extracts the IPv4 address from an IPv4-mapped IPv6 address.
 
MacAddress multicastMac () const
 Returns the Ethernet multicast MAC address for this IPv6 multicast address.
 
Error toSockAddr (struct sockaddr_in6 *sa) const
 Fills a sockaddr_in6 with this address.
 
bool operator== (const Ipv6Address &other) const
 Returns true if both addresses are equal (includes scope ID).
 
bool operator!= (const Ipv6Address &other) const
 Returns true if the addresses are not equal.
 
bool operator< (const Ipv6Address &other) const
 Less-than comparison for ordering (lexicographic, then scope).
 

Static Public Member Functions

static Result< Ipv6AddressfromString (const String &str)
 Parses an IPv6 address from colon-hex notation.
 
static Ipv6Address any ()
 Returns the any address (::).
 
static Ipv6Address loopback ()
 Returns the loopback address (::1).
 
static Result< Ipv6AddressfromSockAddr (const struct sockaddr_in6 *sa)
 Constructs from a sockaddr_in6 structure.
 

Detailed Description

IPv6 network address.

Simple value type representing a 128-bit IPv6 address stored in network byte order. Provides parsing (RFC 5952), formatting, scope ID support, and classification (loopback, multicast, etc.).

This class is purely computational and requires no platform-specific headers or system calls.

This class is not thread-safe. Concurrent access to a single instance requires external synchronization.

Example
auto [addr, err] = Ipv6Address::fromString("fe80::1%eth0");
if(addr.isLinkLocal()) { ... }
String str = addr.toString(); // "fe80::1"
static Result< Ipv6Address > fromString(const String &str)
Parses an IPv6 address from colon-hex notation.
Dynamic array container wrapping std::vector.
Definition list.h:40
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35

Constructor & Destructor Documentation

◆ Ipv6Address() [1/2]

Ipv6Address::Ipv6Address ( const DataFormat bytes)
inlineexplicit

Constructs from raw 16-byte data.

Parameters
bytesThe 16 bytes of the IPv6 address in network byte order.

◆ Ipv6Address() [2/2]

Ipv6Address::Ipv6Address ( const uint8_t bytes)
inlineexplicit

Constructs from a raw byte pointer (copies 16 bytes).

Parameters
bytesPointer to 16 bytes in network byte order.

Member Function Documentation

◆ data()

const DataFormat & Ipv6Address::data ( ) const
inline

Returns a const reference to the raw 16-byte data.

Returns
The underlying DataFormat array.

◆ fromSockAddr()

static Result< Ipv6Address > Ipv6Address::fromSockAddr ( const struct sockaddr_in6 sa)
static

Constructs from a sockaddr_in6 structure.

Parameters
saPointer to a sockaddr_in6. Must have sin6_family == AF_INET6.
Returns
A Result containing the address and Error::Ok, or Error::Invalid if the pointer is null.

◆ fromString()

static Result< Ipv6Address > Ipv6Address::fromString ( const String str)
static

Parses an IPv6 address from colon-hex notation.

Accepts standard colon-hex formats including "::" compression and optional "%scope" suffix. Also accepts IPv4-mapped notation (e.g. "::%%ffff:192.168.1.1").

Parameters
strThe string to parse.
Returns
A Result containing the parsed address and Error::Ok, or a null address and Error::Invalid on parse failure.

◆ multicastMac()

MacAddress Ipv6Address::multicastMac ( ) const

Returns the Ethernet multicast MAC address for this IPv6 multicast address.

Maps this address to its multicast MAC (33:33 + low 32 bits) per RFC 2464.

Returns
The corresponding MacAddress, or a null MacAddress if this address is not multicast.

◆ raw()

const uint8_t * Ipv6Address::raw ( ) const
inline

Returns a pointer to the raw byte data.

Returns
A pointer to the first byte.

◆ scopeId()

uint32_t Ipv6Address::scopeId ( ) const
inline

Returns the scope ID.

Returns
The numeric scope ID, or 0 if not set.

◆ setScopeId()

void Ipv6Address::setScopeId ( uint32_t  id)
inline

Sets the scope ID.

Parameters
idThe numeric scope ID.

◆ toIpv4()

Ipv4Address Ipv6Address::toIpv4 ( ) const

Extracts the IPv4 address from an IPv4-mapped IPv6 address.

Only valid when isV4Mapped() is true. Returns a null Ipv4Address otherwise.

Returns
The extracted Ipv4Address.

◆ toSockAddr()

Error Ipv6Address::toSockAddr ( struct sockaddr_in6 sa) const

Fills a sockaddr_in6 with this address.

Sets sin6_family, sin6_addr, and sin6_scope_id. The port field (sin6_port) is set to zero; callers should set it separately.

Parameters
[out]saThe structure to fill.
Returns
Error::Ok on success, Error::Invalid if sa is null.

◆ toString()

String Ipv6Address::toString ( ) const

Returns a canonical string representation.

Uses "::" compression for the longest run of zero groups per RFC 5952. Does not include the scope ID suffix.

Returns
A String like "fe80::1".

The documentation for this class was generated from the following file: