1
// Copyright 2011 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
13
// LookupHost looks up the given host using the local resolver.
14
// It returns an array of that host's addresses.
15
func LookupHost(host string) (addrs []string, err os.Error) {
16
addrs, err, ok := cgoLookupHost(host)
18
addrs, err = goLookupHost(host)
23
// LookupIP looks up host using the local resolver.
24
// It returns an array of that host's IPv4 and IPv6 addresses.
25
func LookupIP(host string) (addrs []IP, err os.Error) {
26
addrs, err, ok := cgoLookupIP(host)
28
addrs, err = goLookupIP(host)
33
// LookupPort looks up the port for the given network and service.
34
func LookupPort(network, service string) (port int, err os.Error) {
35
port, err, ok := cgoLookupPort(network, service)
37
port, err = goLookupPort(network, service)
42
// LookupCNAME returns the canonical DNS host for the given name.
43
// Callers that do not care about the canonical name can call
44
// LookupHost or LookupIP directly; both take care of resolving
45
// the canonical name as part of the lookup.
46
func LookupCNAME(name string) (cname string, err os.Error) {
47
cname, err, ok := cgoLookupCNAME(name)
49
cname, err = goLookupCNAME(name)
54
// LookupSRV tries to resolve an SRV query of the given service,
55
// protocol, and domain name, as specified in RFC 2782. In most cases
56
// the proto argument can be the same as the corresponding
57
// Addr.Network(). The returned records are sorted by priority
58
// and randomized by weight within a priority.
59
func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err os.Error) {
60
target := "_" + service + "._" + proto + "." + name
62
cname, records, err = lookup(target, dnsTypeSRV)
66
addrs = make([]*SRV, len(records))
67
for i, rr := range records {
69
addrs[i] = &SRV{r.Target, r.Port, r.Priority, r.Weight}
71
sort.Sort(byPriorityWeight(addrs))
73
for j := 1; j < len(addrs); j++ {
74
if addrs[i].Priority != addrs[j].Priority {
75
shuffleSRVByWeight(addrs[i:j])
79
shuffleSRVByWeight(addrs[i:len(addrs)])
83
// LookupMX returns the DNS MX records for the given domain name sorted by preference.
84
func LookupMX(name string) (mx []*MX, err os.Error) {
85
_, rr, err := lookup(name, dnsTypeMX)
89
mx = make([]*MX, len(rr))
91
r := rr[i].(*dnsRR_MX)
92
mx[i] = &MX{r.Mx, r.Pref}
94
// Shuffle the records to match RFC 5321 when sorted
97
mx[i], mx[j] = mx[j], mx[i]
103
// LookupAddr performs a reverse lookup for the given address, returning a list
104
// of names mapping to that address.
105
func LookupAddr(addr string) (name []string, err os.Error) {
106
name = lookupStaticAddr(addr)
111
arpa, err = reverseaddr(addr)
116
_, records, err = lookup(arpa, dnsTypePTR)
120
name = make([]string, len(records))
121
for i := range records {
122
r := records[i].(*dnsRR_PTR)