{"record":{"id":"8547a889b1b49a48","repo":"jstedfast/MailKit","slug":"could-not-resolve-a-suitable-ipv4-address-for-host","errorCode":null,"errorMessage":"Could not resolve a suitable IPv4 address for '{host}'.","messagePattern":"Could not resolve a suitable IPv4 address for '(.+?)'\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Proxy/Socks4Client.cs","lineNumber":140,"sourceCode":"\n\t\tstatic string GetFailureReason (byte reply)\n\t\t{\n\t\t\tswitch ((Socks4Reply) reply) {\n\t\t\tcase Socks4Reply.RequestRejected:       return \"Request rejected or failed.\";\n\t\t\tcase Socks4Reply.RequestFailedNoIdentd: return \"Request failed; unable to contact client machine's identd service.\";\n\t\t\tcase Socks4Reply.RequestFailedWrongId:  return \"Request failed; client ID does not match specified username.\";\n\t\t\tdefault:                                return \"Unknown error.\";\n\t\t\t}\n\t\t}\n\n\t\tstatic IPAddress Resolve (string host, IPAddress[] ipAddresses)\n\t\t{\n\t\t\tfor (int i = 0; i < ipAddresses.Length; i++) {\n\t\t\t\tif (ipAddresses[i].AddressFamily == AddressFamily.InterNetwork)\n\t\t\t\t\treturn ipAddresses[i];\n\t\t\t}\n\n\t\t\tthrow new ArgumentException ($\"Could not resolve a suitable IPv4 address for '{host}'.\", nameof (host));\n\t\t}\n\n\t\tstatic IPAddress Resolve (string host, CancellationToken cancellationToken)\n\t\t{\n\t\t\tcancellationToken.ThrowIfCancellationRequested ();\n\n\t\t\tvar ipAddresses = Dns.GetHostAddresses (host);\n\n\t\t\treturn Resolve (host, ipAddresses);\n\t\t}\n\n\t\tstatic async Task<IPAddress> ResolveAsync (string host, CancellationToken cancellationToken)\n\t\t{\n\t\t\tcancellationToken.ThrowIfCancellationRequested ();\n\n#if NET6_0_OR_GREATER\n\t\t\tvar ipAddresses = await Dns.GetHostAddressesAsync (host, cancellationToken).ConfigureAwait (false);\n#else","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Proxy/Socks4Client.cs#L122-L158","documentation":"SOCKS4 only supports IPv4. Socks4Client.Resolve performs DNS resolution of the proxy (or target) host and throws ArgumentException('Could not resolve a suitable IPv4 address for ...') if none of the resolved addresses has AddressFamily InterNetwork — e.g. the host only resolves to IPv6 (AAAA) addresses.","triggerScenarios":"Using Socks4Client with a host name that resolves exclusively to IPv6 addresses (dual-stack disabled for IPv4 or DNS returning only AAAA records).","commonSituations":"IPv6-only or heavily IPv6-preferring networks; internal DNS entries created as AAAA-only; 'localhost' resolving to ::1 first with no IPv4 mapping in some configurations; container/VM images without IPv4 DNS records.","solutions":["Use Socks5Client, which supports IPv6, instead of Socks4Client.","Pass the proxy host as an IPv4 literal (e.g. 192.0.2.10) to bypass DNS.","Fix DNS so an A record exists for the host, or use a different resolver.","Check with `nslookup host` / `dig A host` that an IPv4 A record exists.","Enable IPv4 (dual-stack) on the machine or network if it is disabled."],"exampleFix":"// before\nvar proxy = new Socks4Client(\"proxy.internal\", 1080); // only AAAA records -> throws\n// after\nvar proxy = new Socks5Client(\"proxy.internal\", 1080); // SOCKS5 handles IPv6","handlingStrategy":"validation","validationCode":"var addrs = Dns.GetHostAddresses(host);\nif (!addrs.Any(a => a.AddressFamily == AddressFamily.InterNetwork))\n    throw new InvalidOperationException($\"{host} has no IPv4 (A) record; SOCKS4 cannot be used\");","typeGuard":"bool HasIPv4(string host) =>\n    Dns.GetHostAddresses(host).Any(a => a.AddressFamily == AddressFamily.InterNetwork);","tryCatchPattern":"try {\n    proxy.Connect(targetEp, cancellationToken);\n} catch (ArgumentException ex) when (ex.Message.Contains(\"suitable IPv4 address\")) {\n    // switch to Socks5Client or an IPv4 literal\n}","preventionTips":["Prefer Socks5Client unless SOCKS4 is explicitly required","Verify the proxy host has a DNS A record (dig/nslookup)","Pass IPv4 literals in IPv6-only environments"],"tags":["socks4","dns","ipv4","proxy","mailkit"],"backgroundTag":"resource-not-found","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}