{"record":{"id":"882684f47f313276","repo":"TechnitiumSoftware/DnsServer","slug":"the-address-must-be-an-ipv4-address-endingaddres","errorCode":null,"errorMessage":"The address must be an IPv4 address: {endingAddress}","messagePattern":"The address must be an IPv4 address: (.+?)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dhcp/Scope.cs","lineNumber":1438,"sourceCode":"            }\n\n            if (expiredLeases > 0)\n                _lastModified = utcNow;\n\n            return expiredLeases;\n        }\n\n        #endregion\n\n        #region public\n\n        public void ChangeNetwork(IPAddress startingAddress, IPAddress endingAddress, IPAddress subnetMask)\n        {\n            if (startingAddress.AddressFamily != AddressFamily.InterNetwork)\n                throw new ArgumentException(\"The address must be an IPv4 address: \" + startingAddress.ToString(), nameof(startingAddress));\n\n            if (endingAddress.AddressFamily != AddressFamily.InterNetwork)\n                throw new ArgumentException(\"The address must be an IPv4 address: \" + endingAddress.ToString(), nameof(endingAddress));\n\n            if (subnetMask.AddressFamily != AddressFamily.InterNetwork)\n                throw new ArgumentException(\"The address must be an IPv4 address: \" + subnetMask.ToString(), nameof(subnetMask));\n\n            uint startingAddressNumber = startingAddress.ConvertIpToNumber();\n            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;","sourceCodeStart":1420,"sourceCodeEnd":1456,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dhcp/Scope.cs#L1420-L1456","documentation":"Second guard in ChangeNetwork: endingAddress must be IPv4. Throws ArgumentException(nameof(endingAddress)) if AddressFamily != InterNetwork.","triggerScenarios":"Calling scope.ChangeNetwork(...) with an endingAddress that is not IPv4.","commonSituations":"Mixed-family range (IPv4 start, IPv6 end). IPv6 ending address supplied to an IPv4 scope.","solutions":["Supply an IPv4 ending address.","Validate both endpoints share AddressFamily.InterNetwork before calling.","Build the range from a CIDR/prefix that yields IPv4 addresses."],"exampleFix":"// before\nscope.ChangeNetwork(Parse('192.168.1.100'), Parse('fd00::ff'), Parse('255.255.255.0'));\n// after\nscope.ChangeNetwork(Parse('192.168.1.100'), Parse('192.168.1.200'), Parse('255.255.255.0'));","handlingStrategy":"validation","validationCode":"if (endingAddress.AddressFamily != AddressFamily.InterNetwork)\n    throw new ArgumentException(\"endingAddress must be IPv4\", nameof(endingAddress));","typeGuard":"static bool IsIPv4(IPAddress a) => a.AddressFamily == AddressFamily.InterNetwork;","tryCatchPattern":"try { scope.ChangeNetwork(start, end, mask); }\ncatch (ArgumentException ex) when (ex.ParamName == \"endingAddress\")\n{ /* supply an IPv4 end address, retry */ }","preventionTips":["Ensure both endpoints share IPv4 family.","Derive end address from start + pool size.","Validate at the config boundary."],"tags":["dhcp","scope","ipv4","validation"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}