bparli / fastping-rs

ICMP ping library in Rust inspired by go-fastping and AnyEvent::FastPing Perl module
MIT License
78 stars 12 forks source link

Support lazy creation of icmpv4 vs icmpv6 transports #23

Closed SkamDart closed 9 months ago

SkamDart commented 3 years ago

Ran into a bit of a hiccup when using your library on a kernel with ipv6 disabled. (I bet you can see where this is going).

You can repro this using your example and disabling ipv6 support in your kernel with something like,

sysctl -w net. ipv6. conf. all. disable_ipv6=1.

Your library rigthfully returns (Rust)

Error: Failed to crete ICMP pinger: Address family not supported by protocol (os error 97)

(strace)

....
close(5)                                = 0
socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6) = -1 EAFNOSUPPORT (Address family not supported by protocol)
close(4)                                = 0
close(3)                                = 0
write(2, "Error: ", 7Error: )                  = 7
write(2, "Failed to crete ICMP pinger: Add"..., 83Failed to crete ICMP pinger: Address family not supported by protocol (os error 97)) = 83
write(2, "\n", 1
)                       = 1
sigaltstack({ss_sp=NULL, ss_flags=SS_DISABLE, ss_size=16384}, NULL) = 0
munmap(0x7f83cbf000, 20480)             = 0
exit_group(1)                           = ?

It looks like I could use fastping_rs::send_ping manually but the ergonomics of this is a bit off in comparison to the rest of the library. Is the send_ping function the way to do only pings only over ipv4 or am I missing something here?

Cheers

bparli commented 3 years ago

Hey @SkamDart thanks for raising this and apologies for the delayed response.

Whats interesting is even if I disable ipv6 on my machine I can still create the transports fine, its just the actual pinging of ipv6 addresses that then correctly raise an error. What distro and kernel are you on?

In any case, I think #24 should address your problem. If you're still able, can you try again with the feature/disable_transports branch?