packet

package
v0.99.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ICMPEchoReply    = 0x00
	ICMPEchoRequest  = 0x08
	ICMPUnreachable  = 0x03
	ICMPTimeExceeded = 0x0b
)

ICMP types.

View Source
const (
	TCPSyn    = 0x02
	TCPAck    = 0x10
	TCPSynAck = TCPSyn | TCPAck
)

Variables

This section is empty.

Functions

func GenICMP

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

GenICMP returns the bytes of an ICMP packet. If payload is too short or too long, it returns nil.

func Hexdump

func Hexdump(b []byte) string

Types

type IP

type IP uint32

IP is an IPv4 address.

func NewIP

func NewIP(b net.IP) IP

NewIP converts a standard library IP address into an IP. It panics if b is not an IPv4 address.

func (IP) String

func (ip IP) String() string

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

EchoResponse returns an IPv4 ICMP echo reply to the request in q.

func (*QDecode) IsEchoRequest

func (q *QDecode) IsEchoRequest() bool

IsEchoRequest reports whether q is an IPv4 ICMP Echo Request.

func (*QDecode) IsEchoResponse added in v0.98.1

func (q *QDecode) IsEchoResponse() bool

IsEchoRequest reports whether q is an IPv4 ICMP Echo Response.

func (*QDecode) IsError added in v0.98.1

func (q *QDecode) IsError() bool

IsError reports whether q is an IPv4 ICMP "Error" packet.

func (*QDecode) IsTCPSyn

func (q *QDecode) IsTCPSyn() bool

IsTCPSyn reports whether q is a TCP SYN packet (i.e. 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

Trim trims 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