]> Cypherpunks repositories - gostls13.git/commitdiff
net: return rooted DNS names on Plan 9
authorDavid du Colombier <0intro@gmail.com>
Thu, 8 Oct 2015 20:33:38 +0000 (22:33 +0200)
committerMikio Hara <mikioh.mikioh@gmail.com>
Fri, 4 Dec 2015 01:47:18 +0000 (01:47 +0000)
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 <bradfitz@golang.org>
Run-TryBot: David du Colombier <0intro@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
src/net/lookup_plan9.go

index c6274640bb7d251434f093474a1f4c65661202a4..56846bcdbdf8308e2438ce26469a128fd5034f47 100644 (file)
@@ -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
 }