func (self *Packet) PrintTo(p printer.Interface) { p.Printf("#%d %s", self.Id, flagString(self.Flag)) p.Printf("ques %v", self.Question) self.Answer.PrintNameTo(p, "answ") self.Authority.PrintNameTo(p, "auth") self.Addition.PrintNameTo(p, "addi") }
func (self *Exchange) printRecv(p printer.Interface) { switch self.PrintFlag { case PrintAll: if self.Recv != nil { p.Print("recv {") p.ShiftIn() self.Recv.PrintTo(p) p.ShiftOut("}") } if self.Error != nil { p.Printf("error %v", self.Error) } case PrintReply: if self.Recv != nil { self.Recv.Packet.PrintTo(p) self.printTimeTaken(p) } if self.Error != nil { p.Printf("error %v", self.Error) } default: panic("unknown print flag") } p.ShiftOut("}") }
func (self *Info) PrintTo(p printer.Interface) { if len(self.Cnames) > 0 { p.Print("cnames {") p.ShiftIn() for _, r := range self.Cnames { p.Printf("%v -> %v", r.Domain, rdata.ToDomain(r.Rdata)) } p.ShiftOut("}") } if len(self.Results) == 0 { p.Print("(unresolvable)") } else { p.Print("ips {") p.ShiftIn() for _, r := range self.Results { d := r.Domain ip := rdata.ToIPv4(r.Rdata) if d.Equal(self.Domain) { p.Printf("%v", ip) } else { p.Printf("%v(%v)", ip, d) } } p.ShiftOut("}") } if len(self.NameServers) > 0 { p.Print("servers {") p.ShiftIn() for _, ns := range self.NameServers { p.Printf("%v", ns) } p.ShiftOut("}") } if len(self.Records) > 0 { p.Print("records {") p.ShiftIn() for _, rr := range self.Records { p.Printf("%v", rr.Digest()) } p.ShiftOut("}") } }
func (self *Exchange) printTimeTaken(p printer.Interface) { d := self.Recv.Timestamp.Sub(self.Send.Timestamp) n := d.Nanoseconds() var s string if n < 1e3 { s = fmt.Sprintf("%dns", n) } else if n < 1e6 { s = fmt.Sprintf("%.1fus", float64(n)/1e3) } else if n < 1e9 { s = fmt.Sprintf("%.2fms", float64(n)/1e6) } else { s = fmt.Sprintf("%.3fs", float64(n)/1e9) } p.Printf("(in %v)", s) }
func (self *Exchange) printSend(p printer.Interface) { p.Printf("%s {", self.Query.String()) p.ShiftIn() switch self.PrintFlag { case PrintAll: p.Print("send {") p.ShiftIn() self.Send.PrintTo(p) p.ShiftOut("}") case PrintReply: // do nothing default: panic("unknown print flag") } }
func (self Section) PrintNameTo(p printer.Interface, name string) { if self == nil { return } if len(self) == 0 { return } if len(self) == 1 { p.Printf("%s %v", name, self[0]) } else { p.Printf("%s {", name) p.ShiftIn() self.PrintTo(p) p.ShiftOut("}") } }
func (self *Message) PrintTo(p printer.Interface) { p.Printf("@%s", addrString(self.RemoteAddr)) self.Packet.PrintTo(p) }