summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Turner <jt@jtnet.co.uk>2017-12-07 19:50:54 +0000
committerGitHub <noreply@github.com>2017-12-07 19:50:54 +0000
commit2f7e3d63bcbfc837f921c6e88036f8971f66e80d (patch)
tree3de1e329257c476fc3a0fb10cf8deb97577af4c7
parent65a97fdf6562316dd8085a871a79aec49fe433c9 (diff)
parent510a7a3cb35e9f8a7605ece277af4cb9e78b0dac (diff)
Merge pull request #2 from jcmturner/v1fix
fix for v1
-rw-r--r--srv.go32
1 files changed, 1 insertions, 31 deletions
diff --git a/srv.go b/srv.go
index a1c74d7..8ec35cd 100644
--- a/srv.go
+++ b/srv.go
@@ -1,11 +1,8 @@
package dnsutils
import (
- "context"
- "fmt"
"math/rand"
"net"
- "os"
"sort"
)
@@ -21,19 +18,8 @@ import (
// // Do something such as dial this SRV. If fails move on the the next or break if it succeeds.
// i += 1
// }
-//
-// To override the operating system's name server set the DNSUTILS_OVERRIDE_NS environment variable.
-// The override should also include the port. For example 127.0.0.1:53
func OrderedSRV(service, proto, name string) (int, map[int]*net.SRV, error) {
- var addrs []*net.SRV
- var err error
- ns := os.Getenv("DNSUTILS_OVERRIDE_NS")
- if ns != "" {
- res := net.Resolver{Dial: overrideNS}
- _, addrs, err = res.LookupSRV(context.Background(), service, proto, name)
- } else {
- _, addrs, err = net.LookupSRV(service, proto, name)
- }
+ _, addrs, err := net.LookupSRV(service, proto, name)
if err != nil {
return 0, make(map[int]*net.SRV), err
}
@@ -41,21 +27,6 @@ func OrderedSRV(service, proto, name string) (int, map[int]*net.SRV, error) {
return index, osrv, nil
}
-func overrideNS(ctx context.Context, network, address string) (conn net.Conn, err error) {
- // Ignore the address provided and override with an environment variable if it is defined
- ns := os.Getenv("DNSUTILS_OVERRIDE_NS")
- if ns != "" {
- address = ns
- }
- if network == "tcp" || network == "udp" {
- var d net.Dialer
- conn, err = d.DialContext(ctx, network, address)
- return
- }
- err = fmt.Errorf("unsupported network protocol %s for DNS lookup", network)
- return
-}
-
func orderSRV(addrs []*net.SRV) (int, map[int]*net.SRV) {
// Initialise the ordered map
var o int
@@ -77,7 +48,6 @@ func orderSRV(addrs []*net.SRV) (int, map[int]*net.SRV) {
tos := weightedOrder(prioMap[p])
for i, s := range tos {
count += 1
- fmt.Fprintf(os.Stderr, "count: %d srv: %v", count, s)
osrv[o+i] = s
}
o += len(tos)