]> Cypherpunks repositories - gostls13.git/commitdiff
net: add a LookupTXT function.
authorNigel Tao <nigeltao@golang.org>
Tue, 13 Sep 2011 03:05:33 +0000 (13:05 +1000)
committerNigel Tao <nigeltao@golang.org>
Tue, 13 Sep 2011 03:05:33 +0000 (13:05 +1000)
This CL only supports Unix, not Plan 9 or Windows.

R=rsc
CC=golang-dev
https://golang.org/cl/4996048

src/pkg/net/lookup_plan9.go
src/pkg/net/lookup_test.go
src/pkg/net/lookup_unix.go
src/pkg/net/lookup_windows.go

index 37d6b8e315a8450d9c4e4196250fbcad167c7240..ee0c9e879eccd56d66efc404b2d030215f1a702d 100644 (file)
@@ -204,6 +204,11 @@ func LookupMX(name string) (mx []*MX, err os.Error) {
        return
 }
 
+// LookupTXT returns the DNS TXT records for the given domain name.
+func LookupTXT(name string) (txt []string, err os.Error) {
+       return nil, os.NewError("net.LookupTXT is not implemented on Plan 9")
+}
+
 // LookupAddr performs a reverse lookup for the given address, returning a list
 // of names mapping to that address.
 func LookupAddr(addr string) (name []string, err os.Error) {
index 995ab03d090d5bf9394349d1877f1b134691b0df..41066fe48091b4ad56b23f003551bfde199f9b0b 100644 (file)
@@ -42,6 +42,24 @@ func TestGmailMX(t *testing.T) {
        }
 }
 
+func TestGmailTXT(t *testing.T) {
+       if runtime.GOOS == "windows" || runtime.GOOS == "plan9" {
+               t.Logf("LookupTXT is not implemented on Windows or Plan 9")
+               return
+       }
+       if testing.Short() || avoidMacFirewall {
+               t.Logf("skipping test to avoid external network")
+               return
+       }
+       txt, err := LookupTXT("gmail.com")
+       if err != nil {
+               t.Errorf("failed: %s", err)
+       }
+       if len(txt) == 0 || len(txt[0]) == 0 {
+               t.Errorf("no results")
+       }
+}
+
 func TestGoogleDNSAddr(t *testing.T) {
        if testing.Short() || avoidMacFirewall {
                t.Logf("skipping test to avoid external network")
index 8f5e66212b3007c0cc8247b81e5ed069590ece81..309f14ec300379af36544a6a18eaf2463fe3b045 100644 (file)
@@ -72,19 +72,32 @@ func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err os.
 
 // LookupMX returns the DNS MX records for the given domain name sorted by preference.
 func LookupMX(name string) (mx []*MX, err os.Error) {
-       _, rr, err := lookup(name, dnsTypeMX)
+       _, records, err := lookup(name, dnsTypeMX)
        if err != nil {
                return
        }
-       mx = make([]*MX, len(rr))
-       for i := range rr {
-               r := rr[i].(*dnsRR_MX)
+       mx = make([]*MX, len(records))
+       for i, rr := range records {
+               r := rr.(*dnsRR_MX)
                mx[i] = &MX{r.Mx, r.Pref}
        }
        byPref(mx).sort()
        return
 }
 
+// LookupTXT returns the DNS TXT records for the given domain name.
+func LookupTXT(name string) (txt []string, err os.Error) {
+       _, records, err := lookup(name, dnsTypeTXT)
+       if err != nil {
+               return
+       }
+       txt = make([]string, len(records))
+       for i, r := range records {
+               txt[i] = r.(*dnsRR_TXT).Txt
+       }
+       return
+}
+
 // LookupAddr performs a reverse lookup for the given address, returning a list
 // of names mapping to that address.
 func LookupAddr(addr string) (name []string, err os.Error) {
index fa3ad7c7f42b9949eccd688cbfac5ed9a7ee8315..b33c7f949e0ed2e0e2c7dc942f22be209e82af8f 100644 (file)
@@ -110,6 +110,10 @@ func LookupMX(name string) (mx []*MX, err os.Error) {
        return mx, nil
 }
 
+func LookupTXT(name string) (txt []string, err os.Error) {
+       return nil, os.NewError("net.LookupTXT is not implemented on Windows")
+}
+
 func LookupAddr(addr string) (name []string, err os.Error) {
        arpa, err := reverseaddr(addr)
        if err != nil {