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
50
51
52
|
package main
import (
"fmt"
"github.com/miekg/dns"
//"strconv"
//"time"
)
type server struct {
address string
port int
}
func (s *server) Run() {
udpHandler := dns.NewServeMux()
udpHandler.HandleFunc(".", Handler.DoUDP)
udpServer := &dns.Server{
Addr: s.Addr(),
Net: "udp",
Handler: udpHandler,
UDPSize: 65535,
ReadTimeout: Config.UdpTimeout,
WriteTimeout: Config.UdpTimeout,
}
go s.start(udpServer)
if !Config.NoTcp {
tcpHandler := dns.NewServeMux()
tcpHandler.HandleFunc(".", Handler.DoTCP)
tcpServer := &dns.Server{
Addr: s.Addr(),
Net: "tcp",
Handler: tcpHandler,
ReadTimeout: Config.TcpTimeout,
WriteTimeout: Config.TcpTimeout,
}
go s.start(tcpServer)
}
}
func (s *Server) start(ds *dns.Server) {
if !Config.Quiet {
fmt.Println("Listening on ", ds.Net, ":", s.Addr())
}
err := ds.ListenAndServe()
if err != nil {
fmt.Println("Failed to listen on ", ds.Net, ":", s.Addr(), ": ", err.Error())
}
}
|