fixture

package
v0.0.0-...-f1cd0c2 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package fixture serve as unittest sample for basic packet encode/decode

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checksum

type Checksum uint16

Checksum conversion so it can display in hex

func (Checksum) String

func (c Checksum) String() string

type EtherType

type EtherType uint16

EtherType custom function for String()

func (EtherType) String

func (t EtherType) String() string

type EthernetII

type EthernetII struct {
	Source Mac
	Dest   Mac
	Type   EtherType
	Body   interface{}
}

EthernetII ethernet frame

func (EthernetII) InstanceFor

func (e EthernetII) InstanceFor(fieldname string) interface{}

InstanceFor return the Body struct pointer for conversion

type IPProtocol

type IPProtocol uint8

IPProtocol protocol type

func (IPProtocol) String

func (p IPProtocol) String() string

type IPv4

type IPv4 struct {
	Version        uint8 `packet:"length=4b"`
	IHL            uint8 `packet:"length=4b"`
	DSCP           uint8 `packet:"length=6b"`
	ECN            uint8 `packet:"length=2b"`
	Length         uint16
	ID             uint16
	Flags          IPv4Flag `packet:"length=3b"`
	FragmentOffset uint16   `packet:"length=13b"`
	TTL            uint8
	Protocol       IPProtocol
	Checksum       Checksum
	Source         net.IP `packet:"length=4B"`
	Dest           net.IP `packet:"length=4B"`
	Options        []byte `packet:"lengthfor"`
	Body           interface{}
}

IPv4 packet

func (IPv4) InstanceFor

func (ip IPv4) InstanceFor(fieldname string) interface{}

InstanceFor returns the Body struct pointer for conversion

func (IPv4) LengthFor

func (ip IPv4) LengthFor(fieldname string) uint64

LengthFor returns the length in bytes for the provided field

type IPv4Flag

type IPv4Flag uint8

IPv4Flag IP flags

const (
	MFrag IPv4Flag = 1 << iota
	DFrag
	Reserved
)

func (IPv4Flag) String

func (f IPv4Flag) String() string

type Mac

type Mac [6]byte

Mac pretty print for mac-address

func (Mac) String

func (m Mac) String() string

type PacketData

type PacketData []byte

PacketData raw bytes for the packet

type Pcap

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

Pcap helps with reading packet from pcap format

func OpenPCAP

func OpenPCAP(file string) (*Pcap, error)

OpenPCAP read file as gopacket.PacketSource

func (*Pcap) PacketData

func (p *Pcap) PacketData() chan PacketData

PacketData use channel so it's possible to do range

type Port

type Port uint16

Port alias for uint16, so we can use it with constants

type TCP

type TCP struct {
	Source        Port
	Dest          Port
	Sequence      uint32
	Ack           uint32
	DataOffset    uint8   `packet:"length=4b"`
	Flags         TCPFlag `packet:"length=12b"`
	WindowSize    uint16
	Checksum      Checksum
	UrgentPointer uint16
	Options       []byte `packet:"lengthfor"`
	Body          interface{}
}

TCP message

func (TCP) InstanceFor

func (tcp TCP) InstanceFor(fieldname string) interface{}

InstanceFor return the Body struct pointer for conversion

func (TCP) LengthFor

func (tcp TCP) LengthFor(fieldname string) uint64

LengthFor

type TCPFlag

type TCPFlag uint16

TCPFlag is 9 bits

const (
	FIN TCPFlag = 1 << iota
	SYN
	RST
	PSH
	ACK
	URG
	ECE
	CWR
	NS
)

func (TCPFlag) String

func (f TCPFlag) String() string

type VLAN

type VLAN struct {
	Priority uint8 `packet:"length=3b"`
	DEI      bool
	ID       uint16 `packet:"length=12b"`
	Type     EtherType
	Body     interface{}
}

VLAN virtual-LAN

func (VLAN) InstanceFor

func (v VLAN) InstanceFor(fieldname string) interface{}

InstanceFor return the Body struct pointer for conversion

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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