At least it gives formerr now

This commit is contained in:
Miek Gieben 2010-12-23 11:02:01 +01:00
parent 4668b309e2
commit 8302d19b42
4 changed files with 166 additions and 110 deletions

4
msg.go
View File

@ -201,7 +201,7 @@ func packStructValue(val *reflect.StructValue, msg []byte, off int, edns bool) (
return len(msg), false
case *reflect.BoolValue:
// Used internally for Edns, not present in the DNS
continue;
continue
case *reflect.SliceValue:
switch f.Tag {
default:
@ -334,7 +334,7 @@ func unpackStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int,
return len(msg), false, false
case *reflect.BoolValue:
// Used internally for Edns, not present in the DNS
continue;
continue
case *reflect.SliceValue:
switch f.Tag {
default:

51
resolverEdns_test.go Normal file
View File

@ -0,0 +1,51 @@
package dns
import (
"testing"
"time"
"fmt"
)
func TestResolverEdns(t *testing.T) {
res := new(Resolver)
ch := NewQuerier(res)
res.Servers = []string{"127.0.0.1"}
res.Timeout = 2
res.Attempts = 1
m := new(Msg)
m.MsgHdr.Recursion_desired = true //only set this bit
m.Question = make([]Question, 1)
m.Extra = make([]RR, 1)
// Add EDNS rr
edns := new(RR_OPT)
edns.Hdr.Edns = true // must be set for edns
edns.Hdr.Name = "." // must . be for edns
edns.Hdr.Rrtype = TypeOPT
edns.Hdr.Class = ClassINET
edns.Hdr.Ttl = 3600
// no options
// edns.Option = make([]Option, 1)
// edns.Option[0].Code = OptionCodeNSID
// edns.Option[0].Data = "lalalala"
// ask something
m.Question[0] = Question{"miek.nl", TypeSOA, ClassINET}
m.Extra[0] = edns
fmt.Printf("%v\n", m)
ch <- DnsMsg{m, nil}
in := <-ch
if in.Dns.Rcode != RcodeSuccess {
t.Log("Failed to get an valid answer")
t.Fail()
}
fmt.Printf("%v\n", in)
ch <- DnsMsg{nil, nil}
time.Sleep(1.0e9)
}

View File

@ -134,10 +134,15 @@ func (h *RR_Header) Header() *RR_Header {
func (h *RR_Header) String() string {
var s string
if h.Edns {
s = ";"
}
if len(h.Name) == 0 {
s = ".\t"
s += ".\t"
} else {
s = h.Name + "\t"
s += h.Name + "\t"
}
s = s + strconv.Itoa(int(h.Ttl)) + "\t"
s = s + class_str[h.Class] + "\t"
@ -376,8 +381,8 @@ func (rr *RR_RRSIG) Header() *RR_Header {
// needs serial stuff
// starts when 1970 has been 68 years ago??
func intToDate(t uint32) string {
// als meer dan 68 jaar geleden, dan 68 jaar bij bedrag optellen
// TODO
// als meer dan 68 jaar geleden, dan 68 jaar bij bedrag optellen
// TODO
ti := time.SecondsToUTC(int64(t))
return ti.Format("20060102030405")
}
@ -389,9 +394,9 @@ func (rr *RR_RRSIG) String() string {
" " + strconv.Itoa(int(rr.Algorithm)) +
" " + strconv.Itoa(int(rr.Labels)) +
" " + strconv.Itoa(int(rr.OrigTtl)) +
// " " + strconv.Itoa(int(rr.Expiration)) + // date calc! TODO
// " " + strconv.Itoa(int(rr.Expiration)) + // date calc! TODO
" " + intToDate(rr.Expiration) +
// " " + strconv.Itoa(int(rr.Inception)) + // date calc! TODO
// " " + strconv.Itoa(int(rr.Inception)) + // date calc! TODO
" " + intToDate(rr.Inception) +
" " + strconv.Itoa(int(rr.KeyTag)) +
" " + rr.SignerName +