Fix the examples
This commit is contained in:
parent
b5c6ec8e5f
commit
0e51508efa
|
@ -14,7 +14,7 @@ import (
|
|||
|
||||
// A small nameserver implementation, not too fast.
|
||||
var (
|
||||
zone *dns.Zone
|
||||
zone []dns.RR
|
||||
ns []dns.RR
|
||||
nsDNSSEC []dns.RR
|
||||
soa dns.RR
|
||||
|
|
|
@ -22,6 +22,7 @@ func main() {
|
|||
dnssec := flag.Bool("dnssec", false, "request DNSSEC records")
|
||||
query := flag.Bool("question", false, "show question")
|
||||
short := flag.Bool("short", false, "abbreviate long DNSKEY and RRSIG RRs")
|
||||
port := flag.Int("port", 53, "port number to use")
|
||||
aa := flag.Bool("aa", false, "set AA flag in query")
|
||||
ad := flag.Bool("ad", false, "set AD flag in query")
|
||||
cd := flag.Bool("cd", false, "set CD flag in query")
|
||||
|
@ -30,7 +31,7 @@ func main() {
|
|||
nsid := flag.Bool("nsid", false, "ask for NSID")
|
||||
fp := flag.Bool("fingerprint", false, "enable server detection")
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(os.Stderr, "Usage: %s [@server(:port)] [qtype] [qclass] [name ...]\n", os.Args[0])
|
||||
fmt.Fprintf(os.Stderr, "Usage: %s [@server] [qtype] [qclass] [name ...]\n", os.Args[0])
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
|
||||
|
@ -52,19 +53,15 @@ Flags:
|
|||
}
|
||||
// First class, then type, to make ANY queries possible
|
||||
// And if it looks like type, it is a type
|
||||
for k, v := range dns.Rr_str {
|
||||
if v == strings.ToUpper(flag.Arg(i)) {
|
||||
if k, ok := dns.Str_rr[strings.ToUpper(flag.Arg(i))]; ok {
|
||||
qtype = k
|
||||
continue Flags
|
||||
}
|
||||
}
|
||||
// If it looks like a class, it is a class
|
||||
for k, v := range dns.Class_str {
|
||||
if v == strings.ToUpper(flag.Arg(i)) {
|
||||
if k, ok := dns.Str_class[strings.ToUpper(flag.Arg(i))]; ok {
|
||||
qclass = k
|
||||
continue Flags
|
||||
}
|
||||
}
|
||||
// If it starts with TYPExxx it is unknown rr
|
||||
if strings.HasPrefix(flag.Arg(i), "TYPE") {
|
||||
i, e := strconv.Atoi(string([]byte(flag.Arg(i))[4:]))
|
||||
|
@ -87,9 +84,7 @@ Flags:
|
|||
}
|
||||
|
||||
nameserver = string([]byte(nameserver)[1:]) // chop off @
|
||||
if !strings.HasSuffix(nameserver, ":53") {
|
||||
nameserver += ":53"
|
||||
}
|
||||
nameserver += ":" + strconv.Itoa(*port)
|
||||
|
||||
// ipv6 todo
|
||||
// We use the async query handling, just to show how
|
||||
|
|
|
@ -55,7 +55,7 @@ func handleReflect(w dns.ResponseWriter, r *dns.Msg) {
|
|||
if v4 {
|
||||
rr = new(dns.RR_A)
|
||||
rr.(*dns.RR_A).Hdr = dns.RR_Header{Name: dom, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 0}
|
||||
rr.(*dns.RR_A).A = a
|
||||
rr.(*dns.RR_A).A = a.To4()
|
||||
} else {
|
||||
rr = new(dns.RR_AAAA)
|
||||
rr.(*dns.RR_AAAA).Hdr = dns.RR_Header{Name: dom, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: 0}
|
||||
|
@ -65,6 +65,7 @@ func handleReflect(w dns.ResponseWriter, r *dns.Msg) {
|
|||
t := new(dns.RR_TXT)
|
||||
t.Hdr = dns.RR_Header{Name: dom, Rrtype: dns.TypeTXT, Class: dns.ClassINET, Ttl: 0}
|
||||
t.Txt = str
|
||||
|
||||
m.Extra[0] = t
|
||||
m.Answer[0] = rr
|
||||
|
||||
|
@ -72,7 +73,7 @@ func handleReflect(w dns.ResponseWriter, r *dns.Msg) {
|
|||
if !ok {
|
||||
return
|
||||
}
|
||||
log.Print("Answering request")
|
||||
log.Printf("Answering request with %d bytes", len(b))
|
||||
w.Write(b)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue