Add generic New() function

This commit is contained in:
Miek Gieben 2011-03-13 17:54:12 +01:00
parent 496ab892d8
commit 80e97d6439
3 changed files with 7 additions and 12 deletions

View File

@ -19,6 +19,7 @@ GOFILES=\
config.go\
server.go \
nsec3.go \
new.go \
# y.go\
include $(GOROOT)/src/Make.pkg

View File

@ -89,13 +89,10 @@ Flags:
m.MsgHdr.RecursionDesired = *rd
m.Question = make([]dns.Question, 1)
if *dnssec || *nsid {
opt := new(dns.RR_OPT)
opt.Hdr = dns.RR_Header{Name: "", Rrtype: dns.TypeOPT}
opt.SetVersion(0)
opt.SetDo()
opt.SetUDPSize(dns.DefaultMsgSize)
opt := dns.New(dns.TypeOPT)
opt.(*dns.RR_OPT).SetDo()
if *nsid {
opt.SetNsid("")
opt.(*dns.RR_OPT).SetNsid("")
}
m.Extra = make([]dns.RR, 1)
m.Extra[0] = opt

9
new.go
View File

@ -9,9 +9,10 @@ func New(i int) RR {
rr = mk()
}
rr.Header().Ttl = DefaultTtl
rr.Header().Class = ClassINET
rr.Header().Rrtype = uint16(i)
switch t := rr.(type) {
case *RR_RFC3597:
t.Hdr = RR_Header{Ttl: DefaultTtl, Class: ClassINET, Rrtype: uint16(i)}
case *RR_TSIG:
t.Hdr = RR_Header{Ttl: 0, Class: ClassANY, Rrtype: uint16(i)}
t.Fudge = 300
@ -19,10 +20,6 @@ func New(i int) RR {
t.Hdr = RR_Header{Name: "", Ttl: 0, Class: 0, Rrtype: uint16(i)}
t.SetVersion(0)
t.SetUDPSize(DefaultMsgSize)
case *RR_A:
t.Hdr = RR_Header{Ttl: DefaultTtl, Class: ClassINET, Rrtype: uint16(i)}
case *RR_AAAA:
t.Hdr = RR_Header{Ttl: DefaultTtl, Class: ClassINET, Rrtype: uint16(i)}
}
return rr
}