pack

package
v0.0.0-...-5abfbfe Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package pack provides utility functions to (un)pack raw data from and to the "wire"

Index

Constants

View Source
const (
	ErrOverflowUnpackUint64 = OverflowError("offset overflow unpacking uint64")
	ErrOverflowUnpackUint32 = OverflowError("offset overflow unpacking uint32")
	ErrOverflowUnpackUint16 = OverflowError("offset overflow unpacking uint16")
	ErrOverflowUnpackUint8  = OverflowError("offset overflow unpacking uint8")
	ErrOverflowPackUint32   = OverflowError("offset overflow packing uint32")
	ErrOverflowPackUint16   = OverflowError("offset overflow packing uint16")
	ErrOverflowPackUint8    = OverflowError("offset overflow packing uint8")

	ErrOverflowUnpackIPv4 = OverflowError("offset overflow unpacking IPv4 address")
	ErrOverflowUnpackIPv6 = OverflowError("offset overflow unpacking IPv6 address")
	ErrOverflowPackIPv4   = OverflowError("offset overflow packing IPv4 address")
	ErrOverfloPpackIPv6   = OverflowError("offset overflow packing IPv6 address")

	ErrOverflowUnpackString = OverflowError("offset overflow unpacking character string")
	ErrOverflowUnpackName   = OverflowError("offset overflow unpacking domain name")
)

Variables

View Source
var (
	ErrCharacterStringTooLong = errors.New("pack: character string too long")
	ErrInvalidName            = errors.New("pack: invalid name")
)

Functions

func PackCharacterString

func PackCharacterString(characters string, buf []byte, offset int) (int, error)

See https://datatracker.ietf.org/doc/html/rfc1035#section-3.3 <character-string>

func PackDomainName

func PackDomainName(name string, buf []byte, offset int, comp compression.Map) (int, error)

PackDomainName packs a name into buf and returns the new offset.

func PackEDNSOptions

func PackEDNSOptions(options []edns.Option, buf []byte, offset int) (int, error)

PackEDNSOptions packs all EDNS options into buf and returns the new offset

func PackIPAddress

func PackIPAddress(addr netip.Addr, buf []byte, offset int) (int, error)

PackIPAddress packs a IP address (v4 or v6) into buf and returns the new offset

func PackUint16

func PackUint16(data uint16, buf []byte, offset int) (int, error)

PackUint16 packs a uint16 (two octets) into buf and returns the new offset

func PackUint32

func PackUint32(data uint32, buf []byte, offset int) (int, error)

PackUint32 ppacks a uint32 (four octets) into buff and returns the new offset

func PackUint8

func PackUint8(data uint8, buf []byte, offset int) (int, error)

PackUint8 packs a uint8 (one octet) into buf and returns the new offset

func UnpackCharacterString

func UnpackCharacterString(data []byte, offset int) (string, int, error)

UnpackCharacterString unpacks a character string. See https://datatracker.ietf.org/doc/html/rfc1035#section-3.3 <character-string>

func UnpackDomainName

func UnpackDomainName(data []byte, offset int) (string, int, error)

UnpackDomainName unoacks a domain name in a DNS question or in a RR header

func UnpackEDNSOptions

func UnpackEDNSOptions(data []byte, offset int, rdlen uint16) ([]edns.Option, int, error)

func UnpackIPv4Address

func UnpackIPv4Address(data []byte, offset int) (netip.Addr, int, error)

UnpackIPv4Address unpacks a IPv4 address and returns the new offset

func UnpackIPv6Address

func UnpackIPv6Address(data []byte, offset int) (netip.Addr, int, error)

UnpackIPv6Address unpacks a IPv6 address and returns the new offset

func UnpackUint16

func UnpackUint16(data []byte, offset int) (uint16, int, error)

UnpackUint16 unpacks a uint16 from data at offset and returns the new offset

func UnpackUint32

func UnpackUint32(data []byte, offset int) (uint32, int, error)

UnpackUint32 unpacks a uint32 from data at offset and returns the new offset

func UnpackUint64

func UnpackUint64(data []byte, offset int) (uint64, int, error)

UnpackUint64 unpacks a uint64 from data at offset and returns the new offset

func UnpackUint8

func UnpackUint8(data []byte, offset int) (uint8, int, error)

UnpackUint8 unpacks a uint8 from data at offset and returns the new offset

Types

type OverflowError

type OverflowError string

func (OverflowError) Error

func (e OverflowError) Error() string

Jump to

Keyboard shortcuts

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