2011-08-17 11:28:29 -06:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package net
|
|
|
|
|
|
|
|
import (
|
2011-11-01 20:05:34 -06:00
|
|
|
"errors"
|
2011-08-17 11:28:29 -06:00
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2011-11-01 20:05:34 -06:00
|
|
|
func query(filename, query string, bufSize int) (res []string, err error) {
|
2011-08-17 11:28:29 -06:00
|
|
|
file, err := os.OpenFile(filename, os.O_RDWR, 0)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
2014-01-08 13:22:18 -07:00
|
|
|
_, err = file.Seek(0, 0)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2011-08-17 11:28:29 -06:00
|
|
|
_, err = file.WriteString(query)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
_, err = file.Seek(0, 0)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
buf := make([]byte, bufSize)
|
|
|
|
for {
|
|
|
|
n, _ := file.Read(buf)
|
|
|
|
if n <= 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
res = append(res, string(buf[:n]))
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-01 20:05:34 -06:00
|
|
|
func queryCS(net, host, service string) (res []string, err error) {
|
2011-08-17 11:28:29 -06:00
|
|
|
switch net {
|
|
|
|
case "tcp4", "tcp6":
|
|
|
|
net = "tcp"
|
|
|
|
case "udp4", "udp6":
|
|
|
|
net = "udp"
|
|
|
|
}
|
|
|
|
if host == "" {
|
|
|
|
host = "*"
|
|
|
|
}
|
2014-01-22 14:21:53 -07:00
|
|
|
return query(netdir+"/cs", net+"!"+host+"!"+service, 128)
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
|
2011-11-01 20:05:34 -06:00
|
|
|
func queryCS1(net string, ip IP, port int) (clone, dest string, err error) {
|
2011-08-17 11:28:29 -06:00
|
|
|
ips := "*"
|
2011-10-31 09:47:44 -06:00
|
|
|
if len(ip) != 0 && !ip.IsUnspecified() {
|
2011-08-17 11:28:29 -06:00
|
|
|
ips = ip.String()
|
|
|
|
}
|
|
|
|
lines, err := queryCS(net, ips, itoa(port))
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
f := getFields(lines[0])
|
|
|
|
if len(f) < 2 {
|
2014-04-07 15:14:19 -06:00
|
|
|
return "", "", errors.New("bad response from ndb/cs")
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
clone, dest = f[0], f[1]
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-01 20:05:34 -06:00
|
|
|
func queryDNS(addr string, typ string) (res []string, err error) {
|
2014-01-22 14:21:53 -07:00
|
|
|
return query(netdir+"/dns", addr+" "+typ, 1024)
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
|
2013-12-17 15:19:11 -07:00
|
|
|
// toLower returns a lower-case version of in. Restricting us to
|
|
|
|
// ASCII is sufficient to handle the IP protocol names and allow
|
|
|
|
// us to not depend on the strings and unicode packages.
|
|
|
|
func toLower(in string) string {
|
|
|
|
for _, c := range in {
|
|
|
|
if 'A' <= c && c <= 'Z' {
|
2013-12-17 17:32:27 -07:00
|
|
|
// Has upper case; need to fix.
|
|
|
|
out := []byte(in)
|
|
|
|
for i := 0; i < len(in); i++ {
|
|
|
|
c := in[i]
|
|
|
|
if 'A' <= c && c <= 'Z' {
|
|
|
|
c += 'a' - 'A'
|
|
|
|
}
|
|
|
|
out[i] = c
|
|
|
|
}
|
|
|
|
return string(out)
|
2013-12-17 15:19:11 -07:00
|
|
|
}
|
|
|
|
}
|
2013-12-17 17:32:27 -07:00
|
|
|
return in
|
2013-12-17 15:19:11 -07:00
|
|
|
}
|
|
|
|
|
2013-03-12 16:05:39 -06:00
|
|
|
// lookupProtocol looks up IP protocol name and returns
|
|
|
|
// the corresponding protocol number.
|
2012-01-21 05:51:53 -07:00
|
|
|
func lookupProtocol(name string) (proto int, err error) {
|
2014-01-22 14:21:53 -07:00
|
|
|
lines, err := query(netdir+"/cs", "!protocol="+toLower(name), 128)
|
2013-03-12 16:05:39 -06:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
if len(lines) == 0 {
|
net: fix inconsistent errors
These a series of changes fix inconsistent errors on the package net
APIs. Now almost all the APIs return OpError as a common error type
except Lookup, Resolve and Parse APIs. The Lookup, Resolve and Parse
APIs return more specific errors such as DNSError, AddrError or
ParseError.
An OpError may contain nested error information. For example, Dial may
return an OpError containing a DNSError, AddrError, unexposed type/value
or other package's type/value like the following:
OpError{/* dial info */, Err: &DNSError{}}
OpError{/* dial info */, Err: &AddrError{}}
OpError{/* dial info */, Err: <unexposed type or value>}
OpError{/* dial info */, Err: <other package's type or value>}
and Read and Write may return an OpError containing other OpError when
an application uses io.Copy or similar:
OpError{/* for io.Reader */, Err: &OpError{/* for io.Writer */}}
When an endpoint is created for connection-oriented byte-stream
protocols, Read may return an io.EOF when the connection is closed by
remote endpoint.
Fixes #4856.
A series of changes:
- net: fix inconsistent error values on Dial, Listen partially
https://go.googlesource.com/go/+/89b7c66d0d14462fd7893be4290bdfe5f9063ae1
- net: fix inconsistent error values on Read
https://go.googlesource.com/go/+/ec1144423f45e010c72363fe59291d43214b6e31
- net: fix inconsistent error values on Write
https://go.googlesource.com/go/+/11b5f98bf0d5eb8854f735cc332c912725070214
- net: fix inconsistent error values on Close
https://go.googlesource.com/go/+/310db63c5bc121e7bfccb494c01a6b91a257e7fc
- net: fix inconsistent error values on Accept
https://go.googlesource.com/go/+/4540e162b1aefda8157372764ad3d290a414ef1d
- net: fix inconsistent error values on File
https://go.googlesource.com/go/+/885111365ba0a74421059bfbd18f4c57c1e70332
- net: fix inconsistent error values on setters
https://go.googlesource.com/go/+/2173a27903897c481b0a0daf3ca3e0a0685701db
- net: fix inconsistent error values on Interface
https://go.googlesource.com/go/+/456cf0f22c93e1a6654980f4a48a564555f6c8a2
- net: fix inconsistent error values on Lookup
https://go.googlesource.com/go/+/0fc582e87942b2e52bed751b6c56660ba99e9a7d
- net: add Source field to OpError
https://go.googlesource.com/go/+/afd2d2b6df3ebfe99faf347030f15adfdf422fa0
Change-Id: Id678e369088dc9fbe9073cfe7ff8a8754a57d61f
Reviewed-on: https://go-review.googlesource.com/9236
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-21 06:20:15 -06:00
|
|
|
return 0, UnknownNetworkError(name)
|
2013-03-12 16:05:39 -06:00
|
|
|
}
|
|
|
|
f := getFields(lines[0])
|
|
|
|
if len(f) < 2 {
|
net: fix inconsistent errors
These a series of changes fix inconsistent errors on the package net
APIs. Now almost all the APIs return OpError as a common error type
except Lookup, Resolve and Parse APIs. The Lookup, Resolve and Parse
APIs return more specific errors such as DNSError, AddrError or
ParseError.
An OpError may contain nested error information. For example, Dial may
return an OpError containing a DNSError, AddrError, unexposed type/value
or other package's type/value like the following:
OpError{/* dial info */, Err: &DNSError{}}
OpError{/* dial info */, Err: &AddrError{}}
OpError{/* dial info */, Err: <unexposed type or value>}
OpError{/* dial info */, Err: <other package's type or value>}
and Read and Write may return an OpError containing other OpError when
an application uses io.Copy or similar:
OpError{/* for io.Reader */, Err: &OpError{/* for io.Writer */}}
When an endpoint is created for connection-oriented byte-stream
protocols, Read may return an io.EOF when the connection is closed by
remote endpoint.
Fixes #4856.
A series of changes:
- net: fix inconsistent error values on Dial, Listen partially
https://go.googlesource.com/go/+/89b7c66d0d14462fd7893be4290bdfe5f9063ae1
- net: fix inconsistent error values on Read
https://go.googlesource.com/go/+/ec1144423f45e010c72363fe59291d43214b6e31
- net: fix inconsistent error values on Write
https://go.googlesource.com/go/+/11b5f98bf0d5eb8854f735cc332c912725070214
- net: fix inconsistent error values on Close
https://go.googlesource.com/go/+/310db63c5bc121e7bfccb494c01a6b91a257e7fc
- net: fix inconsistent error values on Accept
https://go.googlesource.com/go/+/4540e162b1aefda8157372764ad3d290a414ef1d
- net: fix inconsistent error values on File
https://go.googlesource.com/go/+/885111365ba0a74421059bfbd18f4c57c1e70332
- net: fix inconsistent error values on setters
https://go.googlesource.com/go/+/2173a27903897c481b0a0daf3ca3e0a0685701db
- net: fix inconsistent error values on Interface
https://go.googlesource.com/go/+/456cf0f22c93e1a6654980f4a48a564555f6c8a2
- net: fix inconsistent error values on Lookup
https://go.googlesource.com/go/+/0fc582e87942b2e52bed751b6c56660ba99e9a7d
- net: add Source field to OpError
https://go.googlesource.com/go/+/afd2d2b6df3ebfe99faf347030f15adfdf422fa0
Change-Id: Id678e369088dc9fbe9073cfe7ff8a8754a57d61f
Reviewed-on: https://go-review.googlesource.com/9236
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-21 06:20:15 -06:00
|
|
|
return 0, UnknownNetworkError(name)
|
2013-03-12 16:05:39 -06:00
|
|
|
}
|
|
|
|
s := f[1]
|
|
|
|
if n, _, ok := dtoi(s, byteIndex(s, '=')+1); ok {
|
|
|
|
return n, nil
|
|
|
|
}
|
net: fix inconsistent errors
These a series of changes fix inconsistent errors on the package net
APIs. Now almost all the APIs return OpError as a common error type
except Lookup, Resolve and Parse APIs. The Lookup, Resolve and Parse
APIs return more specific errors such as DNSError, AddrError or
ParseError.
An OpError may contain nested error information. For example, Dial may
return an OpError containing a DNSError, AddrError, unexposed type/value
or other package's type/value like the following:
OpError{/* dial info */, Err: &DNSError{}}
OpError{/* dial info */, Err: &AddrError{}}
OpError{/* dial info */, Err: <unexposed type or value>}
OpError{/* dial info */, Err: <other package's type or value>}
and Read and Write may return an OpError containing other OpError when
an application uses io.Copy or similar:
OpError{/* for io.Reader */, Err: &OpError{/* for io.Writer */}}
When an endpoint is created for connection-oriented byte-stream
protocols, Read may return an io.EOF when the connection is closed by
remote endpoint.
Fixes #4856.
A series of changes:
- net: fix inconsistent error values on Dial, Listen partially
https://go.googlesource.com/go/+/89b7c66d0d14462fd7893be4290bdfe5f9063ae1
- net: fix inconsistent error values on Read
https://go.googlesource.com/go/+/ec1144423f45e010c72363fe59291d43214b6e31
- net: fix inconsistent error values on Write
https://go.googlesource.com/go/+/11b5f98bf0d5eb8854f735cc332c912725070214
- net: fix inconsistent error values on Close
https://go.googlesource.com/go/+/310db63c5bc121e7bfccb494c01a6b91a257e7fc
- net: fix inconsistent error values on Accept
https://go.googlesource.com/go/+/4540e162b1aefda8157372764ad3d290a414ef1d
- net: fix inconsistent error values on File
https://go.googlesource.com/go/+/885111365ba0a74421059bfbd18f4c57c1e70332
- net: fix inconsistent error values on setters
https://go.googlesource.com/go/+/2173a27903897c481b0a0daf3ca3e0a0685701db
- net: fix inconsistent error values on Interface
https://go.googlesource.com/go/+/456cf0f22c93e1a6654980f4a48a564555f6c8a2
- net: fix inconsistent error values on Lookup
https://go.googlesource.com/go/+/0fc582e87942b2e52bed751b6c56660ba99e9a7d
- net: add Source field to OpError
https://go.googlesource.com/go/+/afd2d2b6df3ebfe99faf347030f15adfdf422fa0
Change-Id: Id678e369088dc9fbe9073cfe7ff8a8754a57d61f
Reviewed-on: https://go-review.googlesource.com/9236
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-21 06:20:15 -06:00
|
|
|
return 0, UnknownNetworkError(name)
|
2012-01-21 05:51:53 -07:00
|
|
|
}
|
|
|
|
|
2012-01-16 22:51:54 -07:00
|
|
|
func lookupHost(host string) (addrs []string, err error) {
|
2014-01-22 14:21:53 -07:00
|
|
|
// Use netdir/cs instead of netdir/dns because cs knows about
|
2011-08-17 11:28:29 -06:00
|
|
|
// host names in local network (e.g. from /lib/ndb/local)
|
2013-12-16 13:00:23 -07:00
|
|
|
lines, err := queryCS("net", host, "1")
|
2011-08-17 11:28:29 -06:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2014-02-13 08:26:16 -07:00
|
|
|
loop:
|
2011-08-17 11:28:29 -06:00
|
|
|
for _, line := range lines {
|
|
|
|
f := getFields(line)
|
|
|
|
if len(f) < 2 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
addr := f[1]
|
|
|
|
if i := byteIndex(addr, '!'); i >= 0 {
|
|
|
|
addr = addr[:i] // remove port
|
|
|
|
}
|
|
|
|
if ParseIP(addr) == nil {
|
|
|
|
continue
|
|
|
|
}
|
2014-02-13 08:26:16 -07:00
|
|
|
// only return unique addresses
|
|
|
|
for _, a := range addrs {
|
|
|
|
if a == addr {
|
|
|
|
continue loop
|
|
|
|
}
|
|
|
|
}
|
2011-08-17 11:28:29 -06:00
|
|
|
addrs = append(addrs, addr)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-02-12 21:24:47 -07:00
|
|
|
func lookupIP(host string) (addrs []IPAddr, err error) {
|
|
|
|
lits, err := LookupHost(host)
|
2011-08-17 11:28:29 -06:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2015-02-12 21:24:47 -07:00
|
|
|
for _, lit := range lits {
|
|
|
|
host, zone := splitHostZone(lit)
|
|
|
|
if ip := ParseIP(host); ip != nil {
|
|
|
|
addr := IPAddr{IP: ip, Zone: zone}
|
|
|
|
addrs = append(addrs, addr)
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-01-16 22:51:54 -07:00
|
|
|
func lookupPort(network, service string) (port int, err error) {
|
2011-08-17 11:28:29 -06:00
|
|
|
switch network {
|
|
|
|
case "tcp4", "tcp6":
|
|
|
|
network = "tcp"
|
|
|
|
case "udp4", "udp6":
|
|
|
|
network = "udp"
|
|
|
|
}
|
|
|
|
lines, err := queryCS(network, "127.0.0.1", service)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
net: fix inconsistent errors
These a series of changes fix inconsistent errors on the package net
APIs. Now almost all the APIs return OpError as a common error type
except Lookup, Resolve and Parse APIs. The Lookup, Resolve and Parse
APIs return more specific errors such as DNSError, AddrError or
ParseError.
An OpError may contain nested error information. For example, Dial may
return an OpError containing a DNSError, AddrError, unexposed type/value
or other package's type/value like the following:
OpError{/* dial info */, Err: &DNSError{}}
OpError{/* dial info */, Err: &AddrError{}}
OpError{/* dial info */, Err: <unexposed type or value>}
OpError{/* dial info */, Err: <other package's type or value>}
and Read and Write may return an OpError containing other OpError when
an application uses io.Copy or similar:
OpError{/* for io.Reader */, Err: &OpError{/* for io.Writer */}}
When an endpoint is created for connection-oriented byte-stream
protocols, Read may return an io.EOF when the connection is closed by
remote endpoint.
Fixes #4856.
A series of changes:
- net: fix inconsistent error values on Dial, Listen partially
https://go.googlesource.com/go/+/89b7c66d0d14462fd7893be4290bdfe5f9063ae1
- net: fix inconsistent error values on Read
https://go.googlesource.com/go/+/ec1144423f45e010c72363fe59291d43214b6e31
- net: fix inconsistent error values on Write
https://go.googlesource.com/go/+/11b5f98bf0d5eb8854f735cc332c912725070214
- net: fix inconsistent error values on Close
https://go.googlesource.com/go/+/310db63c5bc121e7bfccb494c01a6b91a257e7fc
- net: fix inconsistent error values on Accept
https://go.googlesource.com/go/+/4540e162b1aefda8157372764ad3d290a414ef1d
- net: fix inconsistent error values on File
https://go.googlesource.com/go/+/885111365ba0a74421059bfbd18f4c57c1e70332
- net: fix inconsistent error values on setters
https://go.googlesource.com/go/+/2173a27903897c481b0a0daf3ca3e0a0685701db
- net: fix inconsistent error values on Interface
https://go.googlesource.com/go/+/456cf0f22c93e1a6654980f4a48a564555f6c8a2
- net: fix inconsistent error values on Lookup
https://go.googlesource.com/go/+/0fc582e87942b2e52bed751b6c56660ba99e9a7d
- net: add Source field to OpError
https://go.googlesource.com/go/+/afd2d2b6df3ebfe99faf347030f15adfdf422fa0
Change-Id: Id678e369088dc9fbe9073cfe7ff8a8754a57d61f
Reviewed-on: https://go-review.googlesource.com/9236
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-21 06:20:15 -06:00
|
|
|
unknownPortError := &AddrError{Err: "unknown port", Addr: network + "/" + service}
|
2011-08-17 11:28:29 -06:00
|
|
|
if len(lines) == 0 {
|
|
|
|
return 0, unknownPortError
|
|
|
|
}
|
|
|
|
f := getFields(lines[0])
|
|
|
|
if len(f) < 2 {
|
|
|
|
return 0, unknownPortError
|
|
|
|
}
|
|
|
|
s := f[1]
|
|
|
|
if i := byteIndex(s, '!'); i >= 0 {
|
|
|
|
s = s[i+1:] // remove address
|
|
|
|
}
|
|
|
|
if n, _, ok := dtoi(s, 0); ok {
|
|
|
|
return n, nil
|
|
|
|
}
|
|
|
|
return 0, unknownPortError
|
|
|
|
}
|
|
|
|
|
2015-10-08 14:33:38 -06:00
|
|
|
// ensureEndDot adds '.' at the end of name unless it is already there.
|
|
|
|
func ensureEndDot(name string) string {
|
|
|
|
if name == "" {
|
|
|
|
return "."
|
|
|
|
}
|
|
|
|
if name[len(name)-1] == '.' {
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
return name + "."
|
|
|
|
}
|
|
|
|
|
2012-01-16 22:51:54 -07:00
|
|
|
func lookupCNAME(name string) (cname string, err error) {
|
2011-08-17 11:28:29 -06:00
|
|
|
lines, err := queryDNS(name, "cname")
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(lines) > 0 {
|
|
|
|
if f := getFields(lines[0]); len(f) >= 3 {
|
|
|
|
return f[2] + ".", nil
|
|
|
|
}
|
|
|
|
}
|
2014-04-07 15:14:19 -06:00
|
|
|
return "", errors.New("bad response from ndb/dns")
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
|
2012-01-16 22:51:54 -07:00
|
|
|
func lookupSRV(service, proto, name string) (cname string, addrs []*SRV, err error) {
|
2011-10-18 11:57:04 -06:00
|
|
|
var target string
|
|
|
|
if service == "" && proto == "" {
|
|
|
|
target = name
|
|
|
|
} else {
|
|
|
|
target = "_" + service + "._" + proto + "." + name
|
|
|
|
}
|
2011-08-17 11:28:29 -06:00
|
|
|
lines, err := queryDNS(target, "srv")
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, line := range lines {
|
|
|
|
f := getFields(line)
|
|
|
|
if len(f) < 6 {
|
|
|
|
continue
|
|
|
|
}
|
2013-08-09 15:16:43 -06:00
|
|
|
port, _, portOk := dtoi(f[4], 0)
|
2011-08-17 11:28:29 -06:00
|
|
|
priority, _, priorityOk := dtoi(f[3], 0)
|
2013-08-09 15:16:43 -06:00
|
|
|
weight, _, weightOk := dtoi(f[2], 0)
|
2011-08-17 11:28:29 -06:00
|
|
|
if !(portOk && priorityOk && weightOk) {
|
|
|
|
continue
|
|
|
|
}
|
2015-10-08 14:33:38 -06:00
|
|
|
addrs = append(addrs, &SRV{ensureEndDot(f[5]), uint16(port), uint16(priority), uint16(weight)})
|
|
|
|
cname = ensureEndDot(f[0])
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
byPriorityWeight(addrs).sort()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-01-16 22:51:54 -07:00
|
|
|
func lookupMX(name string) (mx []*MX, err error) {
|
2011-08-17 11:28:29 -06:00
|
|
|
lines, err := queryDNS(name, "mx")
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, line := range lines {
|
|
|
|
f := getFields(line)
|
|
|
|
if len(f) < 4 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if pref, _, ok := dtoi(f[2], 0); ok {
|
2015-10-08 14:33:38 -06:00
|
|
|
mx = append(mx, &MX{ensureEndDot(f[3]), uint16(pref)})
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
byPref(mx).sort()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-10-18 00:39:04 -06:00
|
|
|
func lookupNS(name string) (ns []*NS, err error) {
|
|
|
|
lines, err := queryDNS(name, "ns")
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, line := range lines {
|
|
|
|
f := getFields(line)
|
2013-06-17 12:38:07 -06:00
|
|
|
if len(f) < 3 {
|
2012-10-18 00:39:04 -06:00
|
|
|
continue
|
|
|
|
}
|
2015-10-08 14:33:38 -06:00
|
|
|
ns = append(ns, &NS{ensureEndDot(f[2])})
|
2012-10-18 00:39:04 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-01-16 22:51:54 -07:00
|
|
|
func lookupTXT(name string) (txt []string, err error) {
|
2011-10-31 09:47:44 -06:00
|
|
|
lines, err := queryDNS(name, "txt")
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, line := range lines {
|
|
|
|
if i := byteIndex(line, '\t'); i >= 0 {
|
2015-10-08 14:33:38 -06:00
|
|
|
txt = append(txt, ensureEndDot(line[i+1:]))
|
2011-10-31 09:47:44 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
2011-09-12 21:05:33 -06:00
|
|
|
}
|
|
|
|
|
2012-01-16 22:51:54 -07:00
|
|
|
func lookupAddr(addr string) (name []string, err error) {
|
2011-08-17 11:28:29 -06:00
|
|
|
arpa, err := reverseaddr(addr)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
lines, err := queryDNS(arpa, "ptr")
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, line := range lines {
|
|
|
|
f := getFields(line)
|
|
|
|
if len(f) < 3 {
|
|
|
|
continue
|
|
|
|
}
|
2015-10-08 14:33:38 -06:00
|
|
|
name = append(name, ensureEndDot(f[2]))
|
2011-08-17 11:28:29 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|