Add IsQuestion

This commit is contained in:
Miek Gieben 2011-08-22 12:52:13 +02:00
parent aaf4af6401
commit 3ce319eb8b
3 changed files with 12 additions and 0 deletions

View File

@ -22,6 +22,7 @@ GOFILES=\
rawmsg.go \
tsig.go\
types.go\
update.go\
xfr.go\
zone.go\
zparse.go\

View File

@ -29,6 +29,7 @@ Miek Gieben - 2010, 2011 - miek@miek.nl
* 1876 - LOC record (incomplete)
* 1995 - IXFR
* 1996 - DNS notify
* 2136 - DNS Update
* 2181 - RRset definition
* 2537 - RSAMD5 DNS keys
* 2065 - DNSSEC (updated in later RFCs)

View File

@ -60,6 +60,15 @@ func (dns *Msg) SetRcodeFormatError(request *Msg) {
dns.MsgHdr.Id = request.MsgHdr.Id
}
// IsQuestion returns true if the the packet is a question
func (dns *Msg) IsQuestion() (ok bool) {
if len(dns.Question) == 0 {
return false
}
ok = dns.MsgHdr.Response == false
return
}
// Is the message a packet with the FormErr set?
func (dns *Msg) IsRcodeFormatError() (ok bool) {
if len(dns.Question) == 0 {
@ -82,6 +91,7 @@ func (dns *Msg) IsUpdate() (ok bool) {
// SetUpdate makes the message a dynamic update packet. It
// sets the ZONE section to: z, TypeSOA, classINET.
func (dns *Msg) SetUpdate(z string) {
dns.MsgHdr.Id = Id()
dns.MsgHdr.Opcode = OpcodeUpdate
dns.Question = make([]Question, 1)
dns.Question[0] = Question{z, TypeSOA, ClassINET}