ping

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeout      int  = 3
	DefaultNumPings     int  = 3
	Privileged          bool = false
	DefaultBackoffLimit int  = 3
	DefaultCPing        int  = 3
	DefaultDelayRetry   int  = 15
	IncDelayRetry       int  = 5
	MaxInt16            int  = 32767
	PacketMaxSize       int  = 1500
)

Variables

View Source
var DefaultConfig = Config{
	Timeout:      DefaultTimeout,
	PingNum:      DefaultNumPings,
	Privileged:   Privileged,
	BackoffLimit: DefaultBackoffLimit,
	Cping:        DefaultCPing,
	DelayRetry:   DefaultDelayRetry,
}
View Source
var ErrInvalidIP = errors.New("ip is not ipv4")

Functions

func IPStringToIPv4

func IPStringToIPv4(ip string) (net.IP, error)

func WithConfig

func WithConfig(config Config) func(*Ping)

func WithNumPings

func WithNumPings(numPings int) func(*Ping)

func WithPrivileged

func WithPrivileged(privileged bool) func(*Ping)

Types

type Config

type Config struct {
	// Timeout socket read/write timeout
	Timeout int
	// DefaultBackoffLimit is the number of time to read before the read op
	// is considered as a failed read
	BackoffLimit int
	// PingNum is the number of ICMP echo request to send
	PingNum int
	// Cping number of concurrent ping
	Cping int
	// Privileged is set to true, then raw socket will be used as the underlying socket type
	// otherwise, then dgram socket will be used as the underlying socket type
	Privileged bool
	// DelayRetry tells how much time(milliseconds) to wait before
	// retrying a read icmp message op
	DelayRetry int
}

type Ping

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

func (*Ping) Ping

func (p *Ping) Ping(host string) (*Stats, error)

type Pinger

type Pinger interface {
	Ping(host string) (*Stats, error)
}

func NewPinger

func NewPinger(c *Config, options ...func(ping *Ping)) Pinger

type Stats

type Stats struct {
	// DnsInfo holds information about dns name and the reverse dns name
	DnsInfo *dns.DNSInfo
	// avg rtt
	Rtt float64
	// number of sent packet
	NSent int
	// number of received packet
	NReceived int
	// percentage of lost packet
	PacketLoss float64
	// host is up
	Up bool
}

Jump to

Keyboard shortcuts

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