ip

package
v0.0.0-...-926f593 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UDPHeaderLen defines the length of the UDP datagram header.
	UDPHeaderLen = 8
)

Variables

View Source
var (
	ErrorTruncated = errors.New("Truncated packet")
	ErrorInvalid   = errors.New("Invalid packet")
	ErrorChecksum  = errors.New("Invalid checksum")
)

IP errors.

Functions

func Checksum

func Checksum(data []byte) uint16

Checksum computes the IP checksum for the data.

func ICMPv4Response

func ICMPv4Response(packet gopacket.Packet, icmp *layers.ICMPv4) (
	[]byte, error)

ICMPv4Response creates an ICMPv4 response packet.

Types

type IPv4

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

IPv4 implements a parsed IPv4 packet.

func (*IPv4) Copy

func (p *IPv4) Copy() Packet

Copy creates an independent copy of the packet.

func (*IPv4) Data

func (p *IPv4) Data() []byte

Data returns the packet data.

func (*IPv4) Dst

func (p *IPv4) Dst() net.IP

Dst returns the packet destination IP address.

func (*IPv4) Flags

func (p *IPv4) Flags() int8

Flags returns the packet flags.

func (*IPv4) ID

func (p *IPv4) ID() uint16

ID returns the packet ID.

func (*IPv4) Marshal

func (p *IPv4) Marshal() []byte

Marshal encodes the packet into binary data.

func (*IPv4) Offset

func (p *IPv4) Offset() uint16

Offset returns the packet fragmentation offset.

func (*IPv4) Protocol

func (p *IPv4) Protocol() Protocol

Protocol returns hte packet IP protocol.

func (*IPv4) PseudoHeader

func (p *IPv4) PseudoHeader() []byte

PseudoHeader returns the IP packet pseudo header.

func (*IPv4) SetData

func (p *IPv4) SetData(data []byte)

SetData sets the packet data.

func (*IPv4) SetDst

func (p *IPv4) SetDst(dst net.IP)

SetDst sets the packet destination IP address.

func (*IPv4) SetSrc

func (p *IPv4) SetSrc(src net.IP)

SetSrc sets the packet source IP address.

func (*IPv4) Src

func (p *IPv4) Src() net.IP

Src returns the packet source IP address.

func (*IPv4) String

func (p *IPv4) String() string

func (*IPv4) Swap

func (p *IPv4) Swap()

Swap swaps packet source and destination IP addresses.

func (*IPv4) TOS

func (p *IPv4) TOS() int

TOS returns the packet type-of-service value.

func (*IPv4) TTL

func (p *IPv4) TTL() uint8

TTL returns the packet TTL.

func (*IPv4) Version

func (p *IPv4) Version() int

Version returns the IP version.

type Packet

type Packet interface {
	Copy() Packet

	// Swap swaps source and destination IP addresses.
	Swap()
	Marshal() []byte
	PseudoHeader() []byte
	Version() int
	TOS() int
	ID() uint16
	Flags() int8
	Offset() uint16
	TTL() uint8
	Protocol() Protocol
	Src() net.IP
	SetSrc(src net.IP)
	Dst() net.IP
	SetDst(dst net.IP)
	Data() []byte
	SetData(data []byte)
}

Packet implements an IP packet.

func Parse

func Parse(data []byte) (Packet, error)

Parse parses an IP packet.

func ParseIPv4

func ParseIPv4(data []byte) (Packet, error)

ParseIPv4 parses the IPv4 packet.

type Protocol

type Protocol uint8

Protocol defines IP protocol numbers.

const (
	ProtoICMP Protocol = 1
	ProtoTCP  Protocol = 6
	ProtoUDP  Protocol = 17
)

Supported IP protocol numbers.

func (Protocol) String

func (p Protocol) String() string

type UDP

type UDP struct {
	IP   Packet
	Src  uint16
	Dst  uint16
	Data []byte
}

UDP implements and UDP datagram.

func ParseUDP

func ParseUDP(ip Packet) (*UDP, error)

ParseUDP parses the UPD datagram.

func ParseUDPPacket

func ParseUDPPacket(data []byte) (*UDP, error)

ParseUDPPacket parses the UDP packet.

func (*UDP) Marshal

func (udp *UDP) Marshal() []byte

Marshal encodes the UDP datagram into binary data.

func (*UDP) Swap

func (udp *UDP) Swap()

Swap swaps the datagram source and destination addresses and ports.

Jump to

Keyboard shortcuts

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