Skip to content

Commit

Permalink
fix: set ndots correctly
Browse files Browse the repository at this point in the history
fixes #13
  • Loading branch information
mr-karan committed Feb 15, 2021
1 parent bec7a7f commit a8769e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/doggo/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func main() {
// Resolver Options
f.Int("timeout", 5, "Sets the timeout for a query to T seconds. The default timeout is 5 seconds.")
f.Bool("search", true, "Use the search list provided in resolv.conf. It sets the `ndots` parameter as well unless overridden by `ndots` flag.")
f.Int("ndots", 0, "Specify the ndots parameter. Default value is taken from resolv.conf and fallbacks to 1 if ndots statement is missing in resolv.conf")
f.Int("ndots", -1, "Specify the ndots parameter. Default value is taken from resolv.conf and fallbacks to 1 if ndots statement is missing in resolv.conf")
f.BoolP("ipv4", "4", false, "Use IPv4 only")
f.BoolP("ipv6", "6", false, "Use IPv6 only")

Expand Down
12 changes: 10 additions & 2 deletions cmd/doggo/nameservers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,30 @@ func (hub *Hub) loadNameservers() error {
}
}

// Set `ndots` to the user specified value.
hub.ResolverOpts.Ndots = hub.QueryFlags.Ndots
// fallback to system nameserver
// in case no nameserver is specified by user.
if len(hub.Nameservers) == 0 {
ns, ndots, search, err := getDefaultServers()
if err != nil {
return fmt.Errorf("error fetching system default nameserver")
}
// override if user hasn't specified any value.
if hub.QueryFlags.Ndots == 0 {
// `-1` indicates the flag is not set.
// use from config if user hasn't specified any value.
if hub.ResolverOpts.Ndots == -1 {
hub.ResolverOpts.Ndots = ndots
}
if len(search) > 0 && hub.QueryFlags.UseSearchList {
hub.ResolverOpts.SearchList = search
}
hub.Nameservers = append(hub.Nameservers, ns...)
}
// if the user hasn't given any override of `ndots` AND has
// given a custom nameserver. Set `ndots` to 1 as the fallback value
if hub.ResolverOpts.Ndots == -1 {
hub.ResolverOpts.Ndots = 1
}
return nil
}

Expand Down

0 comments on commit a8769e1

Please sign in to comment.