Documentation ¶
Index ¶
- Constants
- Variables
- type Payload
- type Pinger
- func (pinger *Pinger) Close()
- func (pinger *Pinger) PayloadSize() uint16
- func (pinger *Pinger) Ping(destination *net.IPAddr, timeout time.Duration) (time.Duration, error)
- func (pinger *Pinger) PingAttempts(destination *net.IPAddr, timeout time.Duration, attempts int) (rtt time.Duration, err error)
- func (pinger *Pinger) PingContext(ctx context.Context, destination *net.IPAddr) (time.Duration, error)
- func (pinger *Pinger) PingMulticast(destination *net.IPAddr, wait time.Duration) (<-chan Reply, error)
- func (pinger *Pinger) PingMulticastContext(ctx context.Context, destination *net.IPAddr) (<-chan Reply, error)
- func (pinger *Pinger) SetIfIndex(iface string)
- func (pinger *Pinger) SetMark(mark int) error
- func (pinger *Pinger) SetPayload(data []byte)
- func (pinger *Pinger) SetPayloadSize(size uint16)
- type Reply
Constants ¶
const ( // ProtocolICMP is the number of the Internet Control Message Protocol // (see golang.org/x/net/internal/iana.ProtocolICMP) ProtocolICMP = 1 // ProtocolICMPv6 is the IPv6 Next Header value for ICMPv6 // see golang.org/x/net/internal/iana.ProtocolIPv6ICMP ProtocolICMPv6 = 58 )
Variables ¶
var ( // SetLogger allows updating the Logger. For details, see // "github.com/digineo/go-logwrap".Instance.SetLogger. SetLogger = log.SetLogger )
Functions ¶
This section is empty.
Types ¶
type Payload ¶
type Payload []byte
Payload represents additional data appended to outgoing ICMP Echo Requests.
type Pinger ¶
type Pinger struct { LogUnexpectedPackets bool // increases log verbosity // contains filtered or unexported fields }
Pinger is a instance for ICMP echo requests
func New ¶
New creates a new Pinger. This will open the raw socket and start the receiving logic. You'll need to call Close() to cleanup.
func (*Pinger) PayloadSize ¶
PayloadSize retrieves the current payload size.
func (*Pinger) Ping ¶
Ping sends a single Echo Request and waits for an answer. It returns the round trip time (RTT) if a reply is received in time.
func (*Pinger) PingAttempts ¶
func (pinger *Pinger) PingAttempts(destination *net.IPAddr, timeout time.Duration, attempts int) (rtt time.Duration, err error)
PingAttempts sends ICMP echo requests with a timeout per request, retrying upto `attempt` times . Will finish early on success and return the round trip time of the last ping.
func (*Pinger) PingContext ¶
func (pinger *Pinger) PingContext(ctx context.Context, destination *net.IPAddr) (time.Duration, error)
PingContext sends a single Echo Request and waits for an answer. It returns the round trip time (RTT) if a reply is received before cancellation of the context.
func (*Pinger) PingMulticast ¶
func (pinger *Pinger) PingMulticast(destination *net.IPAddr, wait time.Duration) (<-chan Reply, error)
PingMulticast sends a single echo request and returns a channel for the responses. The channel will be closed on termination of the context. An error is returned if the sending of the echo request fails.
func (*Pinger) PingMulticastContext ¶
func (pinger *Pinger) PingMulticastContext(ctx context.Context, destination *net.IPAddr) (<-chan Reply, error)
PingMulticastContext does the same as PingMulticast but receives a context
func (*Pinger) SetIfIndex ¶
func (*Pinger) SetPayload ¶
SetPayload allows you to overwrite the current payload with your own data.
func (*Pinger) SetPayloadSize ¶
SetPayloadSize resizes additional payload data to the given size. The payload will subsequently be appended to outgoing ICMP Echo Requests.
The default payload size is 56, resulting in 64 bytes for the ICMP packet.