mirror of
https://github.com/golang/go
synced 2024-11-20 03:54:40 -07:00
net: implement LookupTXT for windows
R=rsc CC=golang-dev https://golang.org/cl/5318056
This commit is contained in:
parent
4d3c999086
commit
b43cf81c8c
@ -52,10 +52,6 @@ func TestGmailMX(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGmailTXT(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Logf("LookupTXT is not implemented on Windows")
|
||||
return
|
||||
}
|
||||
if testing.Short() || avoidMacFirewall {
|
||||
t.Logf("skipping test to avoid external network")
|
||||
return
|
||||
|
@ -5,7 +5,6 @@
|
||||
package net
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
"os"
|
||||
@ -81,7 +80,7 @@ func LookupPort(network, service string) (port int, err error) {
|
||||
func LookupCNAME(name string) (cname string, err error) {
|
||||
var r *syscall.DNSRecord
|
||||
e := syscall.DnsQuery(name, syscall.DNS_TYPE_CNAME, 0, nil, &r, nil)
|
||||
if int(e) != 0 {
|
||||
if e != 0 {
|
||||
return "", os.NewSyscallError("LookupCNAME", int(e))
|
||||
}
|
||||
defer syscall.DnsRecordListFree(r, 1)
|
||||
@ -110,7 +109,7 @@ func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err err
|
||||
}
|
||||
var r *syscall.DNSRecord
|
||||
e := syscall.DnsQuery(target, syscall.DNS_TYPE_SRV, 0, nil, &r, nil)
|
||||
if int(e) != 0 {
|
||||
if e != 0 {
|
||||
return "", nil, os.NewSyscallError("LookupSRV", int(e))
|
||||
}
|
||||
defer syscall.DnsRecordListFree(r, 1)
|
||||
@ -126,7 +125,7 @@ func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err err
|
||||
func LookupMX(name string) (mx []*MX, err error) {
|
||||
var r *syscall.DNSRecord
|
||||
e := syscall.DnsQuery(name, syscall.DNS_TYPE_MX, 0, nil, &r, nil)
|
||||
if int(e) != 0 {
|
||||
if e != 0 {
|
||||
return nil, os.NewSyscallError("LookupMX", int(e))
|
||||
}
|
||||
defer syscall.DnsRecordListFree(r, 1)
|
||||
@ -140,7 +139,21 @@ func LookupMX(name string) (mx []*MX, err error) {
|
||||
}
|
||||
|
||||
func LookupTXT(name string) (txt []string, err error) {
|
||||
return nil, errors.New("net.LookupTXT is not implemented on Windows")
|
||||
var r *syscall.DNSRecord
|
||||
e := syscall.DnsQuery(name, syscall.DNS_TYPE_TEXT, 0, nil, &r, nil)
|
||||
if e != 0 {
|
||||
return nil, os.NewSyscallError("LookupTXT", int(e))
|
||||
}
|
||||
defer syscall.DnsRecordListFree(r, 1)
|
||||
txt = make([]string, 0, 10)
|
||||
if r != nil && r.Type == syscall.DNS_TYPE_TEXT {
|
||||
d := (*syscall.DNSTXTData)(unsafe.Pointer(&r.Data[0]))
|
||||
for _, v := range (*[1 << 10]*uint16)(unsafe.Pointer(&(d.StringArray[0])))[:d.StringCount] {
|
||||
s := syscall.UTF16ToString((*[1 << 20]uint16)(unsafe.Pointer(v))[:])
|
||||
txt = append(txt, s)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func LookupAddr(addr string) (name []string, err error) {
|
||||
@ -150,7 +163,7 @@ func LookupAddr(addr string) (name []string, err error) {
|
||||
}
|
||||
var r *syscall.DNSRecord
|
||||
e := syscall.DnsQuery(arpa, syscall.DNS_TYPE_PTR, 0, nil, &r, nil)
|
||||
if int(e) != 0 {
|
||||
if e != 0 {
|
||||
return nil, os.NewSyscallError("LookupAddr", int(e))
|
||||
}
|
||||
defer syscall.DnsRecordListFree(r, 1)
|
||||
|
@ -530,6 +530,11 @@ type DNSMXData struct {
|
||||
Pad uint16
|
||||
}
|
||||
|
||||
type DNSTXTData struct {
|
||||
StringCount uint16
|
||||
StringArray [1]*uint16
|
||||
}
|
||||
|
||||
type DNSRecord struct {
|
||||
Next *DNSRecord
|
||||
Name *uint16
|
||||
|
Loading…
Reference in New Issue
Block a user