icmp

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Overview

Package icmp provides the logic for parsing ICMP packets

Package icmp has icmp tracerouting logic

Index

Constants

View Source
const (
	// IPProtoICMP is the IP protocol number for ICMP
	// we create our own constant here because there are
	// different imports for the constant in different
	// operating systems
	IPProtoICMP = 1
)

Variables

This section is empty.

Functions

func RunICMPTraceroute

func RunICMPTraceroute(ctx context.Context, p Params) (*result.TracerouteRun, error)

RunICMPTraceroute fully executes a ICMP traceroute using the given parameters

Types

type Params

type Params struct {
	// Target is the IP:port to traceroute
	Target netip.Addr
	// ParallelParams are the standard params for parallel traceroutes
	ParallelParams common.TracerouteParallelParams
	// UseWindowsDriver controls whether to use driver-based packet capture (Windows)
	UseWindowsDriver bool
}

Params is the ICMP traceroute parameters

type Parser

type Parser interface {
	Match(header *ipv4.Header, packet []byte, localIP net.IP, localPort uint16, remoteIP net.IP, remotePort uint16, innerIdentifier uint32, packetID uint16) (net.IP, error)
	Parse(header *ipv4.Header, packet []byte) (*Response, error)
}

Parser defines the interface for parsing ICMP packets

func NewICMPTCPParser

func NewICMPTCPParser() Parser

NewICMPTCPParser creates a new ICMPParser that can parse ICMP packets with embedded TCP packets

func NewICMPUDPParser

func NewICMPUDPParser() Parser

NewICMPUDPParser creates a new ICMPParser that can parse ICMP packets with embedded UDP packets

type Response

type Response struct {
	SrcIP        net.IP
	DstIP        net.IP
	TypeCode     layers.ICMPv4TypeCode
	InnerIPID    uint16
	InnerSrcIP   net.IP
	InnerDstIP   net.IP
	InnerSrcPort uint16
	InnerDstPort uint16
	// InnerIdentifier will be populated with
	// an additional identifcation field for matching
	// received packets. For TCP packets, this is the
	// sequence number. For UDP packets, this is the
	// checksum, a uint16 cast to a uint32.
	InnerIdentifier uint32
}

Response encapsulates the data from an ICMP response packet needed for matching

func (*Response) Matches

func (i *Response) Matches(localIP net.IP, localPort uint16, remoteIP net.IP, remotePort uint16, innerIdentifier uint32, packetID uint16) bool

Matches checks if an ICMPResponse matches the expected response based on the local and remote IP, port, and identifier. In this context, identifier will either be the TCP sequence number OR the UDP checksum

type TCPParser

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

TCPParser encapsulates the data and logic for parsing ICMP packets with embedded TCP data

func (*TCPParser) Match

func (p *TCPParser) Match(header *ipv4.Header, packet []byte, localIP net.IP, localPort uint16, remoteIP net.IP, remotePort uint16, innerIdentifier uint32, packetID uint16) (net.IP, error)

Match encapsulates to logic to both parse and match an ICMP packet

func (*TCPParser) Parse

func (p *TCPParser) Parse(header *ipv4.Header, payload []byte) (*Response, error)

Parse parses an ICMP packet with embedded TCP data and returns a Response

type UDPParser

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

UDPParser encapsulates the data and logic for parsing ICMP packets with embedded UDP data

func (*UDPParser) Match

func (p *UDPParser) Match(header *ipv4.Header, packet []byte, localIP net.IP, localPort uint16, remoteIP net.IP, remotePort uint16, innerIdentifier uint32, packetID uint16) (net.IP, error)

Match encapsulates to logic to both parse and match an ICMP packet

func (*UDPParser) Parse

func (p *UDPParser) Parse(header *ipv4.Header, payload []byte) (*Response, error)

Parse parses an ICMP packet with embedded UDP data and returns a Response

Jump to

Keyboard shortcuts

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