From 5087f5a9936b669bc585fb12cd2884d6259dda99 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Tue, 26 Jul 2011 21:41:24 +0200 Subject: [PATCH] SMall fixes --- defaults.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/defaults.go b/defaults.go index 99a742de..f860527f 100644 --- a/defaults.go +++ b/defaults.go @@ -41,9 +41,16 @@ func (dns *Msg) SetRcode(request *Msg, rcode int) { dns.Question = make([]Question, 1) dns.Question[0] = request.Question[0] } -// TODO isRcode for symmetry -// Create a FormError packet. +func (dns *Msg) IsRcode(rcode int) (ok bool) { + if len(dns.Question) == 0 { + return false + } + ok = dns.MsgHdr.Rcode == rcode + return +} + +// Create a packet with FormError set. func (dns *Msg) SetRcodeFormatError(request *Msg) { dns.MsgHdr.Rcode = RcodeFormatError dns.MsgHdr.Opcode = OpcodeQuery @@ -52,6 +59,15 @@ func (dns *Msg) SetRcodeFormatError(request *Msg) { dns.MsgHdr.Id = request.MsgHdr.Id } +// Is the message a packet with the FormErr set? +func (dns *Msg) IsRcodeFormatError() (ok bool) { + if len(dns.Question) == 0 { + return false + } + ok = dns.MsgHdr.Rcode == RcodeFormatError + return +} + // Is the message a dynamic update packet? func (dns *Msg) IsUpdate() (ok bool) { if len(dns.Question) == 0 {