{"record":{"id":"3dc8b2ec6f7f8d1e","repo":"TechnitiumSoftware/DnsServer","slug":"ending-address-cannot-be-same-as-the-broadcast-add","errorCode":null,"errorMessage":"Ending address cannot be same as the broadcast address.","messagePattern":"Ending address cannot be same as the broadcast address\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dhcp/Scope.cs","lineNumber":1462,"sourceCode":"            uint endingAddressNumber = endingAddress.ConvertIpToNumber();\n\n            if (startingAddressNumber >= endingAddressNumber)\n                throw new ArgumentException(\"Ending address must be greater than starting address.\");\n\n            _startingAddress = startingAddress;\n            _endingAddress = endingAddress;\n            _subnetMask = subnetMask;\n\n            //compute other parameters\n            uint subnetMaskNumber = _subnetMask.ConvertIpToNumber();\n            uint networkAddressNumber = startingAddressNumber & subnetMaskNumber;\n            uint broadcastAddressNumber = networkAddressNumber | ~subnetMaskNumber;\n\n            if (networkAddressNumber == startingAddressNumber)\n                throw new ArgumentException(\"Starting address cannot be same as the network address.\");\n\n            if (broadcastAddressNumber == endingAddressNumber)\n                throw new ArgumentException(\"Ending address cannot be same as the broadcast address.\");\n\n            _networkAddress = IPAddressExtensions.ConvertNumberToIp(networkAddressNumber);\n            _broadcastAddress = IPAddressExtensions.ConvertNumberToIp(broadcastAddressNumber);\n\n            _lastAddressOfferedLock.Wait();\n            try\n            {\n                _lastAddressOffered = IPAddressExtensions.ConvertNumberToIp(startingAddressNumber - 1u);\n            }\n            finally\n            {\n                _lastAddressOfferedLock.Release();\n            }\n        }\n\n        public bool TryAddReservedLease(Lease reservedLease)\n        {\n            if (_reservedLeases.TryAdd(reservedLease.ClientIdentifier, reservedLease))","sourceCodeStart":1444,"sourceCodeEnd":1480,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dhcp/Scope.cs#L1444-L1480","documentation":"Thrown by Scope construction / ChangeNetwork when the ending address equals the broadcast address (network OR NOT mask). The broadcast address is reserved for the subnet and cannot be part of the offerable pool, so the library refuses it.","triggerScenarios":"Passing an endingAddress that is the subnet broadcast: e.g. end=192.168.1.255 with mask 255.255.255.0, or end=10.255.255.255 with mask 255.0.0.0. Also when generating end = broadcast without decrementing, or when a narrow mask pushes broadcast onto the supplied end.","commonSituations":"Config generated from CIDR that uses the full block including broadcast; UI defaulting the end field to x.x.x.255; tooling that sets end = broadcastAddress verbatim.","solutions":["Decrement the ending address below the broadcast (broadcast - 1) before constructing the Scope.","Recompute: if (end == (network | ~mask)), reduce end by one host.","For tiny subnets (/31, /32) move to a larger block that has usable hosts between network and broadcast.","Confirm the subnet mask is contiguous and correct so broadcast is computed as expected."],"exampleFix":"// before\nvar scope = new Scope(name, true,\n    IPAddress.Parse(\"192.168.1.1\"),\n    IPAddress.Parse(\"192.168.1.255\"), // broadcast -> throws\n    IPAddress.Parse(\"255.255.255.0\"), log, dhcpServer);\n\n// after\nvar scope = new Scope(name, true,\n    IPAddress.Parse(\"192.168.1.1\"),\n    IPAddress.Parse(\"192.168.1.254\"), // broadcast - 1\n    IPAddress.Parse(\"255.255.255.0\"), log, dhcpServer);","handlingStrategy":"validation","validationCode":"static uint ToUint(IPAddress a){ var b=a.GetAddressBytes(); return (uint)((b[0]<<24)|(b[1]<<16)|(b[2]<<8)|b[3]); }\nstatic IPAddress Decrement(IPAddress a){ var u=ToUint(a)-1u; return new IPAddress(new byte[]{(byte)(u>>24),(byte)(u>>16),(byte)(u>>8),(byte)u}); }\n\nuint network = ToUint(start) & ToUint(mask);\nuint broadcast = network | ~ToUint(mask);\nif (broadcast == ToUint(end)) endingAddress = Decrement(end);","typeGuard":"static bool EndIsNotBroadcast(IPAddress end, IPAddress start, IPAddress mask){\n    uint net = ToUint(start) & ToUint(mask);\n    uint bcast = net | ~ToUint(mask);\n    return bcast != ToUint(end);\n}","tryCatchPattern":"try { scope.ChangeNetwork(start, end, mask); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"broadcast address\"))\n{ end = Decrement(end); scope.ChangeNetwork(start, end, mask); }","preventionTips":["Never set the end field to x.x.x.255 for a /24.","Generate end from broadcast-1 when reading CIDR config.","Validate the mask is contiguous so broadcast is what you expect."],"tags":["dhcp","ipv4","validation","scope","subnet"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}