Skip to content
Snippets Groups Projects
Commit e3e5db7c authored by ale's avatar ale
Browse files

create RR directly rather than parsing a string

parent 3bd78197
Branches
Tags
No related merge requests found
......@@ -4,6 +4,7 @@ import (
"fmt"
"log"
"math/rand"
"net"
"strconv"
"strings"
"time"
......@@ -90,9 +91,17 @@ func ednsFromRequest(req, m *dns.Msg) {
return
}
// Create a RR string for an IP.
func recordForIp(query string, ttl int, recType string, ip string) string {
return fmt.Sprintf("%s %d IN %s %s", query, ttl, recType, ip)
// Create an A RR for a specific IP.
func recordForIp(name string, ttl int, ip string) *dns.A {
rec := new(dns.A)
rec.Hdr = dns.RR_Header{
Name: name,
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: uint32(ttl),
}
rec.A = net.ParseIP(ip)
return rec
}
func (d *DnsRedirector) getQuestionName(req *dns.Msg) string {
......@@ -150,9 +159,8 @@ func (d *DnsRedirector) serveDNS(w dns.ResponseWriter, req *dns.Msg) {
m.SetReply(req)
m.MsgHdr.Authoritative = true
for _, ip := range ips {
rec := recordForIp(query, d.ttl, "A", ip)
answer, _ := dns.NewRR(rec)
m.Answer = append(m.Answer, answer)
rec := recordForIp(query, d.ttl, ip)
m.Answer = append(m.Answer, rec)
}
log.Printf("Query(%s): %v", query, ips)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment