icmp

package
v0.0.0-...-5f133c6 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: BSD-3-Clause, BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsIPv4

func IsIPv4(address string) bool

func IsIPv6

func IsIPv6(address string) bool

Types

type Dispatcher

type Dispatcher struct {
	Socket []Socket

	Defaultv4 *IPv4Socket
	Defaultv6 *IPv6Socket

	DefaultHandler Handler
	// contains filtered or unexported fields
}

func NewDispatcher

func NewDispatcher(options ...DispatcherOption) (*Dispatcher, error)

func (*Dispatcher) Dispatch

func (pr *Dispatcher) Dispatch(dest net.Addr, message *icmp.Message) error

func (*Dispatcher) Register

func (pr *Dispatcher) Register(handler Handler, types ...icmp.Type) error

func (*Dispatcher) Run

func (pr *Dispatcher) Run()

func (*Dispatcher) Unregister

func (pr *Dispatcher) Unregister(types ...icmp.Type) error

type DispatcherOption

type DispatcherOption func(*Dispatcher) error

func AddSocket

func AddSocket(socket Socket) DispatcherOption

func ListenOn

func ListenOn(bindto string) DispatcherOption

func SetDefaultHandler

func SetDefaultHandler(handler Handler) DispatcherOption

type Handler

type Handler func(net.Addr, *icmp.Message) error

type IPProtocol

type IPProtocol int
const (
	// Protocol numbers assigned by IANA to ICMPv4 and ICMPv6.
	// https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers
	ProtocolICMPv4 IPProtocol = 1
	ProtocolICMPv6 IPProtocol = 58
)

type IPv4Socket

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

func NewIPv4Socket

func NewIPv4Socket(bindto string) (*IPv4Socket, error)

func (*IPv4Socket) Run

func (im *IPv4Socket) Run(dispatcher Handler) error

func (*IPv4Socket) SendPing

func (im *IPv4Socket) SendPing(id, sequence uint16, payload []byte, destination *net.IPAddr) error

type IPv6Socket

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

func NewIPv6Socket

func NewIPv6Socket(bindto string) (*IPv6Socket, error)

func (*IPv6Socket) Run

func (im *IPv6Socket) Run(dispatcher Handler) error

func (*IPv6Socket) SendPing

func (im *IPv6Socket) SendPing(id, sequence uint16, payload []byte, destination *net.IPAddr) error

type PingHandler

type PingHandler struct {
	Id         uint16
	Sequence   uint16
	Dispatcher *Dispatcher
	// contains filtered or unexported fields
}

func NewPingHandler

func NewPingHandler(dispatcher *Dispatcher) (*PingHandler, error)

func (*PingHandler) Allocate

func (ph *PingHandler) Allocate(handler Handler, timeout time.Duration) (uint16, error)

func (*PingHandler) Close

func (ph *PingHandler) Close() error

func (*PingHandler) Dispatch

func (ph *PingHandler) Dispatch(addr net.Addr, im *icmp.Message) error

func (*PingHandler) Run

func (ph *PingHandler) Run() error

func (*PingHandler) Send

func (ph *PingHandler) Send(payload []byte, destination *net.IPAddr, handler Handler, timeout time.Duration) error

func (*PingHandler) SendAndWait

func (ph *PingHandler) SendAndWait(payload []byte, destination *net.IPAddr, timeout time.Duration) (net.Addr, *icmp.Message, error)

type Socket

type Socket interface {
	Run(dispatcher Handler) error
	SendPing(id, sequence uint16, payload []byte, destination *net.IPAddr) error
}

func NewSocket

func NewSocket(bindto string) (Socket, error)

Listen will open a listening ICMP socket on the specified address.

bindto is the address to listen on (eg, "127.0.0.1", "::", "0.0.0.0", ...).

Jump to

Keyboard shortcuts

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