{"record":{"id":"f1b8a5efb5ee2946","repo":"TechnitiumSoftware/DnsServer","slug":"address-family-not-supported","errorCode":null,"errorMessage":"Address family not supported.","messagePattern":"Address family not supported\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dhcp/DhcpMessage.cs","lineNumber":99,"sourceCode":"        DhcpMessageTypeOption _dhcpMessageType;\n        VendorClassIdentifierOption _vendorClassIdentifier;\n        ClientIdentifierOption _clientIdentifier;\n        ClientIdentifierOption _clientHardwareIdentifier;\n        HostNameOption _hostName;\n        ClientFullyQualifiedDomainNameOption _clientFullyQualifiedDomainName;\n        ParameterRequestListOption _parameterRequestList;\n        MaximumDhcpMessageSizeOption _maximumDhcpMessageSize;\n        ServerIdentifierOption _serverIdentifier;\n        RequestedIpAddressOption _requestedIpAddress;\n\n        #endregion\n\n        #region constructor\n\n        public DhcpMessage(DhcpMessageOpCode op, DhcpMessageHardwareAddressType hardwareAddressType, byte[] xid, byte[] secs, DhcpMessageFlags flags, IPAddress ciaddr, IPAddress yiaddr, IPAddress siaddr, IPAddress giaddr, byte[] clientHardwareAddress, string sname, string file, IReadOnlyCollection<DhcpOption> options)\n        {\n            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","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dhcp/DhcpMessage.cs#L81-L117","documentation":"Constructor argument guard in DhcpMessage: the ciaddr (client IP address) field must be IPv4 (AddressFamily.InterNetwork). DHCP (RFC 2131) is an IPv4-only protocol; the 4-octet ciaddr slot in the wire format has no room for an IPv6 address, so any non-IPv4 IPAddress is rejected. Note this is the manual DhcpMessage builder constructor, not the packet parser.","triggerScenarios":"Calling the DhcpMessage constructor with an IPAddress for ciaddr whose AddressFamily is InterNetworkV6 (or other) — e.g. building a DHCP reply and passing an IPv6 address object for the client address.","commonSituations":"Mixing IPv6 address objects into DHCPv4 message construction; a helper that resolves names and returns IPv6 addresses by default; code shared between DHCPv4 and (future) DHCPv6 paths passing the wrong family.","solutions":["Pass only IPv4 IPAddress values for ciaddr (and yiaddr/siaddr/giaddr).","When resolving a name, filter to AddressFamily.InterNetwork.","Map/convert or skip IPv6 addresses before building the DHCP message.","Validate ciaddr.AddressFamily before constructing DhcpMessage."],"exampleFix":"// before\nIPAddress ciaddr = IPAddress.Parse(\"fe80::1\"); // IPv6\nvar msg = new DhcpMessage(op, htype, xid, secs, flags, ciaddr, yiaddr, siaddr, giaddr, chaddr, sname, file, opts); // throws [211]\n\n// after\nIPAddress ciaddr = IPAddress.Parse(\"192.168.1.10\"); // IPv4\nvar msg = new DhcpMessage(op, htype, xid, secs, flags, ciaddr, yiaddr, siaddr, giaddr, chaddr, sname, file, opts);","handlingStrategy":"validation","validationCode":"static IPAddress RequireIPv4(IPAddress addr, string name)\n{\n    if (addr is null) throw new ArgumentNullException(name);\n    if (addr.AddressFamily != AddressFamily.InterNetwork)\n        throw new ArgumentException(\"Address must be IPv4 for DHCPv4.\", name);\n    return addr;\n}\n\nRequireIPv4(ciaddr, nameof(ciaddr));\nvar msg = new DhcpMessage(op, htype, xid, secs, flags, ciaddr, yiaddr, siaddr, giaddr, chaddr, sname, file, opts);","typeGuard":"static bool IsIPv4(IPAddress addr) =>\n    addr is not null && addr.AddressFamily == AddressFamily.InterNetwork;","tryCatchPattern":null,"preventionTips":["Build DHCPv4 messages only with IPv4 addresses.","When resolving names, force AddressFamily.InterNetwork.","Keep DHCPv4 and DHCPv6 code paths separate."],"tags":["dhcp","validation","constructor","ipv4","address-family"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}