{"record":{"id":"bf5c7c3e8b3f140b","repo":"TechnitiumSoftware/DnsServer","slug":"server-host-name-cannot-exceed-63-bytes","errorCode":null,"errorMessage":"Server host name cannot exceed 63 bytes.","messagePattern":"Server host name cannot exceed 63 bytes\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dhcp/DhcpMessage.cs","lineNumber":147,"sourceCode":"            _flags = flags;\n\n            _ciaddr = ciaddr;\n            _yiaddr = yiaddr;\n            _siaddr = siaddr;\n            _giaddr = giaddr;\n\n            _clientHardwareAddress = clientHardwareAddress;\n            _chaddr = new byte[16];\n            Buffer.BlockCopy(_clientHardwareAddress, 0, _chaddr, 0, _clientHardwareAddress.Length);\n\n            _sname = new byte[64];\n            if (sname != null)\n            {\n                _serverHostName = sname;\n\n                byte[] buffer = Encoding.ASCII.GetBytes(sname);\n                if (buffer.Length >= 64)\n                    throw new ArgumentException(\"Server host name cannot exceed 63 bytes.\", nameof(sname));\n\n                Buffer.BlockCopy(buffer, 0, _sname, 0, buffer.Length);\n            }\n\n            _file = new byte[128];\n            if (file != null)\n            {\n                _bootFileName = file;\n\n                byte[] buffer = Encoding.ASCII.GetBytes(file);\n                if (buffer.Length >= 128)\n                    throw new ArgumentException(\"Boot file name cannot exceed 127 bytes.\", nameof(file));\n\n                Buffer.BlockCopy(buffer, 0, _file, 0, buffer.Length);\n            }\n\n            _options = options;\n","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dhcp/DhcpMessage.cs#L129-L165","documentation":"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.","triggerScenarios":"Calling the DhcpMessage constructor with a non-null sname whose ASCII encoding is 64 or more bytes.","commonSituations":"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.","solutions":["Use a server host name whose ASCII encoding is <= 63 bytes.","Pass only the bare host label, not a long FQDN with domain suffixes.","Validate Encoding.ASCII.GetByteCount(sname) < 64 before constructing.","If a longer value is needed, use DHCP options instead of the sname field."],"exampleFix":"// before\nstring sname = \"my-very-long-tftp-bootstrap-server-hostname.example.corp.local\"; // > 63 bytes\nvar msg = new DhcpMessage(op, htype, xid, secs, flags, ..., sname, file, opts); // throws [218]\n\n// after\nstring sname = \"pxe01\"; // short label\nif (Encoding.ASCII.GetByteCount(sname) >= 64) throw new InvalidOperationException(\"sname too long\");\nvar msg = new DhcpMessage(op, htype, xid, secs, flags, ..., sname, file, opts);","handlingStrategy":"validation","validationCode":"if (sname is not null && Encoding.ASCII.GetByteCount(sname) >= 64)\n    throw new ArgumentException(\"Server host name (sname) must be <= 63 ASCII bytes.\", nameof(sname));\n\nvar msg = new DhcpMessage(op, htype, xid, secs, flags, ciaddr, yiaddr, siaddr, giaddr, chaddr, sname, file, opts);","typeGuard":"static bool IsValidSname(string sname) =>\n    sname is null || Encoding.ASCII.GetByteCount(sname) < 64;","tryCatchPattern":null,"preventionTips":["Pass only a short server host label as sname, not a long FQDN.","Validate ASCII byte count < 64 before constructing.","Use DHCP options for values that do not fit the 64-byte sname field."],"tags":["dhcp","validation","constructor","rfc2131","hostname"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}