Commit cd294636 authored by David du Colombier's avatar David du Colombier Committed by Mikio Hara

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/15581Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: David du Colombier <0intro@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarMikio Hara <mikioh.mikioh@gmail.com>
parent 4bf81f49
......@@ -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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment