chore: Fix UDP Port parsing

pull/2/head
Karan Sharma 2020-12-11 16:05:16 +05:30
parent 13cf2caaee
commit a57814688c
3 changed files with 12 additions and 2 deletions

View File

@ -20,6 +20,8 @@
- [x] Neatly package them to load args in different functions
- [x] Upper case is not mandatory for query type/classes
- [ ] Output
- [ ] Add client transport options
## Tests
## Documentation

View File

@ -32,7 +32,7 @@ func (hub *Hub) loadQueryArgs(c *cli.Context) error {
func (hub *Hub) parseFreeArgs(c *cli.Context) error {
for _, arg := range c.Args().Slice() {
if strings.HasPrefix(arg, "@") {
hub.QueryFlags.Nameservers.Set(arg)
hub.QueryFlags.Nameservers.Set(strings.Trim(arg, "@"))
} else if _, ok := dns.StringToType[strings.ToUpper(arg)]; ok {
hub.QueryFlags.QTypes.Set(arg)
} else if _, ok := dns.StringToClass[strings.ToUpper(arg)]; ok {

View File

@ -19,9 +19,17 @@ const DefaultResolvConfPath = "/etc/resolv.conf"
// NewResolver accepts a list of nameservers and configures a DNS resolver.
func NewResolver(servers []string) *Resolver {
client := &dns.Client{}
var nameservers []string
for _, srv := range servers {
if i := net.ParseIP(srv); i != nil {
nameservers = append(nameservers, net.JoinHostPort(srv, "53"))
} else {
nameservers = append(nameservers, dns.Fqdn(srv)+":"+"53")
}
}
return &Resolver{
client: client,
servers: servers,
servers: nameservers,
}
}