* gcc.dg/guality/guality.exp: Skip on AIX.
[official-gcc.git] / libgo / go / net / lookup.go
blobbec93ec08cd0415219ddcf8d8477ee5acf515b88
1 // Copyright 2012 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.
5 package net
7 import (
8 "time"
11 // LookupHost looks up the given host using the local resolver.
12 // It returns an array of that host's addresses.
13 func LookupHost(host string) (addrs []string, err error) {
14 return lookupHost(host)
17 func lookupHostDeadline(host string, deadline time.Time) (addrs []string, err error) {
18 if deadline.IsZero() {
19 return lookupHost(host)
22 // TODO(bradfitz): consider pushing the deadline down into the
23 // name resolution functions. But that involves fixing it for
24 // the native Go resolver, cgo, Windows, etc.
26 // In the meantime, just use a goroutine. Most users affected
27 // by http://golang.org/issue/2631 are due to TCP connections
28 // to unresponsive hosts, not DNS.
29 timeout := deadline.Sub(time.Now())
30 if timeout <= 0 {
31 err = errTimeout
32 return
34 t := time.NewTimer(timeout)
35 defer t.Stop()
36 type res struct {
37 addrs []string
38 err error
40 resc := make(chan res, 1)
41 go func() {
42 a, err := lookupHost(host)
43 resc <- res{a, err}
44 }()
45 select {
46 case <-t.C:
47 err = errTimeout
48 case r := <-resc:
49 addrs, err = r.addrs, r.err
51 return
54 // LookupIP looks up host using the local resolver.
55 // It returns an array of that host's IPv4 and IPv6 addresses.
56 func LookupIP(host string) (addrs []IP, err error) {
57 return lookupIP(host)
60 // LookupPort looks up the port for the given network and service.
61 func LookupPort(network, service string) (port int, err error) {
62 return lookupPort(network, service)
65 // LookupCNAME returns the canonical DNS host for the given name.
66 // Callers that do not care about the canonical name can call
67 // LookupHost or LookupIP directly; both take care of resolving
68 // the canonical name as part of the lookup.
69 func LookupCNAME(name string) (cname string, err error) {
70 return lookupCNAME(name)
73 // LookupSRV tries to resolve an SRV query of the given service,
74 // protocol, and domain name. The proto is "tcp" or "udp".
75 // The returned records are sorted by priority and randomized
76 // by weight within a priority.
78 // LookupSRV constructs the DNS name to look up following RFC 2782.
79 // That is, it looks up _service._proto.name. To accommodate services
80 // publishing SRV records under non-standard names, if both service
81 // and proto are empty strings, LookupSRV looks up name directly.
82 func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err error) {
83 return lookupSRV(service, proto, name)
86 // LookupMX returns the DNS MX records for the given domain name sorted by preference.
87 func LookupMX(name string) (mx []*MX, err error) {
88 return lookupMX(name)
91 // LookupNS returns the DNS NS records for the given domain name.
92 func LookupNS(name string) (ns []*NS, err error) {
93 return lookupNS(name)
96 // LookupTXT returns the DNS TXT records for the given domain name.
97 func LookupTXT(name string) (txt []string, err error) {
98 return lookupTXT(name)
101 // LookupAddr performs a reverse lookup for the given address, returning a list
102 // of names mapping to that address.
103 func LookupAddr(addr string) (name []string, err error) {
104 return lookupAddr(addr)