fix the reflect server
This commit is contained in:
parent
052d36458d
commit
265ebba3ba
|
@ -68,20 +68,19 @@ func handleReflect(w dns.ResponseWriter, r *dns.Msg) {
|
||||||
w.Write(b)
|
w.Write(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func serve(net string) {
|
||||||
|
err := dns.ListenAndServe(":8053", net, nil)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to setup the " + net + " server: %s", err.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
dns.HandleFunc(".", handleReflect)
|
dns.HandleFunc(".", handleReflect)
|
||||||
go func() {
|
go serve("udp4")
|
||||||
err := dns.ListenAndServe(":8053", "udp", nil)
|
go serve("udp6")
|
||||||
if err != nil {
|
go serve("tcp4")
|
||||||
fmt.Printf("Failed to setup the udp server")
|
go serve("tcp6")
|
||||||
}
|
|
||||||
}()
|
|
||||||
go func() {
|
|
||||||
err := dns.ListenAndServe(":8053", "tcp", nil)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Failed to setup the tcp server")
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
forever:
|
forever:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|
32
server.go
32
server.go
|
@ -170,47 +170,29 @@ type Server struct {
|
||||||
WriteTimeout int64 // the net.Conn.SetWriteTimeout value for new connections
|
WriteTimeout int64 // the net.Conn.SetWriteTimeout value for new connections
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serve accepts incoming DNS request on the TCP listener l,
|
// ...
|
||||||
// creating a new service thread for each. The service threads
|
|
||||||
// read requests and then call handler to reply to them.
|
|
||||||
// Handler is typically nil, in which case the DefaultServeMux is used.
|
|
||||||
func ServeTCP(l *net.TCPListener, handler Handler) os.Error {
|
|
||||||
srv := &Server{Handler: handler, Net: "tcp"}
|
|
||||||
return srv.ServeTCP(l)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Serve accepts incoming DNS request on the UDP Conn l,
|
|
||||||
// creating a new service thread for each. The service threads
|
|
||||||
// read requests and then call handler to reply to them.
|
|
||||||
// Handler is typically nil, in which case the DefaultServeMux is used.
|
|
||||||
func ServeUDP(l *net.UDPConn, handler Handler) os.Error {
|
|
||||||
srv := &Server{Handler: handler, Net: "udp"}
|
|
||||||
return srv.ServeUDP(l)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fixes for udp/tcp
|
|
||||||
func (srv *Server) ListenAndServe() os.Error {
|
func (srv *Server) ListenAndServe() os.Error {
|
||||||
addr := srv.Addr
|
addr := srv.Addr
|
||||||
if addr == "" {
|
if addr == "" {
|
||||||
addr = ":domain"
|
addr = ":domain"
|
||||||
}
|
}
|
||||||
switch srv.Net {
|
switch srv.Net {
|
||||||
case "tcp":
|
case "tcp", "tcp4", "tcp6":
|
||||||
a, e := net.ResolveTCPAddr("tcp", addr)
|
a, e := net.ResolveTCPAddr(srv.Net, addr)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
l, e := net.ListenTCP("tcp", a)
|
l, e := net.ListenTCP(srv.Net, a)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
return srv.ServeTCP(l)
|
return srv.ServeTCP(l)
|
||||||
case "udp":
|
case "udp", "udp4", "udp6":
|
||||||
a, e := net.ResolveUDPAddr("udp", addr)
|
a, e := net.ResolveUDPAddr(srv.Net, addr)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
l, e := net.ListenUDP("udp", a)
|
l, e := net.ListenUDP(srv.Net, a)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue