udp

package
v0.0.0-...-f5c58d3 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2016 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidLength is an error returned when the packet length is
	// too small.
	ErrInvalidLength = errors.New("Length field is too small")

	// ErrInvalidChecksum is an error returned when the packet checksum
	// is incorrect.
	ErrInvalidChecksum = errors.New("Checksum field is incorrect")
)

Functions

This section is empty.

Types

type Header struct {
	SourcePort      uint16
	DestinationPort uint16
	Length          uint16
	Checksum        uint16
}

Header is the UDP packet header.

func NewHeader

func NewHeader(r io.Reader) (Header, error)

NewHeader reads a header from a reader.

func (Header) Write

func (h Header) Write(w io.Writer) error

Write the header to a Writer.

type Layer

type Layer interface {
	Packets(port uint16) <-chan Packet
	Send(packet Packet) error
}

Layer is an UDP layer.

func NewLayer

func NewLayer(ip ipv4.Layer) Layer

NewLayer creates a new instance of the default UDP layer.

type Packet

type Packet struct {
	Header
	Payload []byte

	// Address is either the source or destination address
	Address ipv4.Address
}

Packet is a UDP packet

func NewPacket

func NewPacket(r io.Reader) (p Packet, err error)

NewPacket reads a packet from a reader.

func (Packet) CalculateChecksum

func (p Packet) CalculateChecksum() uint16

CalculateChecksum calculates the correct checksum of the packet.

func (Packet) Write

func (p Packet) Write(w io.Writer) error

Write the packet to a Writer.

Jump to

Keyboard shortcuts

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