{"record":{"id":"6c4869c4dd955485","repo":"TechnitiumSoftware/DnsServer","slug":"transaction-id-must-be-4-bytes","errorCode":null,"errorMessage":"Transaction ID must be 4 bytes.","messagePattern":"Transaction ID must be 4 bytes\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dhcp/DhcpMessage.cs","lineNumber":116,"sourceCode":"            if (ciaddr.AddressFamily != AddressFamily.InterNetwork)\n                throw new ArgumentException(\"Address family not supported.\", nameof(ciaddr));\n\n            if (yiaddr.AddressFamily != AddressFamily.InterNetwork)\n                throw new ArgumentException(\"Address family not supported.\", nameof(yiaddr));\n\n            if (siaddr.AddressFamily != AddressFamily.InterNetwork)\n                throw new ArgumentException(\"Address family not supported.\", nameof(siaddr));\n\n            if (giaddr.AddressFamily != AddressFamily.InterNetwork)\n                throw new ArgumentException(\"Address family not supported.\", nameof(giaddr));\n\n            ArgumentNullException.ThrowIfNull(clientHardwareAddress);\n\n            if (clientHardwareAddress.Length > 16)\n                throw new ArgumentException(\"Client hardware address cannot exceed 16 bytes.\", nameof(clientHardwareAddress));\n\n            if (xid.Length != 4)\n                throw new ArgumentException(\"Transaction ID must be 4 bytes.\", nameof(xid));\n\n            if (secs.Length != 2)\n                throw new ArgumentException(\"Seconds elapsed must be 2 bytes.\", nameof(secs));\n\n            _op = op;\n            _htype = hardwareAddressType;\n            _hlen = Convert.ToByte(clientHardwareAddress.Length);\n            _hops = 0;\n\n            _xid = xid;\n\n            _secs = secs;\n            _flags = flags;\n\n            _ciaddr = ciaddr;\n            _yiaddr = yiaddr;\n            _siaddr = siaddr;\n            _giaddr = giaddr;","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dhcp/DhcpMessage.cs#L98-L134","documentation":"Constructor argument guard in DhcpMessage: the transaction ID (xid) must be exactly 4 bytes. RFC 2131 defines the xid field as a 4-octet value used to match request/reply pairs, so any other length is invalid wire data.","triggerScenarios":"Calling the DhcpMessage constructor with an xid byte array whose Length is not 4.","commonSituations":"Generating xid with the wrong RNG width (e.g. 16 bytes / a GUID); passing a uint without converting to 4 bytes; copying xid from a truncated/extended buffer.","solutions":["Generate xid as exactly 4 bytes (e.g. BitConverter.GetBytes(RandomNumberGenerator.GetInt32(int.MinValue, int.MaxValue)) or NextBytes on a 4-byte array).","When forwarding, copy the original 4-byte xid unchanged.","Validate xid.Length == 4 before constructing.","Do not substitute a GUID/16-byte token for xid."],"exampleFix":"// before\nbyte[] xid = Guid.NewGuid().ToByteArray(); // 16 bytes\nvar msg = new DhcpMessage(op, htype, xid, secs, flags, ...); // throws [216]\n\n// after\nbyte[] xid = new byte[4];\nRandomNumberGenerator.Fill(xid);\nvar msg = new DhcpMessage(op, htype, xid, secs, flags, ...);","handlingStrategy":"validation","validationCode":"if (xid is null) throw new ArgumentNullException(nameof(xid));\nif (xid.Length != 4) throw new ArgumentException(\"Transaction ID (xid) must be exactly 4 bytes.\", nameof(xid));\n\nvar msg = new DhcpMessage(op, htype, xid, secs, flags, ciaddr, yiaddr, siaddr, giaddr, chaddr, sname, file, opts);","typeGuard":"static bool IsValidXid(byte[] xid) =>\n    xid is not null && xid.Length == 4;","tryCatchPattern":null,"preventionTips":["Generate xid as exactly 4 random bytes.","When forwarding, reuse the original 4-byte xid unchanged.","Never substitute a GUID (16 bytes) for xid."],"tags":["dhcp","validation","constructor","rfc2131","transaction-id"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}