Skip to content

Commit 88c63d6

Browse files
Ma27mr-karan
authored andcommitted
Support literal IPv6 nameservers
This effectively means that `doggo @2001:DB8::53 example.org` works just like we know it from `dig(1)`. This already works for IPv4 because `url.Parse` accepts a literal IPv4 address, but not a literal IPv6 address (due to parsing ambiguities with strings that look like an IPv4 address I guess). This is implemented by checking if the nameserver argument is a valid IP if the URL validation failed. If that's the case, `ns` is returned directly with the `[2001:DB8::53]:53` as address (from `net.JoinHostPort` with the default DNS port) and UDP as protocol (also the default if not specified).
1 parent c21f90c commit 88c63d6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

internal/app/nameservers.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ func initNameserver(n string) (models.Nameserver, error) {
6161
}
6262
u, err := url.Parse(n)
6363
if err != nil {
64-
return ns, err
64+
ip := net.ParseIP(n)
65+
if ip == nil {
66+
return ns, err
67+
}
68+
return ns, nil
6569
}
6670
switch u.Scheme {
6771
case "sdns":

0 commit comments

Comments
 (0)