aboutsummaryrefslogtreecommitdiff
path: root/src/net/dnsclient_unix.go
diff options
context:
space:
mode:
authorMikio Hara <mikioh.mikioh@gmail.com>2015-01-28 20:08:41 +0900
committerMikio Hara <mikioh.mikioh@gmail.com>2015-06-17 00:28:31 +0000
commit99f5f796d9e689befdd27f5563e28cd49dcc1567 (patch)
tree800f976dc851e62ca3110798450a3fff01cdc463 /src/net/dnsclient_unix.go
parentdeb6c5b9200137423b9c594ff6a03bcc848a852e (diff)
downloadgo-99f5f796d9e689befdd27f5563e28cd49dcc1567.tar.gz
go-99f5f796d9e689befdd27f5563e28cd49dcc1567.zip
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>
Diffstat (limited to 'src/net/dnsclient_unix.go')
-rw-r--r--src/net/dnsclient_unix.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/net/dnsclient_unix.go b/src/net/dnsclient_unix.go
index fab515f5c29..8a1745f3cb9 100644
--- a/src/net/dnsclient_unix.go
+++ b/src/net/dnsclient_unix.go
@@ -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
+}