TechnitiumSoftware/DnsServer · error · ArgumentException
Seconds elapsed must be 2 bytes.
Error message
Seconds elapsed must be 2 bytes.
What it means
Constructor argument guard in DhcpMessage: the seconds-elapsed (secs) field must be exactly 2 bytes. RFC 2131 defines secs as a 2-octet field recording seconds since the client began the address acquisition process; other lengths are invalid wire data.
Source
Thrown at DnsServerCore/Dhcp/DhcpMessage.cs:119
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;
_yiaddr = yiaddr;
_siaddr = siaddr;
_giaddr = giaddr;
_clientHardwareAddress = clientHardwareAddress;
_chaddr = new byte[16];View on GitHub (pinned to d0484b6c1e)
Solutions
- Build secs as exactly 2 bytes using BitConverter.GetBytes((ushort)seconds) in the correct endianness (network byte order).
- When forwarding a parsed packet, reuse its original 2-byte secs slice.
- Validate secs.Length == 2 before constructing.
- Do not pass a full int/uint representation.
Example fix
// before
byte[] secs = BitConverter.GetBytes(0u); // 4 bytes
var msg = new DhcpMessage(op, htype, xid, secs, flags, ...); // throws [217]
// after: 2 bytes, network order
ushort s = 0;
byte[] secs = new byte[] { (byte)(s >> 8), (byte)(s & 0xff) };
var msg = new DhcpMessage(op, htype, xid, secs, flags, ...); Defensive patterns
Strategy: validation
Validate before calling
if (secs is null) throw new ArgumentNullException(nameof(secs));
if (secs.Length != 2) throw new ArgumentException("Seconds elapsed (secs) must be exactly 2 bytes.", nameof(secs));
var msg = new DhcpMessage(op, htype, xid, secs, flags, ciaddr, yiaddr, siaddr, giaddr, chaddr, sname, file, opts); Type guard
static bool IsValidSecs(byte[] secs) =>
secs is not null && secs.Length == 2; Prevention
- Build secs as 2 bytes (network order), not a 4-byte uint.
- Reuse the parsed packet's secs slice when forwarding.
- Validate length before constructing.
When it happens
Trigger: Calling the DhcpMessage constructor with a secs byte array whose Length is not 2.
Common situations: Passing a ushort/int directly instead of its 2-byte form; creating secs from the wrong buffer slice; a helper that emits 4 bytes (uint) instead of 2.
Related errors
- Client hardware address cannot exceed 16 bytes.
- Transaction ID must be 4 bytes.
- Server host name cannot exceed 63 bytes.
- Boot file name cannot exceed 127 bytes.
- Address family not supported.
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/80aae9c234928905.
Report an issue: GitHub.