Ordering of arguments for alpine ping

Issue #3 new
Former user created an issue

Net::Ping::External builds a command line that in the Linux case has the -i1 argument at the end. Alpine's iputils's /bin/ping wants the host at the end or else it treats the command args as hosts to ping.

Here's a fix:

diff --git a/lib/net/ping/external.rb b/lib/net/ping/external.rb
index 88563a2..ac90f8a 100644
--- a/lib/net/ping/external.rb
+++ b/lib/net/ping/external.rb
@@ -31,7 +31,7 @@ module Net

       case RbConfig::CONFIG['host_os']
         when /linux/i
-          pcmd += ['-c', count.to_s, '-W', timeout.to_s, host, '-i', interval.to_s]
+          pcmd += ['-c', count.to_s, '-W', timeout.to_s, '-i', interval.to_s, host]
         when /aix/i
           pcmd += ['-c', count.to_s, '-w', timeout.to_s, host]
         when /bsd|osx|mach|darwin/I

Here's it on the command line in Alpine Linux with iputils's /bin/ping:

# ping 127.1 -i 1
ping: -i: Try again
# ping -i 1 127.1
PING 127.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.025 ms

Comments (0)

  1. Log in to comment