TechnitiumSoftware/DnsServer · error · ArgumentException

Client hardware address cannot exceed 16 bytes.

Error message

Client hardware address cannot exceed 16 bytes.

What it means

Constructor argument guard in DhcpMessage: clientHardwareAddress must not exceed 16 bytes. RFC 2131 fixes the 'chaddr' field at exactly 16 bytes; the constructor copies the supplied hardware address into a 16-byte buffer via Buffer.BlockCopy, so anything longer would overflow/truncate. The hlen byte also stores the length.

Source

Thrown at DnsServerCore/Dhcp/DhcpMessage.cs:113

        public DhcpMessage(DhcpMessageOpCode op, DhcpMessageHardwareAddressType hardwareAddressType, byte[] xid, byte[] secs, DhcpMessageFlags flags, IPAddress ciaddr, IPAddress yiaddr, IPAddress siaddr, IPAddress giaddr, byte[] clientHardwareAddress, string sname, string file, IReadOnlyCollection<DhcpOption> options)
        {
            if (ciaddr.AddressFamily != AddressFamily.InterNetwork)
                throw new ArgumentException("Address family not supported.", nameof(ciaddr));

            if (yiaddr.AddressFamily != AddressFamily.InterNetwork)
                throw new ArgumentException("Address family not supported.", nameof(yiaddr));

            if (siaddr.AddressFamily != AddressFamily.InterNetwork)
                throw new ArgumentException("Address family not supported.", nameof(siaddr));

            if (giaddr.AddressFamily != AddressFamily.InterNetwork)
                throw new ArgumentException("Address family not supported.", nameof(giaddr));

            ArgumentNullException.ThrowIfNull(clientHardwareAddress);

            if (clientHardwareAddress.Length > 16)
                throw new ArgumentException("Client hardware address cannot exceed 16 bytes.", nameof(clientHardwareAddress));

            if (xid.Length != 4)
                throw new ArgumentException("Transaction ID must be 4 bytes.", nameof(xid));

            if (secs.Length != 2)
                throw new ArgumentException("Seconds elapsed must be 2 bytes.", nameof(secs));

            _op = op;
            _htype = hardwareAddressType;
            _hlen = Convert.ToByte(clientHardwareAddress.Length);
            _hops = 0;

            _xid = xid;

            _secs = secs;
            _flags = flags;

            _ciaddr = ciaddr;

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Pass only the Layer-2 hardware address (typically a 6-byte Ethernet MAC) as clientHardwareAddress.
  2. Move long client identifiers into a DHCP Client Identifier option instead of chaddr.
  3. Truncate/normalize the identifier to <= 16 bytes if it legitimately encodes a longer link-layer address.
  4. Validate clientHardwareAddress.Length before constructing.

Example fix

// before
byte[] chaddr = clientId; // 20-byte client identifier
var msg = new DhcpMessage(op, htype, xid, secs, flags, ciaddr, yiaddr, siaddr, giaddr, chaddr, sname, file, opts); // throws [215]

// after: MAC in chaddr, client-id in an option
byte[] chaddr = nic.GetPhysicalAddress().GetAddressBytes(); // 6 bytes
var opts2 = new List<DhcpOption>(opts) { new ClientIdentifierOption(chaddr) };
var msg = new DhcpMessage(op, htype, xid, secs, flags, ciaddr, yiaddr, siaddr, giaddr, chaddr, sname, file, opts2);
Defensive patterns

Strategy: validation

Validate before calling

const int MAX_CHADDR = 16;
if (clientHardwareAddress is null) throw new ArgumentNullException(nameof(clientHardwareAddress));
if (clientHardwareAddress.Length > MAX_CHADDR)
    throw new ArgumentException($"Client hardware address must be <= {MAX_CHADDR} bytes.", nameof(clientHardwareAddress));

var msg = new DhcpMessage(op, htype, xid, secs, flags, ciaddr, yiaddr, siaddr, giaddr, clientHardwareAddress, sname, file, opts);

Type guard

static bool IsValidChaddr(byte[] chaddr) =>
    chaddr is not null && chaddr.Length <= 16;

Prevention

When it happens

Trigger: Calling the DhcpMessage constructor with a clientHardwareAddress byte array longer than 16 bytes.

Common situations: Passing a non-Ethernet hardware identifier (e.g. a long client-id, a GUID, a concatenated identifier) where a MAC address is expected; IPv6 interface tokens; a DHCPv6 client identifier reused for DHCPv4.

Related errors


AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13). Data as JSON: /api/errors/10ea5bbe552724ac. Report an issue: GitHub.