pinger

package
v0.0.0-...-404304f Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

This file code is based on https://github.com/go-ping/ping

Index

Constants

View Source
const (
	ProtocolICMP     = 1
	ProtocolIPv6ICMP = 58
)
View Source
const (
	ProtocolIpv4 = ProtocolVersion(4)
	ProtocolIpv6 = ProtocolVersion(6)
)

Variables

View Source
var (
	ErrInvalidConn = errors.New("invalid connection")
	ErrInvalidAddr = errors.New("invalid address")
)

Functions

This section is empty.

Types

type IcmpStats

type IcmpStats struct {
	Valid   bool
	RTT     time.Duration
	Tracker int64
	Seq     uint16
}

type Packet

type Packet struct {
	Proto ProtocolVersion // protocol: 4=IPv4, 6=IPv6
	Bytes []byte          // Marshaled package
	Len   int             // length of package
	TTL   int             // TTL of the packet (currently unused)
	Addr  netip.Addr      // Dest address for sending package and Src address ro received
}

type Pinger

type Pinger struct {
	// Size of packet being sent
	Size int

	// Tracker: Used to uniquely identify packet when non-priviledged
	Tracker int64
	// contains filtered or unexported fields
}

Pinger represents a packet sender.

func NewPinger

func NewPinger(network, protocol string, id uint16) *Pinger

NewPinger returns a new Pinger instance

func (*Pinger) ParsePacket

func (p *Pinger) ParsePacket(recv *Packet) IcmpStats

func (*Pinger) PrepareICMP

func (p *Pinger) PrepareICMP(addr netip.Addr, seq uint16) (*Packet, error)

func (*Pinger) Privileged

func (p *Pinger) Privileged() bool

Privileged returns whether pinger is running in privileged mode.

func (*Pinger) RecvICMP

func (p *Pinger) RecvICMP(proto ProtocolVersion) IcmpStats

func (*Pinger) RecvPacket

func (p *Pinger) RecvPacket(proto ProtocolVersion) (*Packet, error)

func (*Pinger) SendICMP

func (p *Pinger) SendICMP(addr netip.Addr, sequence uint16) error

func (*Pinger) SendPacket

func (p *Pinger) SendPacket(pkt *Packet) error

func (*Pinger) SetConns

func (p *Pinger) SetConns(c4 *icmp.PacketConn, c6 *icmp.PacketConn)

SetConns setups IPv4 and IPv6 connections to pinger

func (*Pinger) SetPrivileged

func (p *Pinger) SetPrivileged(privileged bool)

SetPrivileged sets the type of ping pinger will send. false means pinger will send an "unprivileged" UDP ping. true means pinger will send a "privileged" raw ICMP ping. NOTE: setting to true requires that it be run with super-user privileges.

type ProtocolVersion

type ProtocolVersion int

Jump to

Keyboard shortcuts

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