packet

package
v0.0.0-...-c97f47a Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2020 License: BSD-2-Clause Imports: 5 Imported by: 1

Documentation

Overview

Provides the interfaces for implementing packet encoders and decoders. Every supported protocol implements the Packet interface as a submodule of this package (e.g. packet/ipv4, packet/tcp, ...).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(a, b Packet) bool

func Stringify

func Stringify(p Packet) string

Types

type Buffer

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

A Buffer is a variable-sized buffer of bytes with Read and Write methods. It's based on the bytes.Buffer code provided by the standard library, but implements additional convenience methods.

This is used internally to provide packet encoding and decoding, and should not be used directly.

func (*Buffer) Buffer

func (b *Buffer) Buffer() []byte

Return the whole buffer as slice.

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Return the unread portion of the buffer as slice.

func (*Buffer) Init

func (b *Buffer) Init(buf []byte)

Initialize the buffer with the given slice.

func (*Buffer) LayerBytes

func (b *Buffer) LayerBytes() []byte

Return the buffer of the current layer as slice.

func (*Buffer) LayerLen

func (b *Buffer) LayerLen() int

Return the length of the current decoded layer.

func (*Buffer) Len

func (b *Buffer) Len() int

Return the number of bytes of the unread portion of the buffer.

func (*Buffer) NewLayer

func (b *Buffer) NewLayer()

Point the layer starting offset to the current buffer offset.

func (*Buffer) Next

func (b *Buffer) Next(n int) []byte

Return a slice containing the next n bytes from the buffer, advancing the buffer as if the bytes had been returned by Read

func (*Buffer) PutUint16N

func (b *Buffer) PutUint16N(off int, data uint16)

Write data in network byte order to the specified offset relative to the start of the current layer.

func (*Buffer) Read

func (b *Buffer) Read(p []byte) (n int, err error)

Read the next len(p) bytes from the buffer or until the buffer is drained.

func (*Buffer) ReadL

func (p *Buffer) ReadL(data interface{}) error

Read structured data from the buffer in little endian byte order.

func (*Buffer) ReadLAligned

func (p *Buffer) ReadLAligned(data interface{}, width uintptr) error

Read aligned structured data from the buffer in little endian byte order.

func (*Buffer) ReadN

func (p *Buffer) ReadN(data interface{}) error

Read structured data from the buffer in network byte order.

func (*Buffer) SetOffset

func (b *Buffer) SetOffset(off int)

Manually set the buffer offset to off.

func (*Buffer) Write

func (b *Buffer) Write(p []byte) (n int, err error)

Append the contents of p to the buffer.

func (*Buffer) WriteL

func (b *Buffer) WriteL(data interface{}) error

Append the value of data to the buffer in little endian byter order.

func (*Buffer) WriteN

func (b *Buffer) WriteN(data interface{}) error

Append the value of data to the buffer in network byter order.

type Packet

type Packet interface {
	/* Return the type of the packet */
	GetType() Type

	/* Return the length of the packet including the payload if present */
	GetLength() uint16

	/* Check if the packet matches another packet */
	Equals(other Packet) bool

	/* Check if the packet is an answer to another packet */
	Answers(other Packet) bool

	/* Encode the packet and write it to the given buffer */
	Pack(out *Buffer) error

	/* Decode the packet from the given buffer */
	Unpack(in *Buffer) error

	/* Return the payload of the packet or nil */
	Payload() Packet

	/* Initialize the payload of the packet */
	SetPayload(payload Packet) error

	/* Try to guess the type of the payload */
	GuessPayloadType() Type

	/* Initialize the checksum of the packet with the given seed */
	InitChecksum(seed uint32)

	String() string
}

Packet is the interface used internally to implement packet encoding and decoding independently of the packet wire format.

type Type

type Type uint16

Type represents the protocol of a packet.

const (
	None Type = iota
	ARP
	Bluetooth /* TODO */
	Eth
	GRE /* TODO */
	ICMPv4
	ICMPv6
	IGMP  /* TODO */
	IPSec /* TODO */
	IPv4
	IPv6
	ISIS /* TODO */
	L2TP /* TODO */
	LLC
	LLDP     /* TODO */
	OSPF     /* TODO */
	RadioTap /* TODO */
	Raw
	SCTP /* TODO */
	SLL
	SNAP
	TCP
	TRILL /* TODO */
	UDP
	UDPLite /* TODO */
	VLAN
	WiFi /* TODO */
	WoL  /* TODO */
)

func LinkType

func LinkType(link_type uint32) Type

Create a new type from the given PCAP link type.

func (Type) String

func (t Type) String() string

func (Type) ToLinkType

func (pkttype Type) ToLinkType() uint32

Convert the Type to the corresponding PCAP link type.

Directories

Path Synopsis
Provides encoding and decoding for ARP packets.
Provides encoding and decoding for ARP packets.
Provides encoding and decoding for Ethernet (both EthernetII and 802.3) packets.
Provides encoding and decoding for Ethernet (both EthernetII and 802.3) packets.
Provides encoding and decoding for ICMPv4 packets.
Provides encoding and decoding for ICMPv4 packets.
Provides encoding and decoding for ICMPv6 packets.
Provides encoding and decoding for ICMPv6 packets.
Provides encoding and decoding for IPv4 packets.
Provides encoding and decoding for IPv4 packets.
Provides encoding and decoding for IPv6 packets.
Provides encoding and decoding for IPv6 packets.
Provides encoding and decoding for LLC (802.2 Logical Link Control) packets.
Provides encoding and decoding for LLC (802.2 Logical Link Control) packets.
Provides encoding and decoding for RadioTap packets.
Provides encoding and decoding for RadioTap packets.
Provides encoding and decoding for raw data packets.
Provides encoding and decoding for raw data packets.
Provides encoding and decoding for SLL (Linux cooked mode) packets.
Provides encoding and decoding for SLL (Linux cooked mode) packets.
Provides encoding and decoding for SNAP packets.
Provides encoding and decoding for SNAP packets.
Provides encoding and decoding for TCP packets.
Provides encoding and decoding for TCP packets.
Provides encoding and decoding for UDP packets.
Provides encoding and decoding for UDP packets.
Provides encoding and decoding for VLAN packets.
Provides encoding and decoding for VLAN packets.

Jump to

Keyboard shortcuts

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