Commit 40d85fb0 authored by Nigel Tao's avatar Nigel Tao

net: add a LookupTXT function.

This CL only supports Unix, not Plan 9 or Windows.

R=rsc
CC=golang-dev
https://golang.org/cl/4996048
parent cd269b0c
......@@ -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) {
......
......@@ -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")
......
......@@ -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) {
......
......@@ -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 {
......
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