packet

package
v0.0.0-...-7cefcde Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assemble

func Assemble(p ParsedPacket, max int) ([]byte, error)

Assemble returns a possibly truncated payload for a ParsedPacket. Setting max to a negative value disables truncation.

func EncodeName

func EncodeName(n Namelabel) (payload []byte)

EncodeName encodes a namelabel into the DNS on-wire format: <strlen1><rawstr1><strlen2><rawstr2>

func ParseSoaTtl

func ParseSoaTtl(buf []byte) uint32

Types

type EdnsAttribute

type EdnsAttribute struct {
	Code uint16
	Data []byte
}

type EdnsRecord

type EdnsRecord struct {
	// Whether or not EDNS data is present.
	Present bool
	Version uint8

	UdpPayloadSize uint16
	FlagDnssecOk   bool
	Attributes     []EdnsAttribute
	// contains filtered or unexported fields
}

type Namelabel

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

String array typed to describe DNS labels

func NewNamelabel

func NewNamelabel(name []string) Namelabel

func NewNamelabelString

func NewNamelabelString(str string) Namelabel

NewNamelabelString returns a new absolute namelabel from given string.

func ParseName

func ParseName(buf []byte) (Namelabel, error)

func (Namelabel) Equals

func (l Namelabel) Equals(x Namelabel) bool

Equals returns true if two namelabels are equal. This function is case sensitive, call ToLower() on both if you do not care about case sensitivity.

func (Namelabel) IsChildOf

func (l Namelabel) IsChildOf(parent Namelabel) bool

Returns true if given namelabel is a child of *parent

func (Namelabel) Len

func (l Namelabel) Len() int

Returs the number of labels in the list (1 == .)

func (Namelabel) PoppedLabel

func (l Namelabel) PoppedLabel(n int) Namelabel

Pops a label from the label list, walking the hierarchy

func (Namelabel) String

func (l Namelabel) String() string

func (Namelabel) ToLower

func (l Namelabel) ToLower() Namelabel

ToLower returns a lowercased version of the namelabel.

type ParsedPacket

type ParsedPacket struct {
	Header      ParsedPacketHeader
	Questions   []QuestionFormat
	Answers     []ResourceRecordFormat
	Nameservers []ResourceRecordFormat
	Additionals []ResourceRecordFormat
	Edns        EdnsRecord
}

A fully parsed DNS packet

func Parse

func Parse(buf []byte) (*ParsedPacket, error)

type ParsedPacketHeader

type ParsedPacketHeader struct {
	Id              uint16 // Id of this query
	Response        bool   // `true' if this is a response (qr)
	Opcode          uint8  // The RFC1035 opcode of this query (usually OP_QUERY)
	Authoritative   bool   // `true' if we have authorative data in the reply
	Truncated       bool   // `true' if the query was truncated and might be re-done using TCP or EDNS
	RecDesired      bool   // `true' if the client asked us to resolve recursively
	RecAvailable    bool   // indicates if the host generating this reply is willing to do recursive queries
	ResponseCode    uint16 // RFC1035 or EDNS response code, such as NXDOMAIN
	QuestionCount   uint16 // Number of questions in this packet
	AnswerCount     uint16 // Number of items in the answer section
	NameserverCount uint16 // Number of items in the NS section
	AdditionalCount uint16 // Number of items in the additional section
}

The parsed representation of a DNS header

type QuestionFormat

type QuestionFormat struct {
	Name  Namelabel
	Type  uint16
	Class uint16
}

Question section of the DNS packet

type ResourceRecordFormat

type ResourceRecordFormat struct {
	Name  Namelabel
	Type  uint16
	Class uint16
	Ttl   uint32
	Data  []byte // note: this is RAW data!
}

RR section of a DNS packet

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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