TechnitiumSoftware/DnsServer · error · ArgumentException

Server host name cannot exceed 63 bytes.

Error message

Server host name cannot exceed 63 bytes.

What it means

Constructor argument guard in DhcpMessage: the server host name (sname) must be at most 63 ASCII bytes. RFC 2131 fixes the 'sname' field at 64 bytes (63 usable + a null terminator); the constructor ASCII-encodes sname and rejects a result of 64+ bytes. The check uses >= 64, so up to 63 bytes are allowed.

Source

Thrown at DnsServerCore/Dhcp/DhcpMessage.cs:147

            _flags = flags;

            _ciaddr = ciaddr;
            _yiaddr = yiaddr;
            _siaddr = siaddr;
            _giaddr = giaddr;

            _clientHardwareAddress = clientHardwareAddress;
            _chaddr = new byte[16];
            Buffer.BlockCopy(_clientHardwareAddress, 0, _chaddr, 0, _clientHardwareAddress.Length);

            _sname = new byte[64];
            if (sname != null)
            {
                _serverHostName = sname;

                byte[] buffer = Encoding.ASCII.GetBytes(sname);
                if (buffer.Length >= 64)
                    throw new ArgumentException("Server host name cannot exceed 63 bytes.", nameof(sname));

                Buffer.BlockCopy(buffer, 0, _sname, 0, buffer.Length);
            }

            _file = new byte[128];
            if (file != null)
            {
                _bootFileName = file;

                byte[] buffer = Encoding.ASCII.GetBytes(file);
                if (buffer.Length >= 128)
                    throw new ArgumentException("Boot file name cannot exceed 127 bytes.", nameof(file));

                Buffer.BlockCopy(buffer, 0, _file, 0, buffer.Length);
            }

            _options = options;

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Use a server host name whose ASCII encoding is <= 63 bytes.
  2. Pass only the bare host label, not a long FQDN with domain suffixes.
  3. Validate Encoding.ASCII.GetByteCount(sname) < 64 before constructing.
  4. If a longer value is needed, use DHCP options instead of the sname field.

Example fix

// before
string sname = "my-very-long-tftp-bootstrap-server-hostname.example.corp.local"; // > 63 bytes
var msg = new DhcpMessage(op, htype, xid, secs, flags, ..., sname, file, opts); // throws [218]

// after
string sname = "pxe01"; // short label
if (Encoding.ASCII.GetByteCount(sname) >= 64) throw new InvalidOperationException("sname too long");
var msg = new DhcpMessage(op, htype, xid, secs, flags, ..., sname, file, opts);
Defensive patterns

Strategy: validation

Validate before calling

if (sname is not null && Encoding.ASCII.GetByteCount(sname) >= 64)
    throw new ArgumentException("Server host name (sname) must be <= 63 ASCII bytes.", nameof(sname));

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

Type guard

static bool IsValidSname(string sname) =>
    sname is null || Encoding.ASCII.GetByteCount(sname) < 64;

Prevention

When it happens

Trigger: Calling the DhcpMessage constructor with a non-null sname whose ASCII encoding is 64 or more bytes.

Common situations: A fully-qualified server name exceeding 63 chars (DNS label-length limits aside); appending a domain suffix that pushes it over; non-hostname text being placed in sname; TFTP/BOOTP server name too long.

Related errors


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