packet

package
v0.97.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EchoReply   uint8 = 0x00
	EchoRequest uint8 = 0x08
)
View Source
const (
	TCPSyn    uint8 = 0x02
	TCPAck    uint8 = 0x10
	TCPSynAck uint8 = TCPSyn | TCPAck
)
View Source
const IPAny = IP(0)
View Source
const MIN_FRAG = 60 + 20 // max IPv4 header + basic TCP header

RFC1858: prevent overlapping fragment attacks.

Variables

This section is empty.

Functions

func GenICMP

func GenICMP(srcIP, dstIP IP, ipid uint16, icmpType uint8, icmpCode uint8, payload []byte) []byte

func Hexdump

func Hexdump(b []byte) string

Types

type IP

type IP uint32

func NewIP

func NewIP(b net.IP) IP

func (*IP) MarshalJSON

func (ipp *IP) MarshalJSON() ([]byte, error)

func (IP) String

func (ip IP) String() string

func (*IP) UnmarshalJSON

func (ipp *IP) UnmarshalJSON(b []byte) error

type IPProto

type IPProto int
const (
	Junk IPProto = iota
	Fragment
	ICMP
	UDP
	TCP
)

func (IPProto) String

func (p IPProto) String() string

type QDecode

type QDecode struct {
	IPProto  IPProto // IP subprotocol (UDP, TCP, etc)
	SrcIP    IP      // IP source address
	DstIP    IP      // IP destination address
	SrcPort  uint16  // TCP/UDP source port
	DstPort  uint16  // TCP/UDP destination port
	TCPFlags uint8   // TCP flags (SYN, ACK, etc)
	// contains filtered or unexported fields
}

func (*QDecode) Decode

func (q *QDecode) Decode(b []byte)

An extremely simple packet decoder for basic IPv4 packet types. It extracts only the subprotocol id, IP addresses, and (if any) ports, and shouldn't need any memory allocation.

func (*QDecode) EchoRespond

func (q *QDecode) EchoRespond() []byte

func (*QDecode) IsEchoRequest

func (q *QDecode) IsEchoRequest() bool

For a packet that has already been decoded, check if it's an IPv4 ICMP Echo Request.

func (*QDecode) IsTCPSyn

func (q *QDecode) IsTCPSyn() bool

For a decoded TCP packet, return true if it's a TCP SYN packet (ie. the first packet in a new connection).

func (QDecode) String

func (q QDecode) String() string

func (*QDecode) Sub

func (q *QDecode) Sub(begin, n int) []byte

Returns a subset of the IP subprotocol section.

func (*QDecode) Trim

func (q *QDecode) Trim() []byte

For a packet that is known to be IPv4, trim the buffer to its IPv4 length. Sometimes packets arrive from an interface with extra bytes on the end. This removes them.

Jump to

Keyboard shortcuts

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