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 25)
/* sort by: | */
An AAAAResource is an AAAA Resource record. AAAA [16]byte GoString implements fmt.GoStringer.GoString. *AAAAResource : ResourceBody *AAAAResource : 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. *AResource : ResourceBody *AResource : 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. UnknownResource adds a single UnknownResource. func NewBuilder(buf []byte, h Header) Builder
A Class is a type of network. GoString implements fmt.GoStringer.GoString. String implements fmt.Stringer.String. Class : expvar.Var Class : fmt.GoStringer Class : 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. *CNAMEResource : ResourceBody *CNAMEResource : fmt.GoStringer func (*Parser).CNAMEResource() (CNAMEResource, error) func (*Builder).CNAMEResource(h ResourceHeader, r CNAMEResource) error
Header is a representation of a DNS message header. AuthenticData bool Authoritative bool CheckingDisabled bool ID uint16 OpCode OpCode RCode RCode RecursionAvailable bool RecursionDesired bool Response bool Truncated bool GoString implements fmt.GoStringer.GoString. *Header : 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.AuthenticData bool Header.Authoritative bool Header.CheckingDisabled 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. *Message : fmt.GoStringer
An MXResource is an MX Resource record. MX Name Pref uint16 GoString implements fmt.GoStringer.GoString. *MXResource : ResourceBody *MXResource : fmt.GoStringer func (*Parser).MXResource() (MXResource, error) func (*Builder).MXResource(h ResourceHeader, r MXResource) error
A Name is a non-encoded and non-escaped 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. Note: characters inside the labels are not escaped in any way. Name : expvar.Var *Name : fmt.GoStringer Name : 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. *NSResource : ResourceBody *NSResource : 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. OpCode : 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. *Option : 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. *OPTResource : ResourceBody *OPTResource : 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 the [ErrSectionDone] error. 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. Parser is safe to copy to preserve the parsing state. 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. It does not perform a complete validation of the resource header, which means it may return a nil error when the [AdditionalHeader] would actually return an error. 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. It does not perform a complete validation of the resource header, which means it may return a nil error when the [AnswerHeader] would actually return an error. SkipAuthority skips a single Authority Resource. It does not perform a complete validation of the resource header, which means it may return a nil error when the [AuthorityHeader] would actually return an error. 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. UnknownResource parses a single UnknownResource. 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. *PTRResource : ResourceBody *PTRResource : 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. *Question : 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. RCode : expvar.Var RCode : fmt.GoStringer RCode : 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 (*Resource) GoString() string *Resource : 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 *UnknownResource ResourceBody : 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 extended RCode. *ResourceHeader : 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 func (*Builder).UnknownResource(h ResourceHeader, r UnknownResource) 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. *SOAResource : ResourceBody *SOAResource : 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. *SRVResource : ResourceBody *SRVResource : 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. *TXTResource : ResourceBody *TXTResource : 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. Type : expvar.Var Type : fmt.GoStringer Type : 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
An UnknownResource is a catch-all container for unknown record types. Data []byte Type Type GoString implements fmt.GoStringer.GoString. *UnknownResource : ResourceBody *UnknownResource : fmt.GoStringer func (*Parser).UnknownResource() (UnknownResource, error) func (*Builder).UnknownResource(h ResourceHeader, r UnknownResource) error
Package-Level Functions (total 3)
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 includes buf[:len(buf)] and 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 2)
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 26)
Question.Class
const ClassCHAOS Class = 3
const ClassCSNET Class = 2
const ClassHESIOD Class = 4
ResourceHeader.Class and Question.Class
Header.RCode values.
Header.RCode values.
Header.RCode values.
Header.RCode values.
Header.RCode values.
Header.RCode values.
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