dns

package
v0.0.0-...-c2017eb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2024 License: Apache-2.0 Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("invalid")
View Source
var ErrNil = errors.New("nil")
View Source
var ErrNilReader = fmt.Errorf("reader is %w", ErrNil)

Functions

func NewRequestRecordWithReader

func NewRequestRecordWithReader(reader *Reader) (*record, error)

NewRequestRecordWithReader returns a new request resource record instance with the specified reader.

Types

type AAAARecord

type AAAARecord struct {
	// contains filtered or unexported fields
}

AAAARecord represents a AAAA record.

func NewAAAARecord

func NewAAAARecord() *AAAARecord

NewAAAARecord returns a new AAAA record instance.

func (*AAAARecord) Address

func (a *AAAARecord) Address() net.IP

Address returns the resource ip address.

func (AAAARecord) Bytes

func (r AAAARecord) Bytes() ([]byte, error)

Bytes returns the binary representation.

func (AAAARecord) Class

func (r AAAARecord) Class() Class

Class returns the resource record class.

func (AAAARecord) CompressionBytes

func (r AAAARecord) CompressionBytes() []byte

CompressionBytes returns the compression bytes.

func (*AAAARecord) Content

func (a *AAAARecord) Content() string

Content returns a string representation to the record data.

func (AAAARecord) Data

func (r AAAARecord) Data() []byte

Data returns the record data.

func (AAAARecord) Equal

func (r AAAARecord) Equal(other ResourceRecord) bool

Equal returns true if this record is equal to the specified resource record. otherwise false.

func (AAAARecord) HasNamePrefix

func (r AAAARecord) HasNamePrefix(prefix string) bool

HasNamePrefix returns true if the resource record name has the specified prefix.

func (AAAARecord) HasNameSuffix

func (r AAAARecord) HasNameSuffix(suffix string) bool

HasNameSuffix returns true if the resource record name has the specified suffix.

func (AAAARecord) IsName

func (r AAAARecord) IsName(name string) bool

IsName returns true if the resource record name is the specified name.

func (AAAARecord) Name

func (r AAAARecord) Name() string

Name returns the resource record name.

func (AAAARecord) Reader

func (r AAAARecord) Reader() (*Reader, error)

Reader returns a record reader.

func (AAAARecord) RequestBytes

func (r AAAARecord) RequestBytes() ([]byte, error)

RequestBytes returns only the binary representation of the request fields.

func (AAAARecord) ResponseBytes

func (r AAAARecord) ResponseBytes() ([]byte, error)

ResponseBytes returns only the binary representation of the all fields.

func (AAAARecord) SetClass

func (r AAAARecord) SetClass(cls Class) Record

SetClass sets the specified resource record class.

func (AAAARecord) SetCompressionBytes

func (r AAAARecord) SetCompressionBytes(b []byte)

SetCompressionBytes sets the compression bytes.

func (AAAARecord) SetData

func (r AAAARecord) SetData(b []byte) Record

SetData returns the specified record data.

func (AAAARecord) SetName

func (r AAAARecord) SetName(name string) Record

SetName sets the specified name.

func (AAAARecord) SetTTL

func (r AAAARecord) SetTTL(ttl uint) Record

SetTTL returns the specified TTL second.

func (AAAARecord) SetType

func (r AAAARecord) SetType(typ Type) Record

SetType sets the specified resource record type.

func (AAAARecord) SetUnicastResponse

func (r AAAARecord) SetUnicastResponse(enabled bool) Record

SetUnicastResponse sets the specified unicast response flag.

func (AAAARecord) TTL

func (r AAAARecord) TTL() uint

TTL returns the TTL second.

func (AAAARecord) Type

func (r AAAARecord) Type() Type

Type returns the resource record type.

func (AAAARecord) UnicastResponse

func (r AAAARecord) UnicastResponse() bool

UnicastResponse returns the unicast response flag.

type ARecord

type ARecord struct {
	// contains filtered or unexported fields
}

ARecord represents a A record.

func NewARecord

func NewARecord(res *record) *ARecord

NewARecord returns a new A record instance.

func (*ARecord) Address

func (a *ARecord) Address() net.IP

Address returns the resource ip address.

func (ARecord) Bytes

func (r ARecord) Bytes() ([]byte, error)

Bytes returns the binary representation.

func (ARecord) Class

func (r ARecord) Class() Class

Class returns the resource record class.

func (ARecord) CompressionBytes

func (r ARecord) CompressionBytes() []byte

CompressionBytes returns the compression bytes.

func (*ARecord) Content

func (a *ARecord) Content() string

Content returns a string representation to the record data.

func (ARecord) Data

func (r ARecord) Data() []byte

Data returns the record data.

func (ARecord) Equal

func (r ARecord) Equal(other ResourceRecord) bool

Equal returns true if this record is equal to the specified resource record. otherwise false.

func (ARecord) HasNamePrefix

func (r ARecord) HasNamePrefix(prefix string) bool

HasNamePrefix returns true if the resource record name has the specified prefix.

func (ARecord) HasNameSuffix

func (r ARecord) HasNameSuffix(suffix string) bool

HasNameSuffix returns true if the resource record name has the specified suffix.

func (ARecord) IsName

func (r ARecord) IsName(name string) bool

IsName returns true if the resource record name is the specified name.

func (ARecord) Name

func (r ARecord) Name() string

Name returns the resource record name.

func (ARecord) Reader

func (r ARecord) Reader() (*Reader, error)

Reader returns a record reader.

func (ARecord) RequestBytes

func (r ARecord) RequestBytes() ([]byte, error)

RequestBytes returns only the binary representation of the request fields.

func (ARecord) ResponseBytes

func (r ARecord) ResponseBytes() ([]byte, error)

ResponseBytes returns only the binary representation of the all fields.

func (ARecord) SetClass

func (r ARecord) SetClass(cls Class) Record

SetClass sets the specified resource record class.

func (ARecord) SetCompressionBytes

func (r ARecord) SetCompressionBytes(b []byte)

SetCompressionBytes sets the compression bytes.

func (ARecord) SetData

func (r ARecord) SetData(b []byte) Record

SetData returns the specified record data.

func (ARecord) SetName

func (r ARecord) SetName(name string) Record

SetName sets the specified name.

func (ARecord) SetTTL

func (r ARecord) SetTTL(ttl uint) Record

SetTTL returns the specified TTL second.

func (ARecord) SetType

func (r ARecord) SetType(typ Type) Record

SetType sets the specified resource record type.

func (ARecord) SetUnicastResponse

func (r ARecord) SetUnicastResponse(enabled bool) Record

SetUnicastResponse sets the specified unicast response flag.

func (ARecord) TTL

func (r ARecord) TTL() uint

TTL returns the TTL second.

func (ARecord) Type

func (r ARecord) Type() Type

Type returns the resource record type.

func (ARecord) UnicastResponse

func (r ARecord) UnicastResponse() bool

UnicastResponse returns the unicast response flag.

type Addition

type Addition = ResourceRecord

Addition represents an additional resource record.

type Additions

type Additions = Records

Additions represents an additional resource record array.

type Answer

type Answer = ResourceRecord

Answer represents an answer resource record.

type Answers

type Answers = Records

Answers represents an answer resource record array.

type Attribute

type Attribute struct {
	// contains filtered or unexported fields
}

Attribute represents a DNS attribute.

func NewAttribute

func NewAttribute() *Attribute

NewAttribute returns a new attribute instance.

func NewAttributeFromString

func NewAttributeFromString(str string) (*Attribute, error)

NewAttributeFromString returns a new attribute instance from the specified string.

func (*Attribute) Name

func (attr *Attribute) Name() string

Name returns the attribute name.

func (*Attribute) String

func (attr *Attribute) String() string

String returns the attribute string.

func (*Attribute) Value

func (attr *Attribute) Value() string

Value returns the attribute value.

type Attributes

type Attributes []*Attribute

func NewAttributes

func NewAttributes() Attributes

NewAttributes returns a new attributes instance.

func NewAttributesFromStrings

func NewAttributesFromStrings(strs []string) (Attributes, error)

NewAttributesFromStrings returns a new attributes instance from the specified strings.

func (Attributes) HasAttribute

func (attrs Attributes) HasAttribute(name string) bool

HasAttribute returns true if this instance has the specified attribute.

func (Attributes) LookupAttribute

func (attrs Attributes) LookupAttribute(name string) (*Attribute, bool)

LookupAttribute returns the attribute with the specified name.

func (Attributes) String

func (attrs Attributes) String() string

String returns the attribute string.

type Class

type Class uint
const (
	IN Class = 0x0001
)
type Header struct {
	// contains filtered or unexported fields
}

Header represents a protocol header.

func NewHeader

func NewHeader() *Header

NewHeader returns a nil header instance.

func NewHeaderWithBytes

func NewHeaderWithBytes(bytes []byte) *Header

NewHeaderWithBytes returns a header instance with the specified bytes.

func NewHeaderWithReader

func NewHeaderWithReader(reader io.Reader) (*Header, error)

NewHeaderWithReader returns a header instance with the specified reader.

func NewRequestHeader

func NewRequestHeader() *Header

NewRequestHeader returns a request header instance.

func NewResponseHeader

func NewResponseHeader() *Header

NewResponseHeader returns a response header instance.

func (*Header) AA

func (header *Header) AA() bool

AA returns the authoritative answer bit. RFC 6762: 18.4. AA (Authoritative Answer) Bit In query messages, the Authoritative Answer bit MUST be zero on transmission, and MUST be ignored on reception. In response messages for Multicast domains, the Authoritative Answer bit MUST be set to one (not setting this bit would imply there's some other place where "better" information may be found) and MUST be ignored on reception.

func (*Header) AD

func (header *Header) AD() bool

AD returns the authentic data bit. RFC 6762: 18.9. AD (Authentic Data) Bit In both multicast query and multicast response messages, the Authentic Data bit [RFC2535] MUST be zero on transmission, and MUST be ignored on reception.

func (*Header) AN

func (header *Header) AN() uint

AN returns the number of entries in the answer section.

func (*Header) AR

func (header *Header) AR() uint

AR returns the number of resource records in the additional records section.

func (*Header) Bytes

func (header *Header) Bytes() []byte

Bytes returns the binary representation.

func (*Header) CD

func (header *Header) CD() bool

CD returns the checking disabled bit. RFC 6762: 18.10. CD (Checking Disabled) Bit In both multicast query and multicast response messages, the Checking Disabled bit [RFC2535] MUST be zero on transmission, and MUST be ignored on reception.

func (*Header) Copy

func (header *Header) Copy() *Header

Copy returns the copy header instance.

func (*Header) Equal

func (header *Header) Equal(other *Header) bool

Equal returns true if the header is same as the specified header, otherwise false.

func (*Header) Flags

func (header *Header) Flags() []byte

Flags returns the flags.

func (*Header) ID

func (header *Header) ID() uint

ID returns the query identifier. RFC 6762: 18.1. ID (Query Identifier) In multicast query messages, the Query Identifier SHOULD be set to zero on transmission. In multicast responses, including unsolicited multicast responses, the Query Identifier MUST be set to zero on transmission, and MUST be ignored on reception.

func (*Header) IsQuery

func (header *Header) IsQuery() bool

IsQuery returns true the QR bit is zero, otherwise false.

func (*Header) IsResponse

func (header *Header) IsResponse() bool

IsResponse returns true the QR bit is one, otherwise false.

func (*Header) NS

func (header *Header) NS() uint

NS returns the number of name server resource records in the authority records section.

func (*Header) Opcode

func (header *Header) Opcode() Opcode

Opcode returns the kind of query. RFC 6762: 18.3. OPCODE In both multicast query and multicast response messages, the OPCODE MUST be zero on transmission (only standard queries are currently supported over multicast).

func (*Header) Parse

func (header *Header) Parse(reader io.Reader) error

Parse parses the specified reader.

func (*Header) QD

func (header *Header) QD() uint

QD returns the number of entries in the question section.

func (*Header) QR

func (header *Header) QR() QR

QR returns the query type. RFC 6762: 18.2. QR (Query/Response) Bit In query messages the QR bit MUST be zero. In response messages the QR bit MUST be one.

func (*Header) RA

func (header *Header) RA() bool

RA returns the recursion available bit. RFC 6762: 18.7. RA (Recursion Available) Bit In both multicast query and multicast response messages, the Recursion Available bit MUST be zero on transmission, and MUST be ignored on reception.

func (*Header) RD

func (header *Header) RD() bool

RD returns the recursion desired bit. RFC 6762: 18.6. RD (Recursion Desired) Bit In both multicast query and multicast response messages, the Recursion Desired bit SHOULD be zero on transmission, and MUST be ignored on reception.

func (*Header) ResponseCode

func (header *Header) ResponseCode() ResponseCode

ResponseCode returns the checking disabled bit. RFC 6762: 18.11. RCODE (Response Code) In both multicast query and multicast response messages, the Response Code MUST be zero on transmission. Multicast DNS messages received with non-zero Response Codes MUST be silently ignored.

func (*Header) String

func (header *Header) String() string

String returns the string representation.

func (*Header) TC

func (header *Header) TC() bool

TC returns the truncated bit. RFC 6762: 18.5. TC (Truncated) Bit In query messages, if the TC bit is set, it means that additional Known-Answer records may be following shortly. A responder SHOULD record this fact, and wait for those additional Known-Answer records, before deciding whether to respond. If the TC bit is clear, it means that the querying host has no additional Known Answers. In multicast response messages, the TC bit MUST be zero on transmission, and MUST be ignored on reception.

func (*Header) Z

func (header *Header) Z() bool

Z returns the zero bit. RFC 6762: 18.8. Z (Zero) Bit In both query and response messages, the Zero bit MUST be zero on transmission, and MUST be ignored on reception.

type Message

type Message struct {
	*Header
	Questions
	Answers
	NameServers
	Additions
}

Message represents a protocol message.

func NewMessage

func NewMessage() *Message

NewMessage returns a nil message instance.

func NewMessageWithBytes

func NewMessageWithBytes(msgBytes []byte) (*Message, error)

NewMessageWithBytes returns a message instance with the specified bytes.

func NewRequestMessage

func NewRequestMessage() *Message

NewRequestMessage returns a request message instance.

func NewResponseMessage

func NewResponseMessage() *Message

NewResponseMessage returns a response message instance.

func (*Message) AddAddition

func (msg *Message) AddAddition(a Addition)

AddAddition adds the specified additional record into the message.

func (*Message) AddAnswer

func (msg *Message) AddAnswer(a Answer)

AddAnswer adds the specified answer into the message.

func (*Message) AddNameServer

func (msg *Message) AddNameServer(ns NameServer)

AddNameServer adds the specified name server into the message.

func (*Message) AddQuestion

func (msg *Message) AddQuestion(q *Question)

AddQuestion adds the specified question into the message.

func (*Message) Bytes

func (msg *Message) Bytes() []byte

Bytes returns the binary representation.

func (*Message) Copy

func (msg *Message) Copy() *Message

Copy returns the copy message instance.

func (*Message) Equal

func (msg *Message) Equal(other *Message) bool

Equal returns true if the message is same as the specified message, otherwise false.

func (*Message) HasResourceRecord

func (msg *Message) HasResourceRecord(name string) bool

HasResourceRecord returns true if the resource record of the specified name is included in the message. otherwise false.

func (*Message) LookupResourceRecordForName

func (msg *Message) LookupResourceRecordForName(name string) (ResourceRecord, bool)

LookupResourceRecordForName returns the resource record of the specified name.

func (*Message) LookupResourceRecordForNamePrefix

func (msg *Message) LookupResourceRecordForNamePrefix(prefix string) (ResourceRecord, bool)

LookupResourceRecordForNamePrefix returns the resource record of the specified name prefix.

func (*Message) LookupResourceRecordForNameSuffix

func (msg *Message) LookupResourceRecordForNameSuffix(prefix string) (ResourceRecord, bool)

LookupResourceRecordForNameSuffix returns the resource record of the specified name suffix.

func (*Message) Parse

func (msg *Message) Parse(msgBytes []byte) error

Parse parses the specified reader.

func (*Message) Records

func (msg *Message) Records() Records

Records returns all resource records.

func (*Message) ResourceRecords

func (msg *Message) ResourceRecords() ResourceRecords

ResourceRecords returns all resource records.

func (*Message) String

func (msg *Message) String() string

String returns the string representation.

type MessageHandler

type MessageHandler interface {
	MessageReceived(*Message) (*Message, error)
}

MessageHandler represents a protocol message handler interface.

type NSECRecord

type NSECRecord struct {
	// contains filtered or unexported fields
}

NSECRecord represents a NSEC record. RFC 4034: Resource Records for the DNS Security Extensions. https://www.rfc-editor.org/rfc/rfc4034

func NewNSECRecord

func NewNSECRecord() *NSECRecord

NewNSECRecord returns a new NSEC record instance.

func (NSECRecord) Bytes

func (r NSECRecord) Bytes() ([]byte, error)

Bytes returns the binary representation.

func (NSECRecord) Class

func (r NSECRecord) Class() Class

Class returns the resource record class.

func (NSECRecord) CompressionBytes

func (r NSECRecord) CompressionBytes() []byte

CompressionBytes returns the compression bytes.

func (*NSECRecord) Content

func (nsec *NSECRecord) Content() string

Content returns a string representation to the record data.

func (NSECRecord) Data

func (r NSECRecord) Data() []byte

Data returns the record data.

func (NSECRecord) Equal

func (r NSECRecord) Equal(other ResourceRecord) bool

Equal returns true if this record is equal to the specified resource record. otherwise false.

func (NSECRecord) HasNamePrefix

func (r NSECRecord) HasNamePrefix(prefix string) bool

HasNamePrefix returns true if the resource record name has the specified prefix.

func (NSECRecord) HasNameSuffix

func (r NSECRecord) HasNameSuffix(suffix string) bool

HasNameSuffix returns true if the resource record name has the specified suffix.

func (NSECRecord) IsName

func (r NSECRecord) IsName(name string) bool

IsName returns true if the resource record name is the specified name.

func (NSECRecord) Name

func (r NSECRecord) Name() string

Name returns the resource record name.

func (NSECRecord) Reader

func (r NSECRecord) Reader() (*Reader, error)

Reader returns a record reader.

func (NSECRecord) RequestBytes

func (r NSECRecord) RequestBytes() ([]byte, error)

RequestBytes returns only the binary representation of the request fields.

func (NSECRecord) ResponseBytes

func (r NSECRecord) ResponseBytes() ([]byte, error)

ResponseBytes returns only the binary representation of the all fields.

func (NSECRecord) SetClass

func (r NSECRecord) SetClass(cls Class) Record

SetClass sets the specified resource record class.

func (NSECRecord) SetCompressionBytes

func (r NSECRecord) SetCompressionBytes(b []byte)

SetCompressionBytes sets the compression bytes.

func (NSECRecord) SetData

func (r NSECRecord) SetData(b []byte) Record

SetData returns the specified record data.

func (NSECRecord) SetName

func (r NSECRecord) SetName(name string) Record

SetName sets the specified name.

func (NSECRecord) SetTTL

func (r NSECRecord) SetTTL(ttl uint) Record

SetTTL returns the specified TTL second.

func (NSECRecord) SetType

func (r NSECRecord) SetType(typ Type) Record

SetType sets the specified resource record type.

func (NSECRecord) SetUnicastResponse

func (r NSECRecord) SetUnicastResponse(enabled bool) Record

SetUnicastResponse sets the specified unicast response flag.

func (NSECRecord) TTL

func (r NSECRecord) TTL() uint

TTL returns the TTL second.

func (NSECRecord) Type

func (r NSECRecord) Type() Type

Type returns the resource record type.

func (NSECRecord) UnicastResponse

func (r NSECRecord) UnicastResponse() bool

UnicastResponse returns the unicast response flag.

type NameServer

type NameServer = ResourceRecord

NameServer represents an authoritative nameserver resource record.

type NameServers

type NameServers = Records

NameServers represents an authoritative nameserver resource record array.

type Opcode

type Opcode int
const (
	OpQuery  Opcode = 0
	OpIQuery Opcode = 1
	OpStatus Opcode = 2
)

type PTRRecord

type PTRRecord struct {
	// contains filtered or unexported fields
}

PTRRecord represents a PTR record.

func NewPTRRecord

func NewPTRRecord() *PTRRecord

NewPTRRecord returns a new PTR record instance.

func (PTRRecord) Bytes

func (r PTRRecord) Bytes() ([]byte, error)

Bytes returns the binary representation.

func (PTRRecord) Class

func (r PTRRecord) Class() Class

Class returns the resource record class.

func (PTRRecord) CompressionBytes

func (r PTRRecord) CompressionBytes() []byte

CompressionBytes returns the compression bytes.

func (*PTRRecord) Content

func (ptr *PTRRecord) Content() string

Content returns a string representation to the record data.

func (PTRRecord) Data

func (r PTRRecord) Data() []byte

Data returns the record data.

func (*PTRRecord) DomainName

func (ptr *PTRRecord) DomainName() string

DomainName returns the resource domain name.

func (PTRRecord) Equal

func (r PTRRecord) Equal(other ResourceRecord) bool

Equal returns true if this record is equal to the specified resource record. otherwise false.

func (PTRRecord) HasNamePrefix

func (r PTRRecord) HasNamePrefix(prefix string) bool

HasNamePrefix returns true if the resource record name has the specified prefix.

func (PTRRecord) HasNameSuffix

func (r PTRRecord) HasNameSuffix(suffix string) bool

HasNameSuffix returns true if the resource record name has the specified suffix.

func (PTRRecord) IsName

func (r PTRRecord) IsName(name string) bool

IsName returns true if the resource record name is the specified name.

func (PTRRecord) Name

func (r PTRRecord) Name() string

Name returns the resource record name.

func (PTRRecord) Reader

func (r PTRRecord) Reader() (*Reader, error)

Reader returns a record reader.

func (PTRRecord) RequestBytes

func (r PTRRecord) RequestBytes() ([]byte, error)

RequestBytes returns only the binary representation of the request fields.

func (PTRRecord) ResponseBytes

func (r PTRRecord) ResponseBytes() ([]byte, error)

ResponseBytes returns only the binary representation of the all fields.

func (PTRRecord) SetClass

func (r PTRRecord) SetClass(cls Class) Record

SetClass sets the specified resource record class.

func (PTRRecord) SetCompressionBytes

func (r PTRRecord) SetCompressionBytes(b []byte)

SetCompressionBytes sets the compression bytes.

func (PTRRecord) SetData

func (r PTRRecord) SetData(b []byte) Record

SetData returns the specified record data.

func (PTRRecord) SetName

func (r PTRRecord) SetName(name string) Record

SetName sets the specified name.

func (PTRRecord) SetTTL

func (r PTRRecord) SetTTL(ttl uint) Record

SetTTL returns the specified TTL second.

func (PTRRecord) SetType

func (r PTRRecord) SetType(typ Type) Record

SetType sets the specified resource record type.

func (PTRRecord) SetUnicastResponse

func (r PTRRecord) SetUnicastResponse(enabled bool) Record

SetUnicastResponse sets the specified unicast response flag.

func (PTRRecord) TTL

func (r PTRRecord) TTL() uint

TTL returns the TTL second.

func (PTRRecord) Type

func (r PTRRecord) Type() Type

Type returns the resource record type.

func (PTRRecord) UnicastResponse

func (r PTRRecord) UnicastResponse() bool

UnicastResponse returns the unicast response flag.

type QR

type QR uint
const (
	Query    QR = 0
	Response QR = 1
)

type Question

type Question struct {
	// contains filtered or unexported fields
}

Question represents a question.

func NewQuestion

func NewQuestion() *Question

NewQuestion returns a new question instance.

func NewQuestionWithReader

func NewQuestionWithReader(reader *Reader) (*Question, error)

NewQuestionWithRecord returns a new question instance with the specified record.

func NewQuestionWithRecord

func NewQuestionWithRecord(record *record) *Question

NewQuestionWithRecord returns a new question instance with the specified record.

func (Question) Bytes

func (r Question) Bytes() ([]byte, error)

Bytes returns the binary representation.

func (Question) Class

func (r Question) Class() Class

Class returns the resource record class.

func (Question) CompressionBytes

func (r Question) CompressionBytes() []byte

CompressionBytes returns the compression bytes.

func (Question) Content

func (r Question) Content() string

Content returns a string representation to the record data.

func (Question) Data

func (r Question) Data() []byte

Data returns the record data.

func (Question) Equal

func (r Question) Equal(other ResourceRecord) bool

Equal returns true if this record is equal to the specified resource record. otherwise false.

func (Question) HasNamePrefix

func (r Question) HasNamePrefix(prefix string) bool

HasNamePrefix returns true if the resource record name has the specified prefix.

func (Question) HasNameSuffix

func (r Question) HasNameSuffix(suffix string) bool

HasNameSuffix returns true if the resource record name has the specified suffix.

func (Question) IsName

func (r Question) IsName(name string) bool

IsName returns true if the resource record name is the specified name.

func (Question) Name

func (r Question) Name() string

Name returns the resource record name.

func (Question) Reader

func (r Question) Reader() (*Reader, error)

Reader returns a record reader.

func (Question) RequestBytes

func (r Question) RequestBytes() ([]byte, error)

RequestBytes returns only the binary representation of the request fields.

func (Question) ResponseBytes

func (r Question) ResponseBytes() ([]byte, error)

ResponseBytes returns only the binary representation of the all fields.

func (Question) SetClass

func (r Question) SetClass(cls Class) Record

SetClass sets the specified resource record class.

func (Question) SetCompressionBytes

func (r Question) SetCompressionBytes(b []byte)

SetCompressionBytes sets the compression bytes.

func (Question) SetData

func (r Question) SetData(b []byte) Record

SetData returns the specified record data.

func (Question) SetName

func (r Question) SetName(name string) Record

SetName sets the specified name.

func (Question) SetTTL

func (r Question) SetTTL(ttl uint) Record

SetTTL returns the specified TTL second.

func (Question) SetType

func (r Question) SetType(typ Type) Record

SetType sets the specified resource record type.

func (Question) SetUnicastResponse

func (r Question) SetUnicastResponse(enabled bool) Record

SetUnicastResponse sets the specified unicast response flag.

func (Question) TTL

func (r Question) TTL() uint

TTL returns the TTL second.

func (Question) Type

func (r Question) Type() Type

Type returns the resource record type.

func (Question) UnicastResponse

func (r Question) UnicastResponse() bool

UnicastResponse returns the unicast response flag.

type Questions

type Questions []*Question

Questions represents a question array.

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader represents a record reader.

func NewReaderWithBytes

func NewReaderWithBytes(b []byte) *Reader

NewReaderWithBytes returns a new reader instance with the specified bytes.

func (*Reader) CompressionBytes

func (reader *Reader) CompressionBytes() []byte

CompressionBytes returns the compression bytes.

func (*Reader) Read

func (reader *Reader) Read(p []byte) (int, error)

Read overwrites the io.Reader interface.

func (*Reader) ReadName

func (reader *Reader) ReadName() (string, error)

ReadName returns a name from the reader with the read reader.

func (*Reader) ReadString

func (reader *Reader) ReadString() (string, error)

ReadString returns a string from the reader.

func (*Reader) ReadStrings

func (reader *Reader) ReadStrings() ([]string, error)

ReadStrings returns strings from the reader.

func (*Reader) ReadUint16

func (reader *Reader) ReadUint16() (uint16, error)

ReadUint16 returns a uint16 from the reader.

func (*Reader) ReadUint32

func (reader *Reader) ReadUint32() (uint32, error)

ReadUint32 returns a uint32 from the reader.

func (*Reader) ReadUint8

func (reader *Reader) ReadUint8() (uint8, error)

ReadUint8 returns a uint8 from the reader.

func (*Reader) SetCompressionBytes

func (reader *Reader) SetCompressionBytes(b []byte)

SetCompressionBytes sets the compression bytes.

type Record

type Record interface {
	// SetName sets the resource record name.
	SetName(name string) Record
	// Name returns the resource record name.
	Name() string
	// IsName returns true if the resource record name is the specified name, ignoring case.
	IsName(name string) bool
	// HasNamePrefix returns true if the resource record name has the specified prefix.
	HasNamePrefix(prefix string) bool
	// HasNameSuffix returns true if the resource record name has the specified suffix.
	HasNameSuffix(prefix string) bool
	// SetType sets the resource record type.
	SetType(t Type) Record
	// Type returns the resource record type.
	Type() Type
	// SetClass sets the resource record class.
	SetClass(c Class) Record
	// Class returns the resource record class.
	Class() Class
	// SetTTL sets the TTL second.
	SetTTL(ttl uint) Record
	// TTL returns the TTL second.
	TTL() uint
	// SetUnicastResponse sets the unicast response flag.
	SetUnicastResponse(flag bool) Record
	// UnicastResponse returns the unicast response flag.
	UnicastResponse() bool
	// SetData sets the  record data.
	SetData(data []byte) Record
	// Data returns the record data.
	Data() []byte
	// Content returns a string representation to the record data.
	Content() string
	// SetCompressionBytes sets the compression bytes.
	SetCompressionBytes(b []byte)
	// CompressionBytes returns the compression bytes.
	CompressionBytes() []byte
	// RequestBytes returns only the binary representation of the request fields.
	RequestBytes() ([]byte, error)
	// ResponseBytes returns only the binary representation of the all fields.
	ResponseBytes() ([]byte, error)
	// Bytes returns the binary representation of the record.
	Bytes() ([]byte, error)
}

Record represents a record interface.

type Records

type Records []Record

Records is a list of Record.

func (Records) HasRecord

func (records Records) HasRecord(name string) bool

HasRecord returns true if the resource record of the specified name is included in the list. otherwise false.

func (Records) LookupAAAARecords

func (records Records) LookupAAAARecords() []*AAAARecord

LookupAAAARecords returns the AAAA records.

func (Records) LookupARecords

func (records Records) LookupARecords() []*ARecord

LookupARecords returns the A records.

func (Records) LookupPTRRecords

func (records Records) LookupPTRRecords() []*PTRRecord

LookupPTRRecords returns the PTR records.

func (Records) LookupRecordForName

func (records Records) LookupRecordForName(name string) (Record, bool)

LookupRecordForName returns the resource record of the specified name.

func (Records) LookupRecordForNamePrefix

func (records Records) LookupRecordForNamePrefix(prefix string) (Record, bool)

LookupRecordForNamePrefix returns the resource record of the specified name prefix.

func (Records) LookupRecordForNameSuffix

func (records Records) LookupRecordForNameSuffix(suffix string) (Record, bool)

LookupRecordForNameSuffix returns the resource record of the specified name suffix.

func (Records) LookupRecordForType

func (records Records) LookupRecordForType(t Type) (Record, bool)

LookupRecordForType returns the resource record of the specified type.

func (Records) LookupRecordsForName

func (records Records) LookupRecordsForName(name string) Records

LookupRecordsForName returns the resource records of the specified name.

func (Records) LookupRecordsForNamePrefix

func (records Records) LookupRecordsForNamePrefix(prefix string) Records

LookupRecordsForNamePrefix returns the resource records of the specified name prefix.

func (Records) LookupRecordsForNameSuffix

func (records Records) LookupRecordsForNameSuffix(suffix string) Records

LookupRecordsForNameSuffix returns the resource records of the specified name suffix.

func (Records) LookupRecordsForType

func (records Records) LookupRecordsForType(t Type) []Record

LookupRecordForType returns the resource records of the specified type.

func (Records) LookupSRVRecords

func (records Records) LookupSRVRecords() []*SRVRecord

LookupSRVRecords returns the SRV records.

func (Records) LookupTXTRecords

func (records Records) LookupTXTRecords() []*TXTRecord

LookupTXTRecords returns the TXT records.

func (Records) String

func (records Records) String() string

String returns the string representation.

type ResourceRecord

type ResourceRecord = Record

ResourceRecord represents a resource record interface.

func NewResourceRecordWithReader

func NewResourceRecordWithReader(reader *Reader) (ResourceRecord, error)

NewResourceRecordWithReader returns a new resource record instance with the specified reader.

type ResourceRecords

type ResourceRecords = Records

ResourceRecords is a list of ResourceRecord.

type ResponseCode

type ResponseCode byte
const (
	NoError        ResponseCode = 0
	FormatError    ResponseCode = 1
	ServerFailure  ResponseCode = 2
	NameError      ResponseCode = 3
	NotImplemented ResponseCode = 4
	Refused        ResponseCode = 5
)

type SRVRecord

type SRVRecord struct {
	// contains filtered or unexported fields
}

SRVRecord represents a SRV record. RFC 2782: A DNS RR for specifying the location of services (DNS SRV). https://www.rfc-editor.org/rfc/rfc2782

func NewSRVRecord

func NewSRVRecord() *SRVRecord

NewSRVRecord returns a new SRV record instance.

func (SRVRecord) Bytes

func (r SRVRecord) Bytes() ([]byte, error)

Bytes returns the binary representation.

func (SRVRecord) Class

func (r SRVRecord) Class() Class

Class returns the resource record class.

func (SRVRecord) CompressionBytes

func (r SRVRecord) CompressionBytes() []byte

CompressionBytes returns the compression bytes.

func (*SRVRecord) Content

func (srv *SRVRecord) Content() string

Content returns a string representation to the record data.

func (SRVRecord) Data

func (r SRVRecord) Data() []byte

Data returns the record data.

func (SRVRecord) Equal

func (r SRVRecord) Equal(other ResourceRecord) bool

Equal returns true if this record is equal to the specified resource record. otherwise false.

func (SRVRecord) HasNamePrefix

func (r SRVRecord) HasNamePrefix(prefix string) bool

HasNamePrefix returns true if the resource record name has the specified prefix.

func (SRVRecord) HasNameSuffix

func (r SRVRecord) HasNameSuffix(suffix string) bool

HasNameSuffix returns true if the resource record name has the specified suffix.

func (SRVRecord) IsName

func (r SRVRecord) IsName(name string) bool

IsName returns true if the resource record name is the specified name.

func (*SRVRecord) Name

func (srv *SRVRecord) Name() string

Name returns the resource name.

func (*SRVRecord) Port

func (srv *SRVRecord) Port() uint

Port returns the resource port.

func (*SRVRecord) Priority

func (srv *SRVRecord) Priority() uint

Priority returns the resource priority.

func (*SRVRecord) Proto

func (srv *SRVRecord) Proto() string

Proto returns the protocol name.

func (SRVRecord) Reader

func (r SRVRecord) Reader() (*Reader, error)

Reader returns a record reader.

func (SRVRecord) RequestBytes

func (r SRVRecord) RequestBytes() ([]byte, error)

RequestBytes returns only the binary representation of the request fields.

func (SRVRecord) ResponseBytes

func (r SRVRecord) ResponseBytes() ([]byte, error)

ResponseBytes returns only the binary representation of the all fields.

func (*SRVRecord) Service

func (srv *SRVRecord) Service() string

Service returns the service name.

func (SRVRecord) SetClass

func (r SRVRecord) SetClass(cls Class) Record

SetClass sets the specified resource record class.

func (SRVRecord) SetCompressionBytes

func (r SRVRecord) SetCompressionBytes(b []byte)

SetCompressionBytes sets the compression bytes.

func (SRVRecord) SetData

func (r SRVRecord) SetData(b []byte) Record

SetData returns the specified record data.

func (SRVRecord) SetName

func (r SRVRecord) SetName(name string) Record

SetName sets the specified name.

func (SRVRecord) SetTTL

func (r SRVRecord) SetTTL(ttl uint) Record

SetTTL returns the specified TTL second.

func (SRVRecord) SetType

func (r SRVRecord) SetType(typ Type) Record

SetType sets the specified resource record type.

func (SRVRecord) SetUnicastResponse

func (r SRVRecord) SetUnicastResponse(enabled bool) Record

SetUnicastResponse sets the specified unicast response flag.

func (SRVRecord) TTL

func (r SRVRecord) TTL() uint

TTL returns the TTL second.

func (*SRVRecord) Target

func (srv *SRVRecord) Target() string

Target returns the resource target.

func (SRVRecord) Type

func (r SRVRecord) Type() Type

Type returns the resource record type.

func (SRVRecord) UnicastResponse

func (r SRVRecord) UnicastResponse() bool

UnicastResponse returns the unicast response flag.

func (*SRVRecord) Weight

func (srv *SRVRecord) Weight() uint

Weight returns the resource weight.

type TXTRecord

type TXTRecord struct {
	// contains filtered or unexported fields
}

TXTRecord represents a TXT record.

func NewTXTRecord

func NewTXTRecord() *TXTRecord

NewTXTRecord returns a new TXT record instance.

func (*TXTRecord) Attributes

func (txt *TXTRecord) Attributes() (Attributes, error)

Attributes returns the resource attribute strings.

func (TXTRecord) Bytes

func (r TXTRecord) Bytes() ([]byte, error)

Bytes returns the binary representation.

func (TXTRecord) Class

func (r TXTRecord) Class() Class

Class returns the resource record class.

func (TXTRecord) CompressionBytes

func (r TXTRecord) CompressionBytes() []byte

CompressionBytes returns the compression bytes.

func (*TXTRecord) Content

func (txt *TXTRecord) Content() string

Content returns a string representation to the record data.

func (TXTRecord) Data

func (r TXTRecord) Data() []byte

Data returns the record data.

func (TXTRecord) Equal

func (r TXTRecord) Equal(other ResourceRecord) bool

Equal returns true if this record is equal to the specified resource record. otherwise false.

func (*TXTRecord) HasAttribute

func (txt *TXTRecord) HasAttribute(name string) bool

HasAttribute returns true if this instance has the specified attribute.

func (TXTRecord) HasNamePrefix

func (r TXTRecord) HasNamePrefix(prefix string) bool

HasNamePrefix returns true if the resource record name has the specified prefix.

func (TXTRecord) HasNameSuffix

func (r TXTRecord) HasNameSuffix(suffix string) bool

HasNameSuffix returns true if the resource record name has the specified suffix.

func (TXTRecord) IsName

func (r TXTRecord) IsName(name string) bool

IsName returns true if the resource record name is the specified name.

func (*TXTRecord) LookupAttribute

func (txt *TXTRecord) LookupAttribute(name string) (*Attribute, bool)

LookupAttribute returns the attribute with the specified name.

func (TXTRecord) Name

func (r TXTRecord) Name() string

Name returns the resource record name.

func (TXTRecord) Reader

func (r TXTRecord) Reader() (*Reader, error)

Reader returns a record reader.

func (TXTRecord) RequestBytes

func (r TXTRecord) RequestBytes() ([]byte, error)

RequestBytes returns only the binary representation of the request fields.

func (TXTRecord) ResponseBytes

func (r TXTRecord) ResponseBytes() ([]byte, error)

ResponseBytes returns only the binary representation of the all fields.

func (TXTRecord) SetClass

func (r TXTRecord) SetClass(cls Class) Record

SetClass sets the specified resource record class.

func (TXTRecord) SetCompressionBytes

func (r TXTRecord) SetCompressionBytes(b []byte)

SetCompressionBytes sets the compression bytes.

func (TXTRecord) SetData

func (r TXTRecord) SetData(b []byte) Record

SetData returns the specified record data.

func (TXTRecord) SetName

func (r TXTRecord) SetName(name string) Record

SetName sets the specified name.

func (TXTRecord) SetTTL

func (r TXTRecord) SetTTL(ttl uint) Record

SetTTL returns the specified TTL second.

func (TXTRecord) SetType

func (r TXTRecord) SetType(typ Type) Record

SetType sets the specified resource record type.

func (TXTRecord) SetUnicastResponse

func (r TXTRecord) SetUnicastResponse(enabled bool) Record

SetUnicastResponse sets the specified unicast response flag.

func (*TXTRecord) Strings

func (txt *TXTRecord) Strings() []string

Strings returns the resource attribute strings.

func (TXTRecord) TTL

func (r TXTRecord) TTL() uint

TTL returns the TTL second.

func (TXTRecord) Type

func (r TXTRecord) Type() Type

Type returns the resource record type.

func (TXTRecord) UnicastResponse

func (r TXTRecord) UnicastResponse() bool

UnicastResponse returns the unicast response flag.

type Type

type Type uint

Type represents a message type.

const (
	A     Type = 0x0001
	NS    Type = 0x0002
	CNAME Type = 0x0005
	TXT   Type = 0x0010
	SRV   Type = 0x0021
	OPT   Type = 0x0029
	PTR   Type = 0x000C
	HINFO Type = 0x000D
	MX    Type = 0x000F
	AAAA  Type = 0x001C
	AXFR  Type = 0x00FC
	NSEC  Type = 0x002F
	ANY   Type = 0x00FF
)

func (Type) String

func (t Type) String() string

String returns the string of the type.

type Writer

type Writer struct {
	*bytes.Buffer
}

Writer represents a record writer.

func NewWriter

func NewWriter() *Writer

NewWriter returns a new writer instance.

func (*Writer) WriteBytes

func (writer *Writer) WriteBytes(v []byte) error

WriteBytes writes bytes.

func (*Writer) WriteClass

func (writer *Writer) WriteClass(v Class) error

WriteClass writes a class.

func (*Writer) WriteData

func (writer *Writer) WriteData(v []byte) error

WriteData writes data.

func (*Writer) WriteHeader

func (writer *Writer) WriteHeader(header *Header) error

WriteHeader writes a header.

func (*Writer) WriteName

func (writer *Writer) WriteName(name string) error

WriteName writes a name.

func (*Writer) WriteString

func (writer *Writer) WriteString(v string) error

WriteString writes a string with a length.

func (*Writer) WriteTTL

func (writer *Writer) WriteTTL(v uint) error

WriteTTL writes a TTL.

func (*Writer) WriteType

func (writer *Writer) WriteType(v Type) error

WriteType writes a type.

func (*Writer) WriteUint16

func (writer *Writer) WriteUint16(v uint16) error

WriteUint16 writes a uint16 value.

func (*Writer) WriteUint32

func (writer *Writer) WriteUint32(v uint32) error

WriteUint32 writes a uint32 value.

func (*Writer) WriteUint8

func (writer *Writer) WriteUint8(v uint8) error

WriteByte writes a byte value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL