Skip to content
Browse files

fix v6 ip presentation.

Also fix the parsing from /etc/resolv.conf and make it simpler
in the process.
  • Loading branch information...
1 parent 9159265 commit ba40d60ce77a3f3d67945211f530ea96560b0add @miekg committed Oct 12, 2012
Showing with 21 additions and 17 deletions.
  1. +1 −3 TODO.markdown
  2. +7 −11 clientconfig.go
  3. +13 −3 ex/q/q.go
View
4 TODO.markdown
@@ -1,7 +1,5 @@
# TODO
-* 'q' standardize ipv6 input with [::1]#53 ?
-* make example from chaos
* Support for on-the-fly-signing
* (Re)sign zonefiles
* TLSA support
@@ -11,6 +9,6 @@
## 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
* privatekey.Precompute() when signing?
View
18 clientconfig.go
@@ -32,7 +32,7 @@ func ClientConfigFromFile(conf string) (*ClientConfig, error) {
}
c := new(ClientConfig)
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.Port = "53"
c.Ndots = 1
@@ -45,21 +45,17 @@ func ClientConfigFromFile(conf string) (*ClientConfig, error) {
}
switch f[0] {
case "nameserver": // add one name server
- a := c.Servers
- n := len(a)
- if len(f) > 1 && n < cap(a) {
+ if len(f) > 1 {
// One more check: make sure server name is
// just an IP address. Otherwise we need DNS
// to look it up.
name := f[1]
- switch len(net.ParseIP(name)) {
- case 16:
+ switch x := net.ParseIP(name); true {
+ case x.To4() != nil:
+ c.Servers = append(c.Servers, name)
+ case x.To16() != nil:
name = "[" + name + "]"
- fallthrough
- case 4:
- a = a[0 : n+1]
- a[n] = name
- c.Servers = a
+ c.Servers = append(c.Servers, name)
}
}
View
16 ex/q/q.go
@@ -105,9 +105,19 @@ Flags:
qtype = dns.TypeA
}
- nameserver = dns.Fqdn(string([]byte(nameserver)[1:])) // chop off @
- nameserver += ":" + strconv.Itoa(*port)
-
+ 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)
+ 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.
c := new(dns.Client)
if *tcp {

0 comments on commit ba40d60

Please sign in to comment.
Something went wrong with that request. Please try again.