ping

package module
v0.0.0-...-e7d6640 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2018 License: MIT Imports: 9 Imported by: 2

Documentation

Overview

Package ping provides primitives to ping network endpoints.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pinger

type Pinger interface {
	// Ping sends single packet and waits for a limited time for reply.
	// Returned values are whether reply was received in time, measured
	// round trip time, number of bytes in received payload and error. It
	// only returns errors on non-recoverable errors, if it does not receive
	// reply for implementation-specific time limit, it reports false with
	// nil error which should be interpreted as timeout.
	Ping() (ok bool, info RoundInfo, err error)

	// PeerIP returns IP address Ping sends packets to
	PeerIP() net.IP

	// Summary returns statistics collected from multiple Ping calls. It is
	// usually called after multiple Ping calls and followed by Close call.
	Stat() Summary

	// Close frees resources used by Pinger (network sockets, etc.) Other
	// methods should not be called after Close.
	Close() error
}

Pinger is used to ping remote endpoints.

func NewICMP

func NewICMP(addr string) (Pinger, error)

NewICMP returns new Pinger which pings addr using IPv4 ICMP echo messages. addr should either be an IPv4 or hostname that resolves to IPv4. If addr resolves to multiple addresses, the first IPv4 record is used.

Currently this only works on macOS or Linux; if on Linux you get permission denied error, ensure that sysctl net.ipv4.ping_group_range includes your group id.

type RoundInfo

type RoundInfo struct {
	RTT  time.Duration
	TTL  int
	Size int
}

RoundInfo holds result of a single ping request/reply exchange

type Summary

type Summary struct {
	Sent, Lost int
	MinRTT     time.Duration
	AvgRTT     time.Duration
	MaxRTT     time.Duration
	DevRTT     time.Duration
}

Summary holds statistics from a single ping run

Directories

Path Synopsis
cmd
ping
Command ping is an example of using github.com/artyom/ping package.
Command ping is an example of using github.com/artyom/ping package.

Jump to

Keyboard shortcuts

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