fix v6 ip presentation.

Also fix the parsing from /etc/resolv.conf and make it simpler
in the process.
This commit is contained in:
Miek Gieben 2012-10-12 10:53:38 +02:00
parent 9159265f01
commit ba40d60ce7
3 changed files with 21 additions and 17 deletions

View File

@ -1,7 +1,5 @@
# TODO # TODO
* 'q' standardize ipv6 input with [::1]#53 ?
* make example from chaos
* Support for on-the-fly-signing * Support for on-the-fly-signing
* (Re)sign zonefiles * (Re)sign zonefiles
* TLSA support * TLSA support
@ -11,6 +9,6 @@
## Nice to have ## Nice to have
* Speed, we can always go faster. A simple reflect server now hits 35/45K qps * Speed, we can always go faster. A simple reflect server now hits 45/50K qps
* go test; only works correct on my machine * go test; only works correct on my machine
* privatekey.Precompute() when signing? * privatekey.Precompute() when signing?

View File

@ -32,7 +32,7 @@ func ClientConfigFromFile(conf string) (*ClientConfig, error) {
} }
c := new(ClientConfig) c := new(ClientConfig)
b := bufio.NewReader(file) b := bufio.NewReader(file)
c.Servers = make([]string, 3)[0:0] // small, but the standard limit c.Servers = make([]string, 0)
c.Search = make([]string, 0) c.Search = make([]string, 0)
c.Port = "53" c.Port = "53"
c.Ndots = 1 c.Ndots = 1
@ -45,21 +45,17 @@ func ClientConfigFromFile(conf string) (*ClientConfig, error) {
} }
switch f[0] { switch f[0] {
case "nameserver": // add one name server case "nameserver": // add one name server
a := c.Servers if len(f) > 1 {
n := len(a)
if len(f) > 1 && n < cap(a) {
// One more check: make sure server name is // One more check: make sure server name is
// just an IP address. Otherwise we need DNS // just an IP address. Otherwise we need DNS
// to look it up. // to look it up.
name := f[1] name := f[1]
switch len(net.ParseIP(name)) { switch x := net.ParseIP(name); true {
case 16: case x.To4() != nil:
c.Servers = append(c.Servers, name)
case x.To16() != nil:
name = "[" + name + "]" name = "[" + name + "]"
fallthrough c.Servers = append(c.Servers, name)
case 4:
a = a[0 : n+1]
a[n] = name
c.Servers = a
} }
} }

View File

@ -105,9 +105,19 @@ Flags:
qtype = dns.TypeA qtype = dns.TypeA
} }
nameserver = dns.Fqdn(string([]byte(nameserver)[1:])) // chop off @ nameserver = string([]byte(nameserver)[1:]) // chop off @
if i := net.ParseIP(nameserver); i != nil {
switch {
case i.To4() != nil:
// it's a v4 address
nameserver += ":" + strconv.Itoa(*port) nameserver += ":" + strconv.Itoa(*port)
case i.To16() != nil:
// v6 address
nameserver = "[" + nameserver + "]:" + strconv.Itoa(*port)
}
} else {
nameserver = dns.Fqdn(nameserver) + ":" + strconv.Itoa(*port)
}
// We use the async query handling, just to show how it is to be used. // We use the async query handling, just to show how it is to be used.
c := new(dns.Client) c := new(dns.Client)
if *tcp { if *tcp {