feat: add configurable ICMP identifier

This commit is contained in:
Nate Sales 2021-11-28 18:06:52 -08:00 committed by Charlie Jonas
parent 6e2b003bff
commit 27679364c9

14
ping.go
View File

@ -232,6 +232,9 @@ type Packet struct {
// TTL is the Time To Live on the packet. // TTL is the Time To Live on the packet.
Ttl int Ttl int
// ID is the ICMP identifier.
ID int
} }
// Statistics represent the stats of a currently running or finished // Statistics represent the stats of a currently running or finished
@ -385,6 +388,16 @@ func (p *Pinger) SetLogger(logger Logger) {
p.logger = logger p.logger = logger
} }
// SetID sets the ICMP identifier.
func (p *Pinger) SetID(id int) {
p.id = id
}
// ID returns the ICMP identifier.
func (p *Pinger) ID() int {
return p.id
}
// Run runs the pinger. This is a blocking function that will exit when it's // Run runs the pinger. This is a blocking function that will exit when it's
// done. If Count or Interval are not specified, it will run continuously until // done. If Count or Interval are not specified, it will run continuously until
// it is interrupted. // it is interrupted.
@ -641,6 +654,7 @@ func (p *Pinger) processPacket(recv *packet) error {
IPAddr: p.ipaddr, IPAddr: p.ipaddr,
Addr: p.addr, Addr: p.addr,
Ttl: recv.ttl, Ttl: recv.ttl,
ID: p.id,
} }
switch pkt := m.Body.(type) { switch pkt := m.Body.(type) {