mirror of
https://github.com/golang/go.git
synced 2025-11-09 21:21:03 +00:00
net: allow LookupAddr to use getnameinfo when cgo is enabled
This change allows LookupAddr to use getnameinfo through cgo for working together with various name services other than DNS. Fixes #7855. Change-Id: I5b3b4aefe3d1b904541c3350865734d8cbb1c1c4 Reviewed-on: https://go-review.googlesource.com/3420 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
deb6c5b920
commit
99f5f796d9
9 changed files with 213 additions and 18 deletions
|
|
@ -479,3 +479,28 @@ func goLookupCNAME(name string) (cname string, err error) {
|
|||
cname = rr[0].(*dnsRR_CNAME).Cname
|
||||
return
|
||||
}
|
||||
|
||||
// goLookupPTR is the native Go implementation of LookupAddr.
|
||||
// Used only if cgoLookupPTR refuses to handle the request (that is,
|
||||
// only if cgoLookupPTR is the stub in cgo_stub.go).
|
||||
// Normally we let cgo use the C library resolver instead of depending
|
||||
// on our lookup code, so that Go and C get the same answers.
|
||||
func goLookupPTR(addr string) ([]string, error) {
|
||||
names := lookupStaticAddr(addr)
|
||||
if len(names) > 0 {
|
||||
return names, nil
|
||||
}
|
||||
arpa, err := reverseaddr(addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, rrs, err := lookup(arpa, dnsTypePTR)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ptrs := make([]string, len(rrs))
|
||||
for i, rr := range rrs {
|
||||
ptrs[i] = rr.(*dnsRR_PTR).Ptr
|
||||
}
|
||||
return ptrs, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue