From: David du Colombier <0intro@gmail.com> Date: Thu, 8 Oct 2015 20:33:38 +0000 (+0200) Subject: net: return rooted DNS names on Plan 9 X-Git-Tag: go1.6beta1~206 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=cd294636c846860e4bb792e62c30b516ef6676ec;p=gostls13.git net: return rooted DNS names on Plan 9 This change returns rooted DNS names on Plan 9, for consistency with other operating systems. Updates #12193. Change-Id: If983920c5b9a8f67d4ccb51bb295fac8dfb87e88 Reviewed-on: https://go-review.googlesource.com/15581 Reviewed-by: Brad Fitzpatrick Run-TryBot: David du Colombier <0intro@gmail.com> TryBot-Result: Gobot Gobot Reviewed-by: Mikio Hara --- diff --git a/src/net/lookup_plan9.go b/src/net/lookup_plan9.go index c6274640bb..56846bcdbd 100644 --- a/src/net/lookup_plan9.go +++ b/src/net/lookup_plan9.go @@ -190,6 +190,17 @@ func lookupPort(network, service string) (port int, err error) { return 0, unknownPortError } +// ensureEndDot adds '.' at the end of name unless it is already there. +func ensureEndDot(name string) string { + if name == "" { + return "." + } + if name[len(name)-1] == '.' { + return name + } + return name + "." +} + func lookupCNAME(name string) (cname string, err error) { lines, err := queryDNS(name, "cname") if err != nil { @@ -225,8 +236,8 @@ func lookupSRV(service, proto, name string) (cname string, addrs []*SRV, err err if !(portOk && priorityOk && weightOk) { continue } - addrs = append(addrs, &SRV{f[5], uint16(port), uint16(priority), uint16(weight)}) - cname = f[0] + addrs = append(addrs, &SRV{ensureEndDot(f[5]), uint16(port), uint16(priority), uint16(weight)}) + cname = ensureEndDot(f[0]) } byPriorityWeight(addrs).sort() return @@ -243,7 +254,7 @@ func lookupMX(name string) (mx []*MX, err error) { continue } if pref, _, ok := dtoi(f[2], 0); ok { - mx = append(mx, &MX{f[3], uint16(pref)}) + mx = append(mx, &MX{ensureEndDot(f[3]), uint16(pref)}) } } byPref(mx).sort() @@ -260,7 +271,7 @@ func lookupNS(name string) (ns []*NS, err error) { if len(f) < 3 { continue } - ns = append(ns, &NS{f[2]}) + ns = append(ns, &NS{ensureEndDot(f[2])}) } return } @@ -272,7 +283,7 @@ func lookupTXT(name string) (txt []string, err error) { } for _, line := range lines { if i := byteIndex(line, '\t'); i >= 0 { - txt = append(txt, line[i+1:]) + txt = append(txt, ensureEndDot(line[i+1:])) } } return @@ -292,7 +303,7 @@ func lookupAddr(addr string) (name []string, err error) { if len(f) < 3 { continue } - name = append(name, f[2]) + name = append(name, ensureEndDot(f[2])) } return }