Skip to content

Commit

Permalink
MG-337 fixing test
Browse files Browse the repository at this point in the history
  • Loading branch information
mageddo committed Jul 13, 2017
1 parent dbfa2fa commit 89766dd
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/github.com/mageddo/dns-proxy-server/test/dnsserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ import (
"syscall"
"github.com/miekg/dns"
"github.com/mageddo/log"
"github.com/mageddo/dns-proxy-server/utils"
"net"
"errors"
)

var (
Expand All @@ -68,7 +69,7 @@ func handleReflect(respWriter dns.ResponseWriter, reqMsg *dns.Msg) {

log.Logger.Infof("m=handleReflect, questions=%d, 1stQuestion=%s", len(reqMsg.Question), questionName)

resp := utils.SolveName(questionName)
resp := SolveName(questionName)
resp.SetReply(reqMsg)
resp.Compress = *compress

Expand Down Expand Up @@ -125,3 +126,33 @@ func main2() {
s := <-sig
fmt.Printf("Signal (%s) received, stopping\n", s)
}


// reference https://miek.nl/2014/August/16/go-dns-package/
func SolveName(hostname string) *dns.Msg {


//config, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
c := new(dns.Client)

m := new(dns.Msg)
m.SetQuestion(dns.Fqdn(hostname), dns.TypeA) // CAN BE A, AAA, MX, etc.
m.RecursionDesired = true

//r, _, err := c.Exchange(m, net.JoinHostPort(config.Servers[0], config.Port)) // server and port to ask
r, _, err := c.Exchange(m, net.JoinHostPort("8.8.8.8", "53")) // server and port to ask

// if the answer not be returned
if r == nil {
panic(err)
}

// what the code of the return message ?
if r.Rcode != dns.RcodeSuccess {
panic(errors.New(fmt.Sprintf(" *** invalid answer name %s after MX query for %s", hostname, hostname)))
}

// looping through the anwsers
return r

}

0 comments on commit 89766dd

Please sign in to comment.