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