TechnitiumSoftware/DnsServer · error · ArgumentException

The address must be an IPv4 address: {endingAddress}

Error message

The address must be an IPv4 address: {endingAddress}

What it means

Second guard in ChangeNetwork: endingAddress must be IPv4. Throws ArgumentException(nameof(endingAddress)) if AddressFamily != InterNetwork.

Source

Thrown at DnsServerCore/Dhcp/Scope.cs:1438

            }

            if (expiredLeases > 0)
                _lastModified = utcNow;

            return expiredLeases;
        }

        #endregion

        #region public

        public void ChangeNetwork(IPAddress startingAddress, IPAddress endingAddress, IPAddress subnetMask)
        {
            if (startingAddress.AddressFamily != AddressFamily.InterNetwork)
                throw new ArgumentException("The address must be an IPv4 address: " + startingAddress.ToString(), nameof(startingAddress));

            if (endingAddress.AddressFamily != AddressFamily.InterNetwork)
                throw new ArgumentException("The address must be an IPv4 address: " + endingAddress.ToString(), nameof(endingAddress));

            if (subnetMask.AddressFamily != AddressFamily.InterNetwork)
                throw new ArgumentException("The address must be an IPv4 address: " + subnetMask.ToString(), nameof(subnetMask));

            uint startingAddressNumber = startingAddress.ConvertIpToNumber();
            uint endingAddressNumber = endingAddress.ConvertIpToNumber();

            if (startingAddressNumber >= endingAddressNumber)
                throw new ArgumentException("Ending address must be greater than starting address.");

            _startingAddress = startingAddress;
            _endingAddress = endingAddress;
            _subnetMask = subnetMask;

            //compute other parameters
            uint subnetMaskNumber = _subnetMask.ConvertIpToNumber();
            uint networkAddressNumber = startingAddressNumber & subnetMaskNumber;
            uint broadcastAddressNumber = networkAddressNumber | ~subnetMaskNumber;

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Supply an IPv4 ending address.
  2. Validate both endpoints share AddressFamily.InterNetwork before calling.
  3. Build the range from a CIDR/prefix that yields IPv4 addresses.

Example fix

// before
scope.ChangeNetwork(Parse('192.168.1.100'), Parse('fd00::ff'), Parse('255.255.255.0'));
// after
scope.ChangeNetwork(Parse('192.168.1.100'), Parse('192.168.1.200'), Parse('255.255.255.0'));
Defensive patterns

Strategy: validation

Validate before calling

if (endingAddress.AddressFamily != AddressFamily.InterNetwork)
    throw new ArgumentException("endingAddress must be IPv4", nameof(endingAddress));

Type guard

static bool IsIPv4(IPAddress a) => a.AddressFamily == AddressFamily.InterNetwork;

Try / catch

try { scope.ChangeNetwork(start, end, mask); }
catch (ArgumentException ex) when (ex.ParamName == "endingAddress")
{ /* supply an IPv4 end address, retry */ }

Prevention

When it happens

Trigger: Calling scope.ChangeNetwork(...) with an endingAddress that is not IPv4.

Common situations: Mixed-family range (IPv4 start, IPv6 end). IPv6 ending address supplied to an IPv4 scope.

Related errors


AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13). Data as JSON: /api/errors/882684f47f313276. Report an issue: GitHub.