NAME

Net::DHCPv6::DUID - DUID parse/emit and helper constructors

VERSION

version 0.002

SYNOPSIS

use Net::DHCPv6::DUID;
use Net::DHCPv6::Constants;

# DUID-LLT (type 1) -- link-layer type + time + MAC
my $llt = Net::DHCPv6::DUID->new_llt($LINK_TYPE_ETHERNET, 0x2a3b4c5d,
    "\x00\x11\x22\x33\x44\x55");

# DUID-EN (type 2) -- enterprise number + identifier
my $en = Net::DHCPv6::DUID->new_en(9, "\x00\x01\x02\x03\x04\x05");

# DUID-LL (type 3) -- link-layer type + MAC
my $ll = Net::DHCPv6::DUID->new_ll($LINK_TYPE_ETHERNET,
    "\x00\x11\x22\x33\x44\x55");

# DUID-UUID (type 4) -- 16-byte UUID
my $uuid = Net::DHCPv6::DUID->new_uuid(
    pack('H*', 'f81d4fae7dec11d0a76500a0c91e6bf6') );

my $bytes = $llt->as_bytes;
my $parsed = Net::DHCPv6::DUID->from_bytes($bytes);

DESCRIPTION

Parses, constructs, and serializes DHCPv6 Unique Identifiers (DUIDs) as defined in RFC 8415 §11. Supports DUID-LLT, DUID-EN, DUID-LL, and DUID-UUID types. Unknown DUID types are stored opaquely.

ALPHA STATUS

ALPHA SOFTWARE. This is an early release. The interface is experimental and subject to change without notice.

CONSTRUCTORS

new(%params)

Generic constructor. Requires duid_type. Additional required fields depend on the type:

DUID-EN: enterprise_number, identifier
DUID-UUID: identifier (must be exactly 16 bytes)
Unknown types: identifier (optional)

Convenience constructor for DUID-LLT (type 1).

new_en($enterprise_number, $identifier)

Convenience constructor for DUID-EN (type 2).

Convenience constructor for DUID-LL (type 3).

new_uuid($uuid_bytes)

Convenience constructor for DUID-UUID (type 4).

from_bytes($bytes)

Parse a DUID from its wire-format representation. Reads the 2-byte type prefix and dispatches to the appropriate parser. Falls back to opaque storage for unknown types.

try_from_bytes($bytes)

Attempts to parse a DUID from wire bytes. Returns ($duid, $error). On truncation, $duid is a partial object with whatever fields could be decoded before the error, and $error is an error string. On success, $error is undef.

ACCESSORS

duid_type
time
enterprise_number
identifier

METHODS

as_bytes

Serialize to wire format.

as_string

Human-readable representation: TYPE:hex.

length

Byte length of the wire-format representation.

SEE ALSO

Net::DHCPv6, RFC 8415 §11, RFC 6355

AUTHOR

Dean Hamstead <dean@fragfest.com.au>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2026 by Dean Hamstead.

This is free software, licensed under:

The MIT (X11) License