go-ping / ping

ICMP Ping library for Go
MIT License
1.31k stars 344 forks source link

Always update Packet's addresses #187

Closed gdetal closed 1 year ago

gdetal commented 2 years ago

Hi,

When a ping is performed on multicast addresses, the lib currently provides the address of the original destination in the callbacks. However, in this case the reply will come from another (existing) address. It is useful to provide the actual replied address to the callback instead of the original one (see the output below).

The output of ping without this patch is:

$ sudo ping --privileged ff02::1%ens3
PING ff02::1%ens3 (ff02::1%ens3):
24 bytes from ff02::1%ens3: icmp_seq=0 time=1.504454ms ttl=64
24 bytes from ff02::1%ens3: icmp_seq=0 time=1.553965ms ttl=64 (DUP!)
24 bytes from ff02::1%ens3: icmp_seq=0 time=1.580495ms ttl=64 (DUP!)
24 bytes from ff02::1%ens3: icmp_seq=0 time=1.596156ms ttl=64 (DUP!)

And with this patch:

$ sudo ./ping --privileged ff02::1%ens3
PING ff02::1%ens3 (ff02::1%ens3):
32 bytes from fe80::546f:f0ff:fe0e:a%ens3: icmp_seq=0 time=1.256761ms ttl=64
32 bytes from fe80::546f:f0ff:fe0e:29%ens3: icmp_seq=0 time=1.396183ms ttl=64 (DUP!)
32 bytes from fe80::546f:f0ff:fe0e:8%ens3: icmp_seq=0 time=1.447454ms ttl=64 (DUP!)
32 bytes from fe80::546f:f0ff:fe0e:e%ens3: icmp_seq=0 time=1.460754ms ttl=64 (DUP!)
SuperQ commented 1 year ago

See https://github.com/go-ping/ping/pull/226