About the noddiest thing that works.

This commit is contained in:
Michael Bridgen committed 2014-09-29 16:35:45 +01:00
1 parent 56a6ea6015
commit 2041f18fa1
3 files changed
+120

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
package main
import (
"github.com/miekg/dns"
"net"
"weavedns"
"log"
)
var zone = new(weavedns.ZoneDb)
func handleLocal(w dns.ResponseWriter, r *dns.Msg) {
m := new(dns.Msg)
m.SetReply(r)
q := r.Question[0]
ip, err := zone.MatchLocal(q.Name)
if err == nil {
hdr := dns.RR_Header{Name: q.Name, Rrtype: dns.TypeA,
Class: dns.ClassINET, Ttl: 3600}
a := &dns.A{hdr, net.ParseIP(ip)}
m.Answer = append(m.Answer, a)
} else {
log.Printf("Failed lookup for %s", q.Name)
}
w.WriteMsg(m)
return
}
func main() {
LocalServeMux := dns.NewServeMux()
LocalServeMux.HandleFunc("local", handleLocal)
go weavedns.ListenHttp(zone)
dns.ListenAndServe(":5300", "udp", LocalServeMux)
}