Package dnsmessage
Overview ▹
Index ▹
Constants
Wire constants.
const (
// ResourceHeader.Type and Question.Type
TypeA Type = 1
TypeNS Type = 2
TypeCNAME Type = 5
TypeSOA Type = 6
TypePTR Type = 12
TypeMX Type = 15
TypeTXT Type = 16
TypeAAAA Type = 28
TypeSRV Type = 33
// Question.Type
TypeWKS Type = 11
TypeHINFO Type = 13
TypeMINFO Type = 14
TypeAXFR Type = 252
TypeALL Type = 255
// ResourceHeader.Class and Question.Class
ClassINET Class = 1
ClassCSNET Class = 2
ClassCHAOS Class = 3
ClassHESIOD Class = 4
// Question.Class
ClassANY Class = 255
// Message.Rcode
RCodeSuccess RCode = 0
RCodeFormatError RCode = 1
RCodeServerFailure RCode = 2
RCodeNameError RCode = 3
RCodeNotImplemented RCode = 4
RCodeRefused RCode = 5
)
Variables
var (
// ErrNotStarted indicates that the prerequisite information isn't
// available yet because the previous records haven't been appropriately
// parsed or skipped.
ErrNotStarted = errors.New("parsing of this type isn't available yet")
// ErrSectionDone indicated that all records in the section have been
// parsed.
ErrSectionDone = errors.New("parsing of this section has completed")
)
type AAAAResource ¶
An AAAAResource is an AAAA Resource record.
type AAAAResource struct {
ResourceHeader
AAAA [16]byte
}
type AResource ¶
An AResource is an A Resource record.
type AResource struct {
ResourceHeader
A [4]byte
}
type CNAMEResource ¶
A CNAMEResource is a CNAME Resource record.
type CNAMEResource struct {
ResourceHeader
CNAME string
}
type Class ¶
A Class is a type of network.
type Class uint16
type Header ¶
Header is a representation of a DNS message header.
type Header struct {
ID uint16
Response bool
OpCode OpCode
Authoritative bool
Truncated bool
RecursionDesired bool
RecursionAvailable bool
RCode RCode
}
type MXResource ¶
An MXResource is an MX Resource record.
type MXResource struct {
ResourceHeader
Pref uint16
MX string
}
type Message ¶
Message is a representation of a DNS message.
type Message struct {
Header
Questions []Question
Answers []Resource
Authorities []Resource
Additionals []Resource
}
func (*Message) Pack ¶
func (m *Message) Pack() ([]byte, error)
Pack packs a full Message.
func (*Message) Unpack ¶
func (m *Message) Unpack(msg []byte) error
Unpack parses a full Message.
type NSResource ¶
An NSResource is an NS Resource record.
type NSResource struct {
ResourceHeader
NS string
}
type OpCode ¶
An OpCode is a DNS operation code.
type OpCode uint16
type PTRResource ¶
A PTRResource is a PTR Resource record.
type PTRResource struct {
ResourceHeader
PTR string
}
type Parser ¶
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.
type Parser struct {
// contains filtered or unexported fields
}
func (*Parser) Additional ¶
func (p *Parser) Additional() (Resource, error)
Additional parses a single Additional Resource.
func (*Parser) AdditionalHeader ¶
func (p *Parser) AdditionalHeader() (ResourceHeader, error)
AdditionalHeader parses a single Additional ResourceHeader.
func (*Parser) AllAdditionals ¶
func (p *Parser) AllAdditionals() ([]Resource, error)
AllAdditionals parses all Additional Resources.
func (*Parser) AllAnswers ¶
func (p *Parser) AllAnswers() ([]Resource, error)
AllAnswers parses all Answer Resources.
func (*Parser) AllAuthorities ¶
func (p *Parser) AllAuthorities() ([]Resource, error)
AllAuthorities parses all Authority Resources.
func (*Parser) AllQuestions ¶
func (p *Parser) AllQuestions() ([]Question, error)
AllQuestions parses all Questions.
func (*Parser) Answer ¶
func (p *Parser) Answer() (Resource, error)
Answer parses a single Answer Resource.
func (*Parser) AnswerHeader ¶
func (p *Parser) AnswerHeader() (ResourceHeader, error)
AnswerHeader parses a single Answer ResourceHeader.
func (*Parser) Authority ¶
func (p *Parser) Authority() (Resource, error)
Authority parses a single Authority Resource.
func (*Parser) AuthorityHeader ¶
func (p *Parser) AuthorityHeader() (ResourceHeader, error)
AuthorityHeader parses a single Authority ResourceHeader.
func (*Parser) Question ¶
func (p *Parser) Question() (Question, error)
Question parses a single Question.
func (*Parser) SkipAdditional ¶
func (p *Parser) SkipAdditional() error
SkipAdditional skips a single Additional Resource.
func (*Parser) SkipAllAdditionals ¶
func (p *Parser) SkipAllAdditionals() error
SkipAllAdditionals skips all Additional Resources.
func (*Parser) SkipAllAnswers ¶
func (p *Parser) SkipAllAnswers() error
SkipAllAnswers skips all Answer Resources.
func (*Parser) SkipAllAuthorities ¶
func (p *Parser) SkipAllAuthorities() error
SkipAllAuthorities skips all Authority Resources.
func (*Parser) SkipAllQuestions ¶
func (p *Parser) SkipAllQuestions() error
SkipAllQuestions skips all Questions.
func (*Parser) SkipAnswer ¶
func (p *Parser) SkipAnswer() error
SkipAnswer skips a single Answer Resource.
func (*Parser) SkipAuthority ¶
func (p *Parser) SkipAuthority() error
SkipAuthority skips a single Authority Resource.
func (*Parser) SkipQuestion ¶
func (p *Parser) SkipQuestion() error
SkipQuestion skips a single Question.
func (*Parser) Start ¶
func (p *Parser) Start(msg []byte) (Header, error)
Start parses the header and enables the parsing of Questions.
type Question ¶
A Question is a DNS query.
type Question struct {
Name string
Type Type
Class Class
}
type RCode ¶
An RCode is a DNS response status code.
type RCode uint16
type Resource ¶
A Resource is a DNS resource record.
type Resource interface {
// Header return's the Resource's ResourceHeader.
Header() *ResourceHeader
// contains filtered or unexported methods
}
type ResourceHeader ¶
An ResourceHeader is the header of a DNS resource record. There are many types of DNS resource records, but they all share the same header.
type ResourceHeader struct {
// Name is the domain name for which this resource record pertains.
Name string
// Type is the type of DNS resource record.
//
// This field will be set automatically during packing.
Type Type
// Class is the class of network to which this DNS resource record
// pertains.
Class Class
// 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).
TTL uint32
// Length is the length of data in the resource record after the header.
//
// This field will be set automatically during packing.
Length uint16
}
func (*ResourceHeader) Header ¶
func (h *ResourceHeader) Header() *ResourceHeader
Header implements Resource.Header.
type SOAResource ¶
An SOAResource is an SOA Resource record.
type SOAResource struct {
ResourceHeader
NS string
MBox string
Serial uint32
Refresh uint32
Retry uint32
Expire uint32
// 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)
MinTTL uint32
}
type SRVResource ¶
An SRVResource is an SRV Resource record.
type SRVResource struct {
ResourceHeader
Priority uint16
Weight uint16
Port uint16
Target string // Not compressed as per RFC 2782.
}
type TXTResource ¶
A TXTResource is a TXT Resource record.
type TXTResource struct {
ResourceHeader
Txt string // Not a domain name.
}
type Type ¶
A Type is a type of DNS request and response.
type Type uint16
ActiveGo 1.8