txthinking/brook · error
This is ipv6
Error message
This is ipv6
What it means
Resolve4 refuses to resolve hosts that are already literal IPv6 addresses. After net.ParseIP(host), if the address has a 16-byte (To16) representation but no 4-byte one, the library returns this error instead of attempting a DNS query, since an A lookup is meaningless for an IPv6 literal.
Source
Thrown at resolve.go:36
m.SetQuestion(host+".", dns.TypeAAAA)
r, err := dns.Exchange(m, "[2001:4860:4860::8888]:53")
if err != nil {
return "", err
}
for _, v := range r.Answer {
if t, ok := v.(*dns.AAAA); ok {
return t.AAAA.String(), nil
}
}
return "", errors.New("Can not find IP")
}
func Resolve4(host string) (string, error) {
if net.ParseIP(host).To4() != nil {
return host, nil
}
if net.ParseIP(host).To16() != nil {
return "", errors.New("This is ipv6")
}
m := &dns.Msg{}
m.SetQuestion(host+".", dns.TypeA)
r, err := dns.Exchange(m, "8.8.8.8:53")
if err != nil {
return "", err
}
for _, v := range r.Answer {
if t, ok := v.(*dns.A); ok {
return t.A.String(), nil
}
}
return "", errors.New("Can not find IP")
}
View on GitHub (pinned to 5cd13ef3b1)
Solutions
- Check the address family first: if net.ParseIP(host) != nil && net.ParseIP(host).To4() == nil, call Resolve6(host) instead.
- If IPv4 is mandatory, reject or normalize the input up front and surface a clear 'IPv4 required' validation error to the user.
- Use a family-agnostic wrapper that parses the IP once and dispatches to Resolve4/Resolve6.
Example fix
// before
ip, err := Resolve4(host) // fails with "This is ipv6"
// after
if ip := net.ParseIP(host); ip != nil && ip.To4() == nil {
return Resolve6(host)
}
return Resolve4(host) Defensive patterns
Strategy: validation
Validate before calling
ip := net.ParseIP(host)
if ip != nil && ip.To4() == nil {
// it's IPv6 — route to Resolve6 instead
} Type guard
func isIPv4Literal(s string) bool {
ip := net.ParseIP(s)
return ip != nil && ip.To4() != nil
} Try / catch
ip, err := Resolve4(host)
if err != nil && strings.Contains(err.Error(), "ipv6") {
return Resolve6(host)
} Prevention
- Parse IPs once up front and dispatch by address family.
- Validate user-supplied host/address inputs before choosing a resolver.
- Make dual-stack wrappers the default entry point instead of Resolve4/Resolve6 directly.
When it happens
Trigger: Calling Resolve4("2001:db8::1") or any IPv6 literal string. ParseIP succeeds, To4() is nil, To16() is non-nil, so the guard fires before any DNS traffic.
Common situations: Config or user input supplying an IPv6 address to an IPv4-only resolver; dual-stack code paths that pick Resolve4 without checking address family; reading addresses from URLs/host headers that may be v6.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
AI-assisted analysis of txthinking/brook@5cd13ef3b1 (2026-09-06).
Data as JSON: /api/errors/dd24c420c344f595.
Report an issue: GitHub.