package dnsmessage

Import Path
	vendor/golang.org/x/net/dns/dnsmessage (on go.dev)

Dependency Relation
	imports one package, and imported by one package

Involved Source Files Package dnsmessage provides a mostly RFC 1035 compliant implementation of DNS message packing and unpacking. The package also supports messages with Extension Mechanisms for DNS (EDNS(0)) as defined in RFC 6891. This implementation is designed to minimize heap allocations and avoid unnecessary packing and unpacking as much as possible.
Package-Level Type Names (total 27, in which 24 are exported)
/* sort exporteds by: | */
An AAAAResource is an AAAA Resource record. AAAA [16]byte GoString implements fmt.GoStringer.GoString. *T : ResourceBody *T : fmt.GoStringer func (*Parser).AAAAResource() (AAAAResource, error) func (*Builder).AAAAResource(h ResourceHeader, r AAAAResource) error
An AResource is an A Resource record. A [4]byte GoString implements fmt.GoStringer.GoString. *T : ResourceBody *T : fmt.GoStringer func (*Parser).AResource() (AResource, error) func (*Builder).AResource(h ResourceHeader, r AResource) error
A Builder allows incrementally packing a DNS message. Example usage: buf := make([]byte, 2, 514) b := NewBuilder(buf, Header{...}) b.EnableCompression() // Optionally start a section and add things to that section. // Repeat adding sections as necessary. buf, err := b.Finish() // If err is nil, buf[2:] will contain the built bytes. AAAAResource adds a single AAAAResource. AResource adds a single AResource. CNAMEResource adds a single CNAMEResource. EnableCompression enables compression in the Builder. Leaving compression disabled avoids compression related allocations, but can result in larger message sizes. Be careful with this mode as it can cause messages to exceed the UDP size limit. According to RFC 1035, section 4.1.4, the use of compression is optional, but all implementations must accept both compressed and uncompressed DNS messages. Compression should be enabled before any sections are added for best results. Finish ends message building and generates a binary message. MXResource adds a single MXResource. NSResource adds a single NSResource. OPTResource adds a single OPTResource. PTRResource adds a single PTRResource. Question adds a single Question. SOAResource adds a single SOAResource. SRVResource adds a single SRVResource. StartAdditionals prepares the builder for packing Additionals. StartAnswers prepares the builder for packing Answers. StartAuthorities prepares the builder for packing Authorities. StartQuestions prepares the builder for packing Questions. TXTResource adds a single TXTResource. func NewBuilder(buf []byte, h Header) Builder
A Class is a type of network. GoString implements fmt.GoStringer.GoString. String implements fmt.Stringer.String. T : fmt.GoStringer T : fmt.Stringer const ClassANY const ClassCHAOS const ClassCSNET const ClassHESIOD const ClassINET
A CNAMEResource is a CNAME Resource record. CNAME Name GoString implements fmt.GoStringer.GoString. *T : ResourceBody *T : fmt.GoStringer func (*Parser).CNAMEResource() (CNAMEResource, error) func (*Builder).CNAMEResource(h ResourceHeader, r CNAMEResource) error
Header is a representation of a DNS message header. Authoritative bool ID uint16 OpCode OpCode RCode RCode RecursionAvailable bool RecursionDesired bool Response bool Truncated bool GoString implements fmt.GoStringer.GoString. *T : fmt.GoStringer func (*Parser).Start(msg []byte) (Header, error) func NewBuilder(buf []byte, h Header) Builder
Message is a representation of a DNS message. Additionals []Resource Answers []Resource Authorities []Resource Header Header Header.Authoritative bool Header.ID uint16 Header.OpCode OpCode Header.RCode RCode Header.RecursionAvailable bool Header.RecursionDesired bool Header.Response bool Header.Truncated bool Questions []Question AppendPack is like Pack but appends the full Message to b and returns the extended buffer. GoString implements fmt.GoStringer.GoString. Pack packs a full Message. Unpack parses a full Message. *T : fmt.GoStringer
An MXResource is an MX Resource record. MX Name Pref uint16 GoString implements fmt.GoStringer.GoString. *T : ResourceBody *T : fmt.GoStringer func (*Parser).MXResource() (MXResource, error) func (*Builder).MXResource(h ResourceHeader, r MXResource) error
A Name is a non-encoded domain name. It is used instead of strings to avoid allocations. Data [255]byte Length uint8 GoString implements fmt.GoStringer.GoString. String implements fmt.Stringer.String. *T : fmt.GoStringer T : fmt.Stringer func MustNewName(name string) Name func NewName(name string) (Name, error)
An NSResource is an NS Resource record. NS Name GoString implements fmt.GoStringer.GoString. *T : ResourceBody *T : fmt.GoStringer func (*Parser).NSResource() (NSResource, error) func (*Builder).NSResource(h ResourceHeader, r NSResource) error
An OpCode is a DNS operation code. GoString implements fmt.GoStringer.GoString. T : fmt.GoStringer
An Option represents a DNS message option within OPTResource. The message option is part of the extension mechanisms for DNS as defined in RFC 6891. // option code Data []byte GoString implements fmt.GoStringer.GoString. *T : fmt.GoStringer
An OPTResource is an OPT pseudo Resource record. The pseudo resource record is part of the extension mechanisms for DNS as defined in RFC 6891. Options []Option GoString implements fmt.GoStringer.GoString. *T : ResourceBody *T : fmt.GoStringer func (*Parser).OPTResource() (OPTResource, error) func (*Builder).OPTResource(h ResourceHeader, r OPTResource) error
A Parser allows incrementally parsing a DNS message. When parsing is started, the Header is parsed. Next, each Question can be either parsed or skipped. Alternatively, all Questions can be skipped at once. When all Questions have been parsed, attempting to parse Questions will return (nil, nil) and attempting to skip Questions will return (true, nil). After all Questions have been either parsed or skipped, all Answers, Authorities and Additionals can be either parsed or skipped in the same way, and each type of Resource must be fully parsed or skipped before proceeding to the next type of Resource. Note that there is no requirement to fully skip or parse the message. AAAAResource parses a single AAAAResource. One of the XXXHeader methods must have been called before calling this method. AResource parses a single AResource. One of the XXXHeader methods must have been called before calling this method. Additional parses a single Additional Resource. AdditionalHeader parses a single Additional ResourceHeader. AllAdditionals parses all Additional Resources. AllAnswers parses all Answer Resources. AllAuthorities parses all Authority Resources. AllQuestions parses all Questions. Answer parses a single Answer Resource. AnswerHeader parses a single Answer ResourceHeader. Authority parses a single Authority Resource. AuthorityHeader parses a single Authority ResourceHeader. CNAMEResource parses a single CNAMEResource. One of the XXXHeader methods must have been called before calling this method. MXResource parses a single MXResource. One of the XXXHeader methods must have been called before calling this method. NSResource parses a single NSResource. One of the XXXHeader methods must have been called before calling this method. OPTResource parses a single OPTResource. One of the XXXHeader methods must have been called before calling this method. PTRResource parses a single PTRResource. One of the XXXHeader methods must have been called before calling this method. Question parses a single Question. SOAResource parses a single SOAResource. One of the XXXHeader methods must have been called before calling this method. SRVResource parses a single SRVResource. One of the XXXHeader methods must have been called before calling this method. SkipAdditional skips a single Additional Resource. SkipAllAdditionals skips all Additional Resources. SkipAllAnswers skips all Answer Resources. SkipAllAuthorities skips all Authority Resources. SkipAllQuestions skips all Questions. SkipAnswer skips a single Answer Resource. SkipAuthority skips a single Authority Resource. SkipQuestion skips a single Question. Start parses the header and enables the parsing of Questions. TXTResource parses a single TXTResource. One of the XXXHeader methods must have been called before calling this method.
A PTRResource is a PTR Resource record. PTR Name GoString implements fmt.GoStringer.GoString. *T : ResourceBody *T : fmt.GoStringer func (*Parser).PTRResource() (PTRResource, error) func (*Builder).PTRResource(h ResourceHeader, r PTRResource) error
A Question is a DNS query. Class Class Name Name Type Type GoString implements fmt.GoStringer.GoString. *T : fmt.GoStringer func (*Parser).AllQuestions() ([]Question, error) func (*Parser).Question() (Question, error) func (*Builder).Question(q Question) error
An RCode is a DNS response status code. GoString implements fmt.GoStringer.GoString. String implements fmt.Stringer.String. T : fmt.GoStringer T : fmt.Stringer func (*ResourceHeader).ExtendedRCode(rcode RCode) RCode func (*ResourceHeader).ExtendedRCode(rcode RCode) RCode func (*ResourceHeader).SetEDNS0(udpPayloadLen int, extRCode RCode, dnssecOK bool) error const RCodeFormatError const RCodeNameError const RCodeNotImplemented const RCodeRefused const RCodeServerFailure const RCodeSuccess
A Resource is a DNS resource record. Body ResourceBody Header ResourceHeader (*T) GoString() string *T : fmt.GoStringer func (*Parser).Additional() (Resource, error) func (*Parser).AllAdditionals() ([]Resource, error) func (*Parser).AllAnswers() ([]Resource, error) func (*Parser).AllAuthorities() ([]Resource, error) func (*Parser).Answer() (Resource, error) func (*Parser).Authority() (Resource, error)
A ResourceBody is a DNS resource record minus the header. GoString implements fmt.GoStringer.GoString. *AAAAResource *AResource *CNAMEResource *MXResource *NSResource *OPTResource *PTRResource *SOAResource *SRVResource *TXTResource T : fmt.GoStringer
A ResourceHeader is the header of a DNS resource record. There are many types of DNS resource records, but they all share the same header. Class is the class of network to which this DNS resource record pertains. Length is the length of data in the resource record after the header. This field will be set automatically during packing. Name is the domain name for which this resource record pertains. TTL is the length of time (measured in seconds) which this resource record is valid for (time to live). All Resources in a set should have the same TTL (RFC 2181 Section 5.2). Type is the type of DNS resource record. This field will be set automatically during packing. DNSSECAllowed reports whether the DNSSEC OK bit is set. ExtendedRCode returns an extended RCode. The provided rcode must be the RCode in DNS message header. GoString implements fmt.GoStringer.GoString. SetEDNS0 configures h for EDNS(0). The provided extRCode must be an extedned RCode. *T : fmt.GoStringer func (*Parser).AdditionalHeader() (ResourceHeader, error) func (*Parser).AnswerHeader() (ResourceHeader, error) func (*Parser).AuthorityHeader() (ResourceHeader, error) func (*Builder).AAAAResource(h ResourceHeader, r AAAAResource) error func (*Builder).AResource(h ResourceHeader, r AResource) error func (*Builder).CNAMEResource(h ResourceHeader, r CNAMEResource) error func (*Builder).MXResource(h ResourceHeader, r MXResource) error func (*Builder).NSResource(h ResourceHeader, r NSResource) error func (*Builder).OPTResource(h ResourceHeader, r OPTResource) error func (*Builder).PTRResource(h ResourceHeader, r PTRResource) error func (*Builder).SOAResource(h ResourceHeader, r SOAResource) error func (*Builder).SRVResource(h ResourceHeader, r SRVResource) error func (*Builder).TXTResource(h ResourceHeader, r TXTResource) error
An SOAResource is an SOA Resource record. Expire uint32 MBox Name MinTTL the is the default TTL of Resources records which did not contain a TTL value and the TTL of negative responses. (RFC 2308 Section 4) NS Name Refresh uint32 Retry uint32 Serial uint32 GoString implements fmt.GoStringer.GoString. *T : ResourceBody *T : fmt.GoStringer func (*Parser).SOAResource() (SOAResource, error) func (*Builder).SOAResource(h ResourceHeader, r SOAResource) error
An SRVResource is an SRV Resource record. Port uint16 Priority uint16 // Not compressed as per RFC 2782. Weight uint16 GoString implements fmt.GoStringer.GoString. *T : ResourceBody *T : fmt.GoStringer func (*Parser).SRVResource() (SRVResource, error) func (*Builder).SRVResource(h ResourceHeader, r SRVResource) error
A TXTResource is a TXT Resource record. TXT []string GoString implements fmt.GoStringer.GoString. *T : ResourceBody *T : fmt.GoStringer func (*Parser).TXTResource() (TXTResource, error) func (*Builder).TXTResource(h ResourceHeader, r TXTResource) error
A Type is a type of DNS request and response. GoString implements fmt.GoStringer.GoString. String implements fmt.Stringer.String. T : fmt.GoStringer T : fmt.Stringer const TypeA const TypeAAAA const TypeALL const TypeAXFR const TypeCNAME const TypeHINFO const TypeMINFO const TypeMX const TypeNS const TypeOPT const TypePTR const TypeSOA const TypeSRV const TypeTXT const TypeWKS
Package-Level Functions (total 39, in which 3 are exported)
MustNewName creates a new Name from a string and panics on error.
NewBuilder creates a new builder with compression disabled. Note: Most users will want to immediately enable compression with the EnableCompression method. See that method's comment for why you may or may not want to enable compression. The DNS message is appended to the provided initial buffer buf (which may be nil) as it is built. The final message is returned by the (*Builder).Finish method, which may return the same underlying array if there was sufficient capacity in the slice.
NewName creates a new Name from a string.
Package-Level Variables (total 23, in which 2 are exported)
ErrNotStarted indicates that the prerequisite information isn't available yet because the previous records haven't been appropriately parsed, skipped or finished.
ErrSectionDone indicated that all records in the section have been parsed or finished.
Package-Level Constants (total 48, in which 26 are exported)
Question.Class
const ClassCHAOS Class = 3
const ClassCSNET Class = 2
const ClassHESIOD Class = 4
ResourceHeader.Class and Question.Class
const RCodeRefused RCode = 5
Message.Rcode
ResourceHeader.Type and Question.Type
const TypeAAAA Type = 28
const TypeALL Type = 255
const TypeAXFR Type = 252
const TypeCNAME Type = 5
const TypeHINFO Type = 13
const TypeMINFO Type = 14
const TypeMX Type = 15
const TypeNS Type = 2
const TypeOPT Type = 41
const TypePTR Type = 12
const TypeSOA Type = 6
const TypeSRV Type = 33
const TypeTXT Type = 16
Question.Type