diff options
Diffstat (limited to 'libgo/go/net/lookup_windows.go')
-rw-r--r-- | libgo/go/net/lookup_windows.go | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/libgo/go/net/lookup_windows.go b/libgo/go/net/lookup_windows.go index 53cb8f468ad..61d8a8871e1 100644 --- a/libgo/go/net/lookup_windows.go +++ b/libgo/go/net/lookup_windows.go @@ -5,11 +5,10 @@ package net import ( - "errors" - "syscall" - "unsafe" "os" "sync" + "syscall" + "unsafe" ) var ( @@ -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) |