6 year68 = 1 << 31 // For RFC1982 (Serial Arithmetic) calculations in 32 bits.
7 defaultTtl = 3600 // Default internal TTL.
9 // DefaultMsgSize is the standard default for messages larger than 512 bytes.
11 // MinMsgSize is the minimal size of a DNS packet.
13 // MaxMsgSize is the largest possible DNS packet.
17 // Error represents a DNS error.
18 type Error struct{ err string }
20 func (e *Error) Error() string {
24 return "dns: " + e.err
27 // An RR represents a resource record.
29 // Header returns the header of an resource record. The header contains
30 // everything up to the rdata.
32 // String returns the text representation of the resource record.
35 // copy returns a copy of the RR
38 // len returns the length (in octets) of the compressed or uncompressed RR in wire format.
40 // If compression is nil, the uncompressed size will be returned, otherwise the compressed
41 // size will be returned and domain names will be added to the map for future compression.
42 len(off int, compression map[string]struct{}) int
44 // pack packs the records RDATA into wire format. The header will
45 // already have been packed into msg.
46 pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error)
48 // unpack unpacks an RR from wire format.
50 // This will only be called on a new and empty RR type with only the header populated. It
51 // will only be called if the record's RDATA is non-empty.
52 unpack(msg []byte, off int) (off1 int, err error)
54 // parse parses an RR from zone file format.
56 // This will only be called on a new and empty RR type with only the header populated.
57 parse(c *zlexer, origin, file string) *ParseError
59 // isDuplicate returns whether the two RRs are duplicates.
60 isDuplicate(r2 RR) bool
63 // RR_Header is the header all DNS resource records share.
64 type RR_Header struct {
65 Name string `dns:"cdomain-name"`
69 Rdlength uint16 // Length of data after header.
72 // Header returns itself. This is here to make RR_Header implements the RR interface.
73 func (h *RR_Header) Header() *RR_Header { return h }
75 // Just to implement the RR interface.
76 func (h *RR_Header) copy() RR { return nil }
78 func (h *RR_Header) String() string {
81 if h.Rrtype == TypeOPT {
83 // and maybe other things
86 s += sprintName(h.Name) + "\t"
87 s += strconv.FormatInt(int64(h.Ttl), 10) + "\t"
88 s += Class(h.Class).String() + "\t"
89 s += Type(h.Rrtype).String() + "\t"
93 func (h *RR_Header) len(off int, compression map[string]struct{}) int {
94 l := domainNameLen(h.Name, off, compression, true)
95 l += 10 // rrtype(2) + class(2) + ttl(4) + rdlength(2)
99 func (h *RR_Header) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {
100 // RR_Header has no RDATA to pack.
104 func (h *RR_Header) unpack(msg []byte, off int) (int, error) {
105 panic("dns: internal error: unpack should never be called on RR_Header")
108 func (h *RR_Header) parse(c *zlexer, origin, file string) *ParseError {
109 panic("dns: internal error: parse should never be called on RR_Header")
112 // ToRFC3597 converts a known RR to the unknown RR representation from RFC 3597.
113 func (rr *RFC3597) ToRFC3597(r RR) error {
114 buf := make([]byte, Len(r)*2)
115 headerEnd, off, err := packRR(r, buf, 0, compressionMap{}, false)
121 *rr = RFC3597{Hdr: *r.Header()}
122 rr.Hdr.Rdlength = uint16(off - headerEnd)
128 _, err = rr.unpack(buf, headerEnd)