packet

package
v0.0.0-...-cd4c4ab Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ARP

type ARP struct {
	HType    ARPType
	PType    EtherType
	HLen     byte
	PLen     byte
	Oper     ARPOpCode
	SourceHW net.HardwareAddr
	SourceIP netip.Addr
	DestHW   net.HardwareAddr
	DestIP   netip.Addr
	PacketBytes
}

func (ARP) GetContents

func (e ARP) GetContents() []byte

func (ARP) GetPayload

func (e ARP) GetPayload() []byte

func (ARP) Type

func (e ARP) Type() LayerType

func (*ARP) Unmarshal

func (a *ARP) Unmarshal(data []byte) error

type ARPOpCode

type ARPOpCode uint16
const (
	ARPOPCodeRequest ARPOpCode = 1
	ARPOPCodeReply   ARPOpCode = 2
)

func (ARPOpCode) String

func (i ARPOpCode) String() string

type ARPType

type ARPType uint16
const (
	// ARPTypeNetROM     ARPType = 0
	ARPTypeEther ARPType = 1
)

func (ARPType) String

func (i ARPType) String() string

type EtherType

type EtherType uint16
const (
	EtherTypeTooLow EtherType = 0x07FF

	EthernetTypeIPv4 EtherType = 0x0800
	EthernetTypeARP  EtherType = 0x0806
	EthernetTypeIPv6 EtherType = 0x86DD

	EtherTypeTooHigh EtherType = 0x86DE
)

func (EtherType) String

func (i EtherType) String() string

type Ethernet

type Ethernet struct {
	PacketBytes
	Destination  net.HardwareAddr
	Source       net.HardwareAddr
	EthernetType EtherType
}

func (Ethernet) GetContents

func (e Ethernet) GetContents() []byte

func (Ethernet) GetPayload

func (e Ethernet) GetPayload() []byte

func (Ethernet) Type

func (e Ethernet) Type() LayerType

func (*Ethernet) Unmarshal

func (e *Ethernet) Unmarshal(data []byte) error

type IPv4

type IPv4 struct {
	IHL            uint8
	DSCP           uint8
	ECN            uint8
	TotalLen       uint16
	ID             uint16
	Flags          uint8
	FragOffset     uint16
	Hops           uint8
	Proto          uint8
	HeaderChecksum uint16
	Source         netip.Addr
	Destination    netip.Addr
	// Todo: options
	PacketBytes
}

func (IPv4) GetContents

func (e IPv4) GetContents() []byte

func (IPv4) GetPayload

func (e IPv4) GetPayload() []byte

func (IPv4) Type

func (e IPv4) Type() LayerType

func (*IPv4) Unmarshal

func (p *IPv4) Unmarshal(data []byte) error

type Layer

type Layer interface {
	// Type returns the layer type.
	Type() LayerType

	// GetContents() returns the entire layer contents in bytes.
	GetContents() []byte

	// GetPayload() returns the layer payload. That is Contents()[hdrSize:]
	GetPayload() []byte
}

Layer contains a decoded layer instance, such as an Ethernet frame, or an IP packet.

type LayerType

type LayerType uint8

LayerType is a non-standard enumeration of layer instances such as Ethernet, or IPv4.

const (
	LayerTypeUnknown  LayerType = 0
	LayerTypeEthernet LayerType = 1
	LayerTypeIPv4     LayerType = 2
	LayerTypeARP      LayerType = 3
)

func (LayerType) String

func (i LayerType) String() string

type Packet

type Packet struct {
	// Link contains the link-layer representation of the packet.
	Link *Ethernet

	// Network contains the network-layer representation of the packet.
	Network Layer
}

Packet represents a raw packet flowing through the network.

func Decode

func Decode(b []byte) (Packet, error)

Decode copies the input bytes, and eagerly decodes the provided byte slice.

func PacketFromEthernet

func PacketFromEthernet(e *Ethernet) (Packet, error)

PacketFromEthernet creates a new packet from an ethernet descriptor.

type PacketBytes

type PacketBytes struct {
	// Contents contains the entire packet's bytes.
	Contents []byte

	// Payload contains the packet's payload. That is, the contents minus the
	// packet header.
	Payload []byte
}

PacketBytes ensures a coherent naming scheme for packets' internal byte slice references.

type TCP

type TCP struct {
	Payload []byte
}

func (*TCP) Unmarshal

func (e *TCP) Unmarshal(data []byte) error

Jump to

Keyboard shortcuts

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