dns

package
v0.7.10 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package dns deals with encoding and decoding DNS wire format.

Index

Constants

View Source
const (
	// https://tools.ietf.org/html/rfc1035#section-3.2.2
	RRTypeTXT = 16
	// https://tools.ietf.org/html/rfc6891#section-6.1.1
	RRTypeOPT = 41

	// https://tools.ietf.org/html/rfc1035#section-3.2.4
	ClassIN = 1

	// https://tools.ietf.org/html/rfc1035#section-4.1.1
	RcodeNoError        = 0 // a.k.a. NOERROR
	RcodeFormatError    = 1 // a.k.a. FORMERR
	RcodeNameError      = 3 // a.k.a. NXDOMAIN
	RcodeNotImplemented = 4 // a.k.a. NOTIMPL
	// https://tools.ietf.org/html/rfc6891#section-9
	ExtendedRcodeBadVers = 16 // a.k.a. BADVERS
)

Variables

View Source
var (
	// ErrZeroLengthLabel is the error returned for names that contain a
	// zero-length label, like "example..com".
	ErrZeroLengthLabel = errors.New("name contains a zero-length label")

	// ErrLabelTooLong is the error returned for labels that are longer than
	// 63 octets.
	ErrLabelTooLong = errors.New("name contains a label longer than 63 octets")

	// ErrNameTooLong is the error returned for names whose encoded
	// representation is longer than 255 octets.
	ErrNameTooLong = errors.New("name is longer than 255 octets (try using a shorter base domain?)")

	// ErrReservedLabelType is the error returned when reading a label type
	// prefix whose two most significant bits are not 00 or 11.
	ErrReservedLabelType = errors.New("reserved label type")

	// ErrTooManyPointers is the error returned when reading a compressed
	// name that has too many compression pointers.
	ErrTooManyPointers = errors.New("too many compression pointers")

	// ErrTrailingBytes is the error returned when bytes remain in the parse
	// buffer after parsing a message.
	ErrTrailingBytes = errors.New("trailing bytes after message")

	// ErrIntegerOverflow is the error returned when trying to encode an
	// integer greater than 65535 into a 16-bit field.
	ErrIntegerOverflow = errors.New("integer overflow")
)

Functions

func DecodeRDataTXT

func DecodeRDataTXT(p []byte) ([]byte, error)

DecodeRDataTXT decodes TXT-DATA (as found in the RDATA for a resource record with TYPE=TXT) as a raw byte slice, by concatenating all the <character-string>s it contains.

https://tools.ietf.org/html/rfc1035#section-3.3.14

func EncodeRDataTXT

func EncodeRDataTXT(p []byte) []byte

EncodeRDataTXT encodes a slice of bytes as TXT-DATA, as appropriate for the RDATA of a resource record with TYPE=TXT. No length restriction is enforced here; that must be checked at a higher level.

https://tools.ietf.org/html/rfc1035#section-3.3.14

Types

type Message

type Message struct {
	ID    uint16
	Flags uint16

	Question   []Question
	Answer     []RR
	Authority  []RR
	Additional []RR
}

Message represents a DNS message.

https://tools.ietf.org/html/rfc1035#section-4.1

func MessageFromWireFormat

func MessageFromWireFormat(buf []byte) (Message, error)

MessageFromWireFormat parses a message from buf and returns a Message object. It returns ErrTrailingBytes if there are bytes remaining in buf after parsing is done.

func (*Message) Opcode

func (message *Message) Opcode() uint16

Opcode extracts the OPCODE part of the Flags field.

https://tools.ietf.org/html/rfc1035#section-4.1.1

func (*Message) Rcode

func (message *Message) Rcode() uint16

Rcode extracts the RCODE part of the Flags field.

https://tools.ietf.org/html/rfc1035#section-4.1.1

func (*Message) WireFormat

func (message *Message) WireFormat() ([]byte, error)

WireFormat encodes a Message as a slice of bytes in DNS wire format. It returns ErrIntegerOverflow if the number of entries in any section, or the length of the data in any resource record, does not fit in 16 bits.

type Name

type Name [][]byte

Name represents a domain name, a sequence of labels each of which is 63 octets or less in length.

https://tools.ietf.org/html/rfc1035#section-3.1

func NewName

func NewName(labels [][]byte) (Name, error)

NewName returns a Name from a slice of labels, after checking the labels for validity. Does not include a zero-length label at the end of the slice.

func ParseName

func ParseName(s string) (Name, error)

ParseName returns a new Name from a string of labels separated by dots, after checking the name for validity. A single dot at the end of the string is ignored.

func (Name) String

func (name Name) String() string

String returns a reversible string representation of name. Labels are separated by dots, and any bytes in a label that are outside the set [0-9A-Za-z-] are replaced with a \xXX hex escape sequence.

func (Name) TrimSuffix

func (name Name) TrimSuffix(suffix Name) (Name, bool)

TrimSuffix returns a Name with the given suffix removed, if it was present. The second return value indicates whether the suffix was present. If the suffix was not present, the first return value is nil.

type Question

type Question struct {
	Name  Name
	Type  uint16
	Class uint16
}

Question represents an entry in the question section of a message.

https://tools.ietf.org/html/rfc1035#section-4.1.2

type RR

type RR struct {
	Name  Name
	Type  uint16
	Class uint16
	TTL   uint32
	Data  []byte
}

RR represents a resource record.

https://tools.ietf.org/html/rfc1035#section-4.1.3

Jump to

Keyboard shortcuts

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