From af5144a5ca498e2cfee14264e31371d8af111709 Mon Sep 17 00:00:00 2001 From: bshea3 <69991786+bshea3@users.noreply.github.com> Date: Fri, 24 Dec 2021 12:12:14 -0500 Subject: [PATCH] Fix location of opt pseudosection and prevent empty additional section in dig-like output (#1320) Automatically submitted. --- msg.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/msg.go b/msg.go index ead4b693..60a2e8c3 100644 --- a/msg.go +++ b/msg.go @@ -901,6 +901,11 @@ func (dns *Msg) String() string { s += "ANSWER: " + strconv.Itoa(len(dns.Answer)) + ", " s += "AUTHORITY: " + strconv.Itoa(len(dns.Ns)) + ", " s += "ADDITIONAL: " + strconv.Itoa(len(dns.Extra)) + "\n" + opt := dns.IsEdns0() + if opt != nil { + // OPT PSEUDOSECTION + s += opt.String() + "\n" + } if len(dns.Question) > 0 { s += "\n;; QUESTION SECTION:\n" for _, r := range dns.Question { @@ -923,10 +928,10 @@ func (dns *Msg) String() string { } } } - if len(dns.Extra) > 0 { + if len(dns.Extra) > 0 && (opt == nil || len(dns.Extra) > 1) { s += "\n;; ADDITIONAL SECTION:\n" for _, r := range dns.Extra { - if r != nil { + if r != nil && r.Header().Rrtype != TypeOPT { s += r.String() + "\n" } }