icmpx

package module
v0.0.0-...-34b109a Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: MIT Imports: 15 Imported by: 1

README

icmpx Test Status Go Reference Go Report Card

Package icmpx provides low-level ICMPv4 (IPPROTO_ICMP) and ICMPv6 (IPPROTO_ICMPV6) raw socket support for Linux. MIT Licensed.

Documentation

Overview

Package icmpx provides low-level ICMPv4 (IPPROTO_ICMP) and ICMPv6 (IPPROTO_ICMPV6) raw socket support for Linux.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn interface {
	// Close closes the underlying socket.
	io.Closer

	// ReadFrom reads an ICMP message and returns the sender's IP address.
	ReadFrom(ctx context.Context) (*icmp.Message, netip.Addr, error)

	// WriteTo writes an ICMP message to a destination IP address.
	WriteTo(ctx context.Context, msg *icmp.Message, dst netip.Addr) error
}

A Conn allows reading and writing ICMPv4/6 messages, depending on the concrete type of Conn.

type IPv4Config

type IPv4Config struct {
	// Filter applies an optional ICMPv4 filter to an IPv4Conn's underlying
	// socket before bind(2) is called, ensuring that no packets will be
	// received which do not match the filter.
	//
	// If nil, no ICMPv4 filter is applied.
	Filter *IPv4Filter
}

An IPv4Config configures an IPv4Conn.

type IPv4Conn

type IPv4Conn struct {
	// IP is the chosen IPv4 bind address for ICMPv4 communication.
	IP netip.Addr
	// contains filtered or unexported fields
}

An IPv4Conn allows reading and writing ICMPv4 data on a network interface.

func ListenIPv4

func ListenIPv4(ifi *net.Interface, cfg IPv4Config) (*IPv4Conn, error)

ListenIPv4 binds an ICMPv4 socket on the specified network interface.

func (*IPv4Conn) Close

func (c *IPv4Conn) Close() error

Close closes the underlying socket.

func (*IPv4Conn) ReadFrom

func (c *IPv4Conn) ReadFrom(ctx context.Context) (*icmp.Message, netip.Addr, error)

ReadFrom reads an ICMPv4 message and returns the sender's IPv4 address.

func (*IPv4Conn) SetTOS

func (c *IPv4Conn) SetTOS(tos int) error

SetTOS sets the IPv4 Type of Service (ToS) field for outgoing packets.

func (*IPv4Conn) WriteTo

func (c *IPv4Conn) WriteTo(ctx context.Context, msg *icmp.Message, dst netip.Addr) error

WriteTo writes an ICMPv4 message to a destination IPv4 address.

type IPv4Filter

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

An IPv4Filter creates an ICMPv4 filter which may be attached to an IPv4Conn.

func IPv4AllowOnly

func IPv4AllowOnly(types ...ipv4.ICMPType) *IPv4Filter

IPv4AllowOnly constructs an IPv4Filter which only permits the specified ICMPv4 types. All other ICMPv4 traffic is filtered out.

func (*IPv4Filter) Accept

func (f *IPv4Filter) Accept(typ ipv4.ICMPType)

Accept accepts an ICMPv4 type using the filter.

func (*IPv4Filter) Block

func (f *IPv4Filter) Block(typ ipv4.ICMPType)

Block blocks an ICMPv4 type using the filter.

func (*IPv4Filter) SetAll

func (f *IPv4Filter) SetAll(block bool)

SetAll either blocks or allows all ICMPv4 types on the filter depending on the input value.

func (*IPv4Filter) WillBlock

func (f *IPv4Filter) WillBlock(typ ipv4.ICMPType) bool

WillBlock reports whether a given ICMPv4 type will be blocked by the filter.

type IPv6Config

type IPv6Config struct {
	// Filter applies an optional ICMPv6 filter to an IPv6Conn's underlying
	// socket before bind(2) is called, ensuring that no packets will be
	// received which do not match the filter.
	//
	// If nil, no ICMPv6 filter is applied.
	Filter *IPv6Filter
}

An IPv6Config configures an IPv6Conn.

type IPv6Conn

type IPv6Conn struct {
	// IP is the chosen IPv6 bind address for ICMPv6 communication.
	IP netip.Addr
	// contains filtered or unexported fields
}

An IPv6Conn allows reading and writing ICMPv6 data on a network interface.

func ListenIPv6

func ListenIPv6(ifi *net.Interface, cfg IPv6Config) (*IPv6Conn, error)

ListenIPv6 binds an ICMPv6 socket on the specified network interface.

func (*IPv6Conn) Close

func (c *IPv6Conn) Close() error

Close closes the underlying socket.

func (*IPv6Conn) ReadFrom

func (c *IPv6Conn) ReadFrom(ctx context.Context) (*icmp.Message, netip.Addr, error)

ReadFrom reads an ICMPv6 message and returns the sender's IPv6 address.

func (*IPv6Conn) SetTrafficClass

func (c *IPv6Conn) SetTrafficClass(tc int) error

SetTrafficClass sets the IPv6 Traffic Class field for outgoing packets.

func (*IPv6Conn) WriteTo

func (c *IPv6Conn) WriteTo(ctx context.Context, msg *icmp.Message, dst netip.Addr) error

WriteTo writes an ICMPv6 message to a destination IPv6 address.

type IPv6Filter

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

An IPv6Filter creates an ICMPv6 filter which may be attached to an IPv6Conn.

func IPv6AllowOnly

func IPv6AllowOnly(types ...ipv6.ICMPType) *IPv6Filter

IPv6AllowOnly constructs an IPv6Filter which only permits the specified ICMPv6 types. All other ICMPv6 traffic is filtered out.

func (*IPv6Filter) Accept

func (f *IPv6Filter) Accept(typ ipv6.ICMPType)

Accept accepts an ICMPv6 type using the filter.

func (*IPv6Filter) Block

func (f *IPv6Filter) Block(typ ipv6.ICMPType)

Block blocks an ICMPv6 type using the filter.

func (*IPv6Filter) SetAll

func (f *IPv6Filter) SetAll(block bool)

SetAll either blocks or allows all ICMPv6 types on the filter depending on the input value.

func (*IPv6Filter) WillBlock

func (f *IPv6Filter) WillBlock(typ ipv6.ICMPType) bool

WillBlock reports whether a given ICMPv6 type will be blocked by the filter.

Directories

Path Synopsis
Package echo implements an ICMPv4/6 echo client for performing ping operations on destination hosts.
Package echo implements an ICMPv4/6 echo client for performing ping operations on destination hosts.

Jump to

Keyboard shortcuts

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