packet

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package packet decodes layer two, three and four OSI model layers

Index

Constants

View Source
const (
	// EtherTypeARP is Address Resolution Protocol EtherType value
	EtherTypeARP = 0x0806

	// EtherTypeIPv4 is Internet Protocol version 4 EtherType value
	EtherTypeIPv4 = 0x0800

	// EtherTypeIPv6 is Internet Protocol Version 6 EtherType value
	EtherTypeIPv6 = 0x86DD

	// EtherTypeLACP is Link Aggregation Control Protocol EtherType value
	EtherTypeLACP = 0x8809

	// EtherTypeIEEE8021Q is VLAN-tagged frame (IEEE 802.1Q) EtherType value
	EtherTypeIEEE8021Q = 0x8100
)
View Source
const (
	// IPv4HLen is IPv4 header length size
	IPv4HLen = 20

	// IPv6HLen is IPv6 header length size
	IPv6HLen = 40

	// IANAProtoICMP is IANA Internet Control Message number
	IANAProtoICMP = 1

	// IANAProtoTCP is IANA Transmission Control number
	IANAProtoTCP = 6

	// IANAProtoUDP is IANA User Datagram number
	IANAProtoUDP = 17

	// IANAProtoIPv6ICMP is IANA Internet Control Message number for IPv6
	IANAProtoIPv6ICMP = 58
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Datalink struct {
	// SrcMAC represents source MAC address
	SrcMAC string

	// DstMAC represents destination MAC address
	DstMAC string

	// Vlan represents VLAN value
	Vlan int

	// EtherType represents upper layer type value
	EtherType uint16
}

Datalink represents layer two IEEE 802.11

type ICMP

type ICMP struct {
	// Type is ICMP type
	Type int

	// Code is ICMP subtype
	Code int

	// Rest of Header
	RestHeader []byte
}

type IPv4Header

type IPv4Header struct {
	Version  int    // protocol version
	TOS      int    // type-of-service
	TotalLen int    // packet total length
	ID       int    // identification
	Flags    int    // flags
	FragOff  int    // fragment offset
	TTL      int    // time-to-live
	Protocol int    // next protocol
	Checksum int    // checksum
	Src      string // source address
	Dst      string // destination address
}

IPv4Header represents an IPv4 header

type IPv6Header

type IPv6Header struct {
	Version      int    // protocol version
	TrafficClass int    // traffic class
	FlowLabel    int    // flow label
	PayloadLen   int    // payload length
	NextHeader   int    // next header
	HopLimit     int    // hop limit
	Src          string // source address
	Dst          string // destination address
}

IPv6Header represents an IPv6 header

type Packet

type Packet struct {
	L2 Datalink
	L3 interface{}
	L4 interface{}
	// contains filtered or unexported fields
}

Packet represents layer 2,3,4 available info

func NewPacket

func NewPacket() Packet

NewPacket constructs a packet object

func (*Packet) Decoder

func (p *Packet) Decoder(data []byte, protocol uint32) (*Packet, error)

Decoder decodes packet's layers

type TCPHeader

type TCPHeader struct {
	SrcPort    int
	DstPort    int
	DataOffset int
	Reserved   int
	Flags      int
}

TCPHeader represents TCP header

type UDPHeader

type UDPHeader struct {
	SrcPort int
	DstPort int
}

UDPHeader represents UDP header

Jump to

Keyboard shortcuts

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