mirror of
https://github.com/golang/go
synced 2024-11-25 05:07:56 -07:00
net, syscall: fix windows build
Fix resolv_windows.go to support recent DNS-lookup changes R=brainman, rsc1, rsc CC=golang-dev https://golang.org/cl/4300045
This commit is contained in:
parent
7d77e3117c
commit
10694c81b0
@ -14,26 +14,51 @@ import (
|
||||
var hostentLock sync.Mutex
|
||||
var serventLock sync.Mutex
|
||||
|
||||
func LookupHost(name string) (cname string, addrs []string, err os.Error) {
|
||||
func goLookupHost(name string) (addrs []string, err os.Error) {
|
||||
ips, err := goLookupIP(name)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
addrs = make([]string, 0, len(ips))
|
||||
for _, ip := range ips {
|
||||
addrs = append(addrs, ip.String())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func goLookupIP(name string) (addrs []IP, err os.Error) {
|
||||
hostentLock.Lock()
|
||||
defer hostentLock.Unlock()
|
||||
h, e := syscall.GetHostByName(name)
|
||||
if e != 0 {
|
||||
return "", nil, os.NewSyscallError("GetHostByName", e)
|
||||
return nil, os.NewSyscallError("GetHostByName", e)
|
||||
}
|
||||
cname = name
|
||||
switch h.AddrType {
|
||||
case syscall.AF_INET:
|
||||
i := 0
|
||||
addrs = make([]string, 100) // plenty of room to grow
|
||||
addrs = make([]IP, 100) // plenty of room to grow
|
||||
for p := (*[100](*[4]byte))(unsafe.Pointer(h.AddrList)); i < cap(addrs) && p[i] != nil; i++ {
|
||||
addrs[i] = IPv4(p[i][0], p[i][1], p[i][2], p[i][3]).String()
|
||||
addrs[i] = IPv4(p[i][0], p[i][1], p[i][2], p[i][3])
|
||||
}
|
||||
addrs = addrs[0:i]
|
||||
default: // TODO(vcc): Implement non IPv4 address lookups.
|
||||
return "", nil, os.NewSyscallError("LookupHost", syscall.EWINDOWS)
|
||||
return nil, os.NewSyscallError("LookupHost", syscall.EWINDOWS)
|
||||
}
|
||||
return cname, addrs, nil
|
||||
return addrs, 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
|
||||
}
|
||||
|
||||
type SRV struct {
|
||||
@ -62,7 +87,7 @@ func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err os.
|
||||
return name, addrs, nil
|
||||
}
|
||||
|
||||
func LookupPort(network, service string) (port int, err os.Error) {
|
||||
func goLookupPort(network, service string) (port int, err os.Error) {
|
||||
switch network {
|
||||
case "tcp4", "tcp6":
|
||||
network = "tcp"
|
||||
|
@ -482,6 +482,10 @@ type DNSSRVData struct {
|
||||
Pad uint16
|
||||
}
|
||||
|
||||
type DNSPTRData struct {
|
||||
Host *uint16
|
||||
}
|
||||
|
||||
type DNSRecord struct {
|
||||
Next *DNSRecord
|
||||
Name *uint16
|
||||
|
Loading…
Reference in New Issue
Block a user