func (*Resolver) lookupSRV(ctx context.Context, service, proto, name string) (string, []*SRV, error) { // TODO(bradfitz): finish ctx plumbing. Nothing currently depends on this. acquireThread() defer releaseThread() var target string if service == "" && proto == "" { target = name } else { target = "_" + service + "._" + proto + "." + name } var r *syscall.DNSRecord e := syscall.DnsQuery(target, syscall.DNS_TYPE_SRV, 0, nil, &r, nil) if e != nil { return "", nil, &DNSError{Err: winError("dnsquery", e).Error(), Name: target} } defer syscall.DnsRecordListFree(r, 1) srvs := make([]*SRV, 0, 10) for _, p := range validRecs(r, syscall.DNS_TYPE_SRV, target) { v := (*syscall.DNSSRVData)(unsafe.Pointer(&p.Data[0])) srvs = append(srvs, &SRV{absDomainName([]byte(syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(v.Target))[:]))), v.Port, v.Priority, v.Weight}) } byPriorityWeight(srvs).sort() return absDomainName([]byte(target)), srvs, nil }
func LookupCNAME(name string) (cname string, err os.Error) { var r *syscall.DNSRecord e := syscall.DnsQuery(name, syscall.DNS_TYPE_CNAME, 0, nil, &r, nil) if int(e) != 0 { return "", os.NewSyscallError("LookupCNAME", int(e)) } defer syscall.DnsRecordListFree(r, 1) if r != nil && r.Type == syscall.DNS_TYPE_CNAME { v := (*syscall.DNSPTRData)(unsafe.Pointer(&r.Data[0])) cname = syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(v.Host))[:]) + "." } return }
func lookupNS(name string) (ns []*NS, err error) { var r *syscall.DNSRecord e := syscall.DnsQuery(name, syscall.DNS_TYPE_NS, 0, nil, &r, nil) if e != nil { return nil, os.NewSyscallError("LookupNS", e) } defer syscall.DnsRecordListFree(r, 1) ns = make([]*NS, 0, 10) for p := r; p != nil && p.Type == syscall.DNS_TYPE_NS; p = p.Next { v := (*syscall.DNSPTRData)(unsafe.Pointer(&p.Data[0])) ns = append(ns, &NS{syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(v.Host))[:]) + "."}) } return ns, nil }
func LookupMX(name string) (mx []*MX, err os.Error) { var r *syscall.DNSRecord e := syscall.DnsQuery(name, syscall.DNS_TYPE_MX, 0, nil, &r, nil) if int(e) != 0 { return nil, os.NewSyscallError("LookupMX", int(e)) } defer syscall.DnsRecordListFree(r, 1) mx = make([]*MX, 0, 10) for p := r; p != nil && p.Type == syscall.DNS_TYPE_MX; p = p.Next { v := (*syscall.DNSMXData)(unsafe.Pointer(&p.Data[0])) mx = append(mx, &MX{syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(v.NameExchange))[:]) + ".", v.Preference}) } byPref(mx).sort() return mx, nil }
func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err os.Error) { var r *syscall.DNSRecord target := "_" + service + "._" + proto + "." + name e := syscall.DnsQuery(target, syscall.DNS_TYPE_SRV, 0, nil, &r, nil) if int(e) != 0 { return "", nil, os.NewSyscallError("LookupSRV", int(e)) } defer syscall.DnsRecordListFree(r, 1) addrs = make([]*SRV, 0, 10) for p := r; p != nil && p.Type == syscall.DNS_TYPE_SRV; p = p.Next { v := (*syscall.DNSSRVData)(unsafe.Pointer(&p.Data[0])) addrs = append(addrs, &SRV{syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(v.Target))[:]), v.Port, v.Priority, v.Weight}) } byPriorityWeight(addrs).sort() return name, addrs, nil }
func lookupNS(name string) ([]*NS, error) { acquireThread() defer releaseThread() var r *syscall.DNSRecord e := syscall.DnsQuery(name, syscall.DNS_TYPE_NS, 0, nil, &r, nil) if e != nil { return nil, &DNSError{Err: os.NewSyscallError("dnsquery", e).Error(), Name: name} } defer syscall.DnsRecordListFree(r, 1) nss := make([]*NS, 0, 10) for _, p := range validRecs(r, syscall.DNS_TYPE_NS, name) { v := (*syscall.DNSPTRData)(unsafe.Pointer(&p.Data[0])) nss = append(nss, &NS{ensureEndDot(syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(v.Host))[:]))}) } return nss, nil }
func lookupNS(name string) (ns []*NS, err error) { acquireThread() defer releaseThread() var r *syscall.DNSRecord e := syscall.DnsQuery(name, syscall.DNS_TYPE_NS, 0, nil, &r, nil) if e != nil { return nil, os.NewSyscallError("LookupNS", e) } defer syscall.DnsRecordListFree(r, 1) ns = make([]*NS, 0, 10) for _, p := range validRecs(r, syscall.DNS_TYPE_NS, name) { v := (*syscall.DNSPTRData)(unsafe.Pointer(&p.Data[0])) ns = append(ns, &NS{syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(v.Host))[:]) + "."}) } return ns, nil }
func lookupTXT(name string) (txt []string, err error) { var r *syscall.DNSRecord e := syscall.DnsQuery(name, syscall.DNS_TYPE_TEXT, 0, nil, &r, nil) if e != nil { return nil, os.NewSyscallError("LookupTXT", 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 (*Resolver) lookupNS(ctx context.Context, name string) ([]*NS, error) { // TODO(bradfitz): finish ctx plumbing. Nothing currently depends on this. acquireThread() defer releaseThread() var r *syscall.DNSRecord e := syscall.DnsQuery(name, syscall.DNS_TYPE_NS, 0, nil, &r, nil) if e != nil { return nil, &DNSError{Err: winError("dnsquery", e).Error(), Name: name} } defer syscall.DnsRecordListFree(r, 1) nss := make([]*NS, 0, 10) for _, p := range validRecs(r, syscall.DNS_TYPE_NS, name) { v := (*syscall.DNSPTRData)(unsafe.Pointer(&p.Data[0])) nss = append(nss, &NS{absDomainName([]byte(syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(v.Host))[:])))}) } return nss, nil }
func LookupAddr(addr string) (name []string, err os.Error) { arpa, err := reverseaddr(addr) if err != nil { return nil, err } var r *syscall.DNSRecord e := syscall.DnsQuery(arpa, syscall.DNS_TYPE_PTR, 0, nil, &r, nil) if int(e) != 0 { return nil, os.NewSyscallError("LookupAddr", int(e)) } defer syscall.DnsRecordListFree(r, 1) name = make([]string, 0, 10) for p := r; p != nil && p.Type == syscall.DNS_TYPE_PTR; p = p.Next { v := (*syscall.DNSPTRData)(unsafe.Pointer(&p.Data[0])) name = append(name, syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(v.Host))[:])) } return name, nil }
func lookupMX(name string) ([]*MX, error) { acquireThread() defer releaseThread() var r *syscall.DNSRecord e := syscall.DnsQuery(name, syscall.DNS_TYPE_MX, 0, nil, &r, nil) if e != nil { return nil, &DNSError{Err: os.NewSyscallError("dnsquery", e).Error(), Name: name} } defer syscall.DnsRecordListFree(r, 1) mxs := make([]*MX, 0, 10) for _, p := range validRecs(r, syscall.DNS_TYPE_MX, name) { v := (*syscall.DNSMXData)(unsafe.Pointer(&p.Data[0])) mxs = append(mxs, &MX{ensureEndDot(syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(v.NameExchange))[:])), v.Preference}) } byPref(mxs).sort() return mxs, nil }
func lookupMX(name string) (mx []*MX, err error) { acquireThread() defer releaseThread() var r *syscall.DNSRecord e := syscall.DnsQuery(name, syscall.DNS_TYPE_MX, 0, nil, &r, nil) if e != nil { return nil, os.NewSyscallError("LookupMX", e) } defer syscall.DnsRecordListFree(r, 1) mx = make([]*MX, 0, 10) for _, p := range validRecs(r, syscall.DNS_TYPE_MX, name) { v := (*syscall.DNSMXData)(unsafe.Pointer(&p.Data[0])) mx = append(mx, &MX{syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(v.NameExchange))[:]) + ".", v.Preference}) } byPref(mx).sort() return mx, nil }
func lookupCNAME(name string) (string, error) { acquireThread() defer releaseThread() var r *syscall.DNSRecord e := syscall.DnsQuery(name, syscall.DNS_TYPE_CNAME, 0, nil, &r, nil) // windows returns DNS_INFO_NO_RECORDS if there are no CNAME-s if errno, ok := e.(syscall.Errno); ok && errno == syscall.DNS_INFO_NO_RECORDS { // if there are no aliases, the canonical name is the input name return ensureEndDot(name), nil } if e != nil { return "", &DNSError{Err: os.NewSyscallError("dnsquery", e).Error(), Name: name} } defer syscall.DnsRecordListFree(r, 1) resolved := resolveCNAME(syscall.StringToUTF16Ptr(name), r) cname := syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(resolved))[:]) return ensureEndDot(cname), nil }
func (*Resolver) lookupMX(ctx context.Context, name string) ([]*MX, error) { // TODO(bradfitz): finish ctx plumbing. Nothing currently depends on this. acquireThread() defer releaseThread() var r *syscall.DNSRecord e := syscall.DnsQuery(name, syscall.DNS_TYPE_MX, 0, nil, &r, nil) if e != nil { return nil, &DNSError{Err: winError("dnsquery", e).Error(), Name: name} } defer syscall.DnsRecordListFree(r, 1) mxs := make([]*MX, 0, 10) for _, p := range validRecs(r, syscall.DNS_TYPE_MX, name) { v := (*syscall.DNSMXData)(unsafe.Pointer(&p.Data[0])) mxs = append(mxs, &MX{absDomainName([]byte(syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(v.NameExchange))[:]))), v.Preference}) } byPref(mxs).sort() return mxs, nil }
func (*Resolver) lookupCNAME(ctx context.Context, name string) (string, error) { // TODO(bradfitz): finish ctx plumbing. Nothing currently depends on this. acquireThread() defer releaseThread() var r *syscall.DNSRecord e := syscall.DnsQuery(name, syscall.DNS_TYPE_CNAME, 0, nil, &r, nil) // windows returns DNS_INFO_NO_RECORDS if there are no CNAME-s if errno, ok := e.(syscall.Errno); ok && errno == syscall.DNS_INFO_NO_RECORDS { // if there are no aliases, the canonical name is the input name return absDomainName([]byte(name)), nil } if e != nil { return "", &DNSError{Err: winError("dnsquery", e).Error(), Name: name} } defer syscall.DnsRecordListFree(r, 1) resolved := resolveCNAME(syscall.StringToUTF16Ptr(name), r) cname := syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(resolved))[:]) return absDomainName([]byte(cname)), nil }
func lookupTXT(name string) ([]string, error) { acquireThread() defer releaseThread() var r *syscall.DNSRecord e := syscall.DnsQuery(name, syscall.DNS_TYPE_TEXT, 0, nil, &r, nil) if e != nil { return nil, &DNSError{Err: os.NewSyscallError("dnsquery", e).Error(), Name: name} } defer syscall.DnsRecordListFree(r, 1) txts := make([]string, 0, 10) for _, p := range validRecs(r, syscall.DNS_TYPE_TEXT, name) { d := (*syscall.DNSTXTData)(unsafe.Pointer(&p.Data[0])) for _, v := range (*[1 << 10]*uint16)(unsafe.Pointer(&(d.StringArray[0])))[:d.StringCount] { s := syscall.UTF16ToString((*[1 << 20]uint16)(unsafe.Pointer(v))[:]) txts = append(txts, s) } } return txts, nil }
func lookupAddr(addr string) (name []string, err error) { acquireThread() defer releaseThread() arpa, err := reverseaddr(addr) if err != nil { return nil, err } var r *syscall.DNSRecord e := syscall.DnsQuery(arpa, syscall.DNS_TYPE_PTR, 0, nil, &r, nil) if e != nil { return nil, os.NewSyscallError("LookupAddr", e) } defer syscall.DnsRecordListFree(r, 1) name = make([]string, 0, 10) for _, p := range validRecs(r, syscall.DNS_TYPE_PTR, arpa) { v := (*syscall.DNSPTRData)(unsafe.Pointer(&p.Data[0])) name = append(name, syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(v.Host))[:])) } return name, nil }
func lookupAddr(addr string) ([]string, error) { acquireThread() defer releaseThread() arpa, err := reverseaddr(addr) if err != nil { return nil, err } var r *syscall.DNSRecord e := syscall.DnsQuery(arpa, syscall.DNS_TYPE_PTR, 0, nil, &r, nil) if e != nil { return nil, &DNSError{Err: os.NewSyscallError("dnsquery", e).Error(), Name: addr} } defer syscall.DnsRecordListFree(r, 1) ptrs := make([]string, 0, 10) for _, p := range validRecs(r, syscall.DNS_TYPE_PTR, arpa) { v := (*syscall.DNSPTRData)(unsafe.Pointer(&p.Data[0])) ptrs = append(ptrs, ensureEndDot(syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(v.Host))[:]))) } return ptrs, nil }
func (*Resolver) lookupTXT(ctx context.Context, name string) ([]string, error) { // TODO(bradfitz): finish ctx plumbing. Nothing currently depends on this. acquireThread() defer releaseThread() var r *syscall.DNSRecord e := syscall.DnsQuery(name, syscall.DNS_TYPE_TEXT, 0, nil, &r, nil) if e != nil { return nil, &DNSError{Err: winError("dnsquery", e).Error(), Name: name} } defer syscall.DnsRecordListFree(r, 1) txts := make([]string, 0, 10) for _, p := range validRecs(r, syscall.DNS_TYPE_TEXT, name) { d := (*syscall.DNSTXTData)(unsafe.Pointer(&p.Data[0])) for _, v := range (*[1 << 10]*uint16)(unsafe.Pointer(&(d.StringArray[0])))[:d.StringCount] { s := syscall.UTF16ToString((*[1 << 20]uint16)(unsafe.Pointer(v))[:]) txts = append(txts, s) } } return txts, nil }
func (*Resolver) lookupAddr(ctx context.Context, addr string) ([]string, error) { // TODO(bradfitz): finish ctx plumbing. Nothing currently depends on this. acquireThread() defer releaseThread() arpa, err := reverseaddr(addr) if err != nil { return nil, err } var r *syscall.DNSRecord e := syscall.DnsQuery(arpa, syscall.DNS_TYPE_PTR, 0, nil, &r, nil) if e != nil { return nil, &DNSError{Err: winError("dnsquery", e).Error(), Name: addr} } defer syscall.DnsRecordListFree(r, 1) ptrs := make([]string, 0, 10) for _, p := range validRecs(r, syscall.DNS_TYPE_PTR, arpa) { v := (*syscall.DNSPTRData)(unsafe.Pointer(&p.Data[0])) ptrs = append(ptrs, absDomainName([]byte(syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(v.Host))[:])))) } return ptrs, nil }
func lookupCNAME(name string) (cname string, err error) { acquireThread() defer releaseThread() var r *syscall.DNSRecord e := syscall.DnsQuery(name, syscall.DNS_TYPE_CNAME, 0, nil, &r, nil) // windows returns DNS_INFO_NO_RECORDS if there are no CNAME-s if errno, ok := e.(syscall.Errno); ok && errno == syscall.DNS_INFO_NO_RECORDS { // if there are no aliases, the canonical name is the input name if name == "" || name[len(name)-1] != '.' { return name + ".", nil } return name, nil } if e != nil { return "", os.NewSyscallError("LookupCNAME", e) } defer syscall.DnsRecordListFree(r, 1) resolved := resolveCNAME(syscall.StringToUTF16Ptr(name), r) cname = syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(resolved))[:]) + "." return }
func lookupSRV(service, proto, name string) (cname string, addrs []*SRV, err error) { acquireThread() defer releaseThread() var target string if service == "" && proto == "" { target = name } else { target = "_" + service + "._" + proto + "." + name } var r *syscall.DNSRecord e := syscall.DnsQuery(target, syscall.DNS_TYPE_SRV, 0, nil, &r, nil) if e != nil { return "", nil, os.NewSyscallError("LookupSRV", e) } defer syscall.DnsRecordListFree(r, 1) addrs = make([]*SRV, 0, 10) for p := r; p != nil && p.Type == syscall.DNS_TYPE_SRV; p = p.Next { v := (*syscall.DNSSRVData)(unsafe.Pointer(&p.Data[0])) addrs = append(addrs, &SRV{syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(v.Target))[:]), v.Port, v.Priority, v.Weight}) } byPriorityWeight(addrs).sort() return name, addrs, nil }
func lookupSRV(service, proto, name string) (string, []*SRV, error) { acquireThread() defer releaseThread() var target string if service == "" && proto == "" { target = name } else { target = "_" + service + "._" + proto + "." + name } var r *syscall.DNSRecord e := syscall.DnsQuery(target, syscall.DNS_TYPE_SRV, 0, nil, &r, nil) if e != nil { return "", nil, &DNSError{Err: os.NewSyscallError("dnsquery", e).Error(), Name: target} } defer syscall.DnsRecordListFree(r, 1) srvs := make([]*SRV, 0, 10) for _, p := range validRecs(r, syscall.DNS_TYPE_SRV, target) { v := (*syscall.DNSSRVData)(unsafe.Pointer(&p.Data[0])) srvs = append(srvs, &SRV{ensureEndDot(syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(v.Target))[:])), v.Port, v.Priority, v.Weight}) } byPriorityWeight(srvs).sort() return ensureEndDot(target), srvs, nil }