Documentation
¶
Overview ¶
Package dns deals with encoding and decoding DNS wire format.
Index ¶
- Constants
- Variables
- func DecodeRDataA(chunks [][]byte) ([]byte, error)
- func DecodeRDataAAAA(chunks [][]byte) ([]byte, error)
- func DecodeRDataCAA(p []byte) ([]byte, error)
- func DecodeRDataCNAME(data []byte, domain Name) ([]byte, error)
- func DecodeRDataMX(data []byte, domain Name) ([]byte, error)
- func DecodeRDataNS(data []byte, domain Name) ([]byte, error)
- func DecodeRDataNULL(p []byte) ([]byte, error)
- func DecodeRDataSRV(data []byte, domain Name) ([]byte, error)
- func DecodeRDataTXT(p []byte) ([]byte, error)
- func EncodeRDataA(p []byte) [][]byte
- func EncodeRDataAAAA(p []byte) [][]byte
- func EncodeRDataCAA(p []byte) []byte
- func EncodeRDataCNAME(p []byte, domain Name) ([]byte, error)
- func EncodeRDataMX(p []byte, domain Name) ([]byte, error)
- func EncodeRDataNS(p []byte, domain Name) ([]byte, error)
- func EncodeRDataNULL(p []byte) []byte
- func EncodeRDataSRV(p []byte, domain Name) ([]byte, error)
- func EncodeRDataTXT(p []byte) []byte
- func ParseRecordType(s string) (uint16, error)
- type Message
- type Name
- type Question
- type RR
Constants ¶
const ( // https://tools.ietf.org/html/rfc1035#section-3.2.2 RRTypeA = 1 RRTypeNS = 2 RRTypeCNAME = 5 RRTypeNULL = 10 RRTypeMX = 15 RRTypeTXT = 16 RRTypeAAAA = 28 RRTypeSRV = 33 RRTypeCAA = 257 // 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 RcodeServerFailure = 2 // a.k.a. SERVFAIL 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 ¶
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") // 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 DecodeRDataA ¶ added in v0.2.4
DecodeRDataA decodes multiple A record RDATA chunks back to the original payload.
func DecodeRDataAAAA ¶ added in v0.2.4
DecodeRDataAAAA decodes multiple AAAA record RDATA chunks back to the original payload.
func DecodeRDataCAA ¶ added in v0.2.8
DecodeRDataCAA decodes CAA RDATA and returns the value portion. https://datatracker.ietf.org/doc/html/rfc8659
func DecodeRDataCNAME ¶ added in v0.2.4
DecodeRDataCNAME decodes CNAME RDATA back to the original payload.
func DecodeRDataMX ¶ added in v0.2.4
DecodeRDataMX decodes MX RDATA back to the original payload.
func DecodeRDataNS ¶ added in v0.2.4
DecodeRDataNS decodes NS RDATA back to the original payload.
func DecodeRDataNULL ¶ added in v0.2.8
DecodeRDataNULL decodes NULL RDATA as a raw byte slice. https://tools.ietf.org/html/rfc1035#section-3.3.10
func DecodeRDataSRV ¶ added in v0.2.4
DecodeRDataSRV decodes SRV RDATA back to the original payload.
func DecodeRDataTXT ¶
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.
func EncodeRDataA ¶ added in v0.2.4
EncodeRDataA encodes a payload as multiple A record RDATA chunks (4 bytes each).
func EncodeRDataAAAA ¶ added in v0.2.4
EncodeRDataAAAA encodes a payload as multiple AAAA record RDATA chunks (16 bytes each).
func EncodeRDataCAA ¶ added in v0.2.8
EncodeRDataCAA encodes a slice of bytes as CAA RDATA using a fixed "issue" tag so the payload lives entirely in the value portion. https://datatracker.ietf.org/doc/html/rfc8659
func EncodeRDataCNAME ¶ added in v0.2.4
EncodeRDataCNAME encodes a payload as CNAME RDATA. https://tools.ietf.org/html/rfc1035#section-3.3.1
func EncodeRDataMX ¶ added in v0.2.4
EncodeRDataMX encodes a payload as MX RDATA: [preference:2][exchange:name]. https://tools.ietf.org/html/rfc1035#section-3.3.9
func EncodeRDataNS ¶ added in v0.2.4
EncodeRDataNS encodes a payload as NS RDATA (identical format to CNAME). https://tools.ietf.org/html/rfc1035#section-3.3.11
func EncodeRDataNULL ¶ added in v0.2.8
EncodeRDataNULL encodes a slice of bytes as NULL RDATA. https://tools.ietf.org/html/rfc1035#section-3.3.10
func EncodeRDataSRV ¶ added in v0.2.4
EncodeRDataSRV encodes a payload as SRV RDATA: [priority:2][weight:2][port:2][target:name]. https://tools.ietf.org/html/rfc2782
func EncodeRDataTXT ¶
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.
func ParseRecordType ¶ added in v0.2.4
ParseRecordType converts a record type string ("txt", "cname", "a", etc.) to the corresponding RR type constant. Returns an error for unknown types.
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 ¶
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) WireFormat ¶
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 NameFromWireFormat ¶ added in v0.2.4
NameFromWireFormat parses an uncompressed DNS name from raw bytes. It does not handle compression pointers.
func NewName ¶
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 ¶
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 ¶
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 ¶
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.
func (Name) WireFormat ¶ added in v0.2.4
WireFormat serializes a Name to uncompressed DNS wire format: a sequence of length-prefixed labels followed by a zero-length root label.