summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNigel Tao <nigeltao@golang.org>2011-09-13 13:05:33 +1000
committerNigel Tao <nigeltao@golang.org>2011-09-13 13:05:33 +1000
commit855eb671dafeaf7474e33dc0f6c62a22ec34c773 (patch)
treedde2c8b55e4761ddad2a013d0478d445753ada73
parent86a485fed27be5a3236bd768bc9c0254a6104612 (diff)
downloadgo-855eb671dafeaf7474e33dc0f6c62a22ec34c773.tar.gz
net: add a LookupTXT function.
This CL only supports Unix, not Plan 9 or Windows. R=rsc CC=golang-dev http://codereview.appspot.com/4996048
-rw-r--r--src/pkg/net/lookup_plan9.go5
-rw-r--r--src/pkg/net/lookup_test.go18
-rw-r--r--src/pkg/net/lookup_unix.go21
-rw-r--r--src/pkg/net/lookup_windows.go4
4 files changed, 44 insertions, 4 deletions
diff --git a/src/pkg/net/lookup_plan9.go b/src/pkg/net/lookup_plan9.go
index 37d6b8e31..ee0c9e879 100644
--- a/src/pkg/net/lookup_plan9.go
+++ b/src/pkg/net/lookup_plan9.go
@@ -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) {
diff --git a/src/pkg/net/lookup_test.go b/src/pkg/net/lookup_test.go
index 995ab03d0..41066fe48 100644
--- a/src/pkg/net/lookup_test.go
+++ b/src/pkg/net/lookup_test.go
@@ -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")
diff --git a/src/pkg/net/lookup_unix.go b/src/pkg/net/lookup_unix.go
index 8f5e66212..309f14ec3 100644
--- a/src/pkg/net/lookup_unix.go
+++ b/src/pkg/net/lookup_unix.go
@@ -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) {
diff --git a/src/pkg/net/lookup_windows.go b/src/pkg/net/lookup_windows.go
index fa3ad7c7f..b33c7f949 100644
--- a/src/pkg/net/lookup_windows.go
+++ b/src/pkg/net/lookup_windows.go
@@ -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 {