-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpocketDNS.go
49 lines (44 loc) · 1.04 KB
/
pocketDNS.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
log "github.com/sirupsen/logrus"
"github.com/OompahLoompah/pocketDNS/internal/pdnsconfig"
dns "github.com/OompahLoompah/pocketDNS/pkg/DNS"
listener "github.com/OompahLoompah/pocketDNS/pkg/Listener"
)
func parseRecords(domains map[string]pdnsconfig.Domain) map[string]dns.ResourceRecord {
records := make(map[string]dns.ResourceRecord)
for n, d := range domains {
for _, r := range d.Records {
if r.Type == "A" {
records[n] = dns.ResourceRecord{
NAME: n,
TYPE: "A",
CLASS: "IN",
TTL: uint32(r.TTL),
RDLENGTH: uint16(len(r.RDATA)),
RDATA: r.RDATA,
}
}
}
}
return records
}
func main() {
log.SetFormatter(&log.JSONFormatter{})
log.SetLevel(log.DebugLevel)
log.Print("pocketDNS Starting...")
conf := pdnsconfig.Config()
for k, v := range conf.Domains {
log.Debug(k)
log.Debug(v)
}
d := parseRecords(conf.Domains)
f := &dns.ResponseFactory{
ARecords: d,
}
l := listener.New("127.0.0.1", 53, f)
err := l.Listen()
if err != nil {
log.Fatal(err)
}
}