···2233this is a go package for packing/unpacking dns packets.
4455+> which we expect to be so popular that it would be a waste of wire space
66+- rfc2671 4.2
77+58## Spec
69[x] 103{4,5} - DNS standard
710···25282629[ ] 2065 - DNSSEC (updated in later RFCs)
27302828-[ ] 2671 - EDNS record
3131+[x] 2671 - EDNS record
29323033[ ] 2782 - SRV record
3134
+26
message.go
···7788// Decode decodes a DNS packet.
99func (m *Message) Decode(buf []byte) (err error) {
1010+ // gets checked when parsing additional records
1111+ m.HasEDNS = false
1212+1013 offset, err := m.Header.Decode(buf, 0)
1114 if err != nil {
1215 return fmt.Errorf("failed to decode message header: %w", err)
···5356 return fmt.Errorf("failed to decode additional record #%d: %w", i+1, err)
5457 }
55585959+ if rr.RType == OPTType {
6060+ opt, ok := rr.RData.(*OPT)
6161+ if !ok {
6262+ // this should never fail
6363+ return fmt.Errorf("unable to parse RData as OPT")
6464+ }
6565+6666+ m.HasEDNS = true
6767+ m.ExtendedRCode = uint8(rr.TTL >> 24 & 0xFF000000)
6868+ m.EDNSVersion = uint8((rr.TTL & 0x00FF0000) >> 16)
6969+ m.EDNSFlags = uint16(rr.TTL & 0x0000FFFF)
7070+ m.EDNSOptions = opt.Options
7171+ m.UDPSize = uint16(rr.RClass)
7272+ }
7373+5674 m.Additional = append(m.Additional, rr)
7575+ }
7676+7777+ if !m.HasEDNS {
7878+ m.ExtendedRCode = 0
7979+ m.EDNSVersion = 0
8080+ m.EDNSFlags = 0
8181+ m.EDNSOptions = make([]EDNSOption, 0)
8282+ m.UDPSize = 512 // default in rfc-1035 section 2.3.4.
5783 }
58845985 return nil