func serve(net, name, secret string) { switch name { case "": err := dns.ListenAndServe(":8053", net, nil) if err != nil { fmt.Printf("Failed to setup the "+net+" server: %s\n", err.Error()) } default: err := dns.ListenAndServeTsig(":8053", net, nil, map[string]string{name: secret}) if err != nil { fmt.Printf("Failed to setup the "+net+" server: %s\n", err.Error()) } } }
func serve(net, name, secret string) { switch name { case "": err := dns.ListenAndServe(":8053", net, nil) if err != nil { fmt.Printf("Failed to setup the "+net+" server: %s\n", err.Error()) } default: server := &dns.Server{Addr: ":8053", Net: "net", TsigSecret: map[string]string{name: secret}} err := server.ListenAndServe() if err != nil { fmt.Printf("Failed to setup the "+net+" server: %s\n", err.Error()) } } }
func main() { debug = flag.Bool("debug", false, "enable debugging") cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file") flag.Parse() if *cpuprofile != "" { f, err := os.Create(*cpuprofile) if err != nil { log.Fatal(err) } pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } file, err := os.Open("miek.nl.signed") defer file.Close() if err != nil { fmt.Printf("%s\n", err.String()) return } p := dns.NewParser(bufio.NewReader(file)) zone, err = p.Zone() if err != nil { fmt.Printf("%s\n", err.String()) return } s, err := zone.LookupName("miek.nl.", dns.ClassINET, dns.TypeSOA) if err != nil { fmt.Printf("%s\n", err.String()) return } soa = s.RRs[0] s1, err := zone.LookupName("miek.nl.", dns.ClassINET, dns.TypeNS) if err != nil { fmt.Printf("%s\n", err.String()) return } ns = s1.RRs if len(s1.RRsigs) > 0 { nsDNSSEC = ns for _, r := range s.RRsigs { nsDNSSEC = append(nsDNSSEC, r) } } spam := "Proudly served by Go: http://www.golang.org" spamIN = &dns.RR_TXT{Hdr: dns.RR_Header{Name: "miek.nl.", Rrtype: dns.TypeTXT, Class: dns.ClassINET}, Txt: spam} spamCH = &dns.RR_TXT{Hdr: dns.RR_Header{Name: "miek.nl.", Rrtype: dns.TypeTXT, Class: dns.ClassCHAOS}, Txt: spam} dns.HandleFunc("miek.nl.", handleQuery) dns.HandleFunc("bind.", handleQueryCHAOS) dns.HandleFunc("server.", handleQueryCHAOS) go func() { err := dns.ListenAndServe(":8053", "udp", nil) if err != nil { } }() go func() { err := dns.ListenAndServe(":8053", "tcp", nil) if err != nil { } }() forever: for { select { case <-signal.Incoming: fmt.Printf("Signal received, stopping\n") break forever } } }
func listenAndServe(add, net string) { err := dns.ListenAndServe(add, net, nil) if err != nil { fmt.Printf("Failed to setup: " + net + " " + add + "\n") } }
func serve(net string) { err := dns.ListenAndServe(":8053", net, nil, 0) if err != nil { fmt.Printf("Failed to setup the "+net+" server: %s\n", err.Error()) } }
func listenAndServe(add, net string) { if err := dns.ListenAndServe(add, net, nil, 512); err != nil { println("Failed to setup:", net, add) } }