Skip to content

Commit

Permalink
fix: ndots options
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-karan committed Dec 13, 2020
1 parent 646829a commit 94b9c6b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
8 changes: 4 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Resolver
- [x] Create a DNS Resolver struct
- [x]] Add methods to initialise the config, set defaults
- [x] Add methods to initialise the config, set defaults
- [x] Add a resolve method
- [x] Make it separate from Hub
- [x] Parse output into separate fields
Expand All @@ -15,14 +15,12 @@
- [x] Major records supported

## CLI Features
- [ ] `digfile`
- [ ] `ndots` support
- [x] `ndots` support
- [x] `search list` support
- [x] JSON output
- [x] Colorized output
- [x] Table output
- [x] Parsing options free-form
- [x] Remove urfave/cli in favour of `flag`

## CLI Grunt
- [x] Query args
Expand All @@ -35,6 +33,7 @@
- [ ] Add different commands
- [x] Add client transport options
- [x] Fix an issue while loading free form args, where the same records are being added twice
- [x] Remove urfave/cli in favour of `pflag + koanf`

## Tests

Expand All @@ -53,3 +52,4 @@
## v1.0

- [ ] Support obscure protocal tweaks in `dig`
- [ ] `digfile`
3 changes: 2 additions & 1 deletion cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func main() {

// Resolver Options
f.Bool("search", false, "Use the search list provided in resolv.conf. It sets the `ndots` parameter as well unless overriden by `ndots` flag.")
f.Int("ndots", 1, "Specify the ndots paramter")
f.Int("ndots", 1, "Specify the ndots paramter. Default value is taken from resolv.conf and fallbacks to 1 if ndots statement is missing in resolv.conf")

// Output Options
f.BoolP("json", "J", false, "Set the output format as JSON")
Expand All @@ -67,6 +67,7 @@ func main() {
} else {
hub.Logger.SetLevel(logrus.InfoLevel)
}

// Run the app.
hub.Logger.Debug("Starting doggo 🐶")

Expand Down
14 changes: 8 additions & 6 deletions cmd/lookup.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"strings"

"github.com/miekg/dns"
Expand Down Expand Up @@ -34,12 +35,11 @@ func (hub *Hub) prepareQuestions() error {
domains []string
ndots int
)
ndots = 1

ndots = hub.QueryFlags.Ndots
// If `search` flag is specified then fetch the search list
// from `resolv.conf` and set the
if hub.QueryFlags.UseSearchList {
list, n, err := fetchDomainList(name, false, hub.QueryFlags.Ndots)
list, n, err := fetchDomainList(name, ndots)
if err != nil {
return err
}
Expand Down Expand Up @@ -69,13 +69,15 @@ func (hub *Hub) prepareQuestions() error {
return nil
}

func fetchDomainList(d string, isNdotsSet bool, ndots int) ([]string, int, error) {
func fetchDomainList(d string, ndots int) ([]string, int, error) {
fmt.Println(ndots)
cfg, err := dns.ClientConfigFromFile(resolvers.DefaultResolvConfPath)
if err != nil {
return nil, 0, err
}
// if user specified a custom ndots parameter, override it
if isNdotsSet {
// if it's the default value
if cfg.Ndots == 1 {
// override what the user gave. If the user didn't give any setting then it's 1 by default.
cfg.Ndots = ndots
}
return cfg.NameList(d), cfg.Ndots, nil
Expand Down
1 change: 1 addition & 0 deletions cmd/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func (hub *Hub) loadQueryArgs() error {
hub.Logger.WithError(err).Error("Error parsing nameservers")
hub.Logger.Exit(2)
}

hub.loadFallbacks()
return err
}
Expand Down

0 comments on commit 94b9c6b

Please sign in to comment.