~ubuntu-branches/ubuntu/utopic/golang/utopic

« back to all changes in this revision

Viewing changes to src/pkg/net/lookup.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
4
 
 
5
package net
 
6
 
 
7
import (
 
8
        "time"
 
9
)
 
10
 
 
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)
 
15
}
 
16
 
 
17
func lookupHostDeadline(host string, deadline time.Time) (addrs []string, err error) {
 
18
        if deadline.IsZero() {
 
19
                return lookupHost(host)
 
20
        }
 
21
 
 
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.
 
25
        //
 
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
 
33
        }
 
34
        t := time.NewTimer(timeout)
 
35
        defer t.Stop()
 
36
        type res struct {
 
37
                addrs []string
 
38
                err   error
 
39
        }
 
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
 
50
        }
 
51
        return
 
52
}
 
53
 
 
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)
 
58
}
 
59
 
 
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)
 
63
}
 
64
 
 
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)
 
71
}
 
72
 
 
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.
 
77
//
 
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)
 
84
}
 
85
 
 
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)
 
89
}
 
90
 
 
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)
 
94
}
 
95
 
 
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)
 
99
}
 
100
 
 
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)
 
105
}