* strange behaviour in ping when specifying timeout in msec
@ 2009-08-05 23:27 Michele BOLOGNA
2009-08-10 19:09 ` Brent Cook
0 siblings, 1 reply; 2+ messages in thread
From: Michele BOLOGNA @ 2009-08-05 23:27 UTC (permalink / raw)
To: yoshfuji; +Cc: netdev
Dear Mr. Yoshifuji,
I recently noticed a strange behaviour in ping from iputils.
First of all some information:
mbologna@neptune:~$ ping -V
ping utility, iputils-sss20071127
Now, I want to specify a timeout and after it expires I would like
that ping exits, regardless of the packets received, so I use the -W
option:
-W timeout
Time to wait for a response, in seconds. The option affects only
timeout in absense of any responses, otherwise ping waits for
two RTTs.
So, if I decide to wait 1s for 5 packets, the ping works fine and
exits after 5s:
mbologna@neptune:~$ ping -c 5 -W 1 1.1.1.1
PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
--- 1.1.1.1 ping statistics ---
5 packets transmitted, 0 received, 100% packet loss, time 3999ms
However, if I want to specify a timeout that is less than 1s, the ping
does not exit after 5*0.5 s and keeps staying active (notice the ^C):
mbologna@neptune:~$ ping -c 5 -W 0.5 1.1.1.1
PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
^C
--- 1.1.1.1 ping statistics ---
5 packets transmitted, 0 received, 100% packet loss, time 3999ms
I also tried escaping the timeout with \ '' "" and so on, with no luck.
In a few words, is possible to specify a timeout that is less than 1 s?
Where am I wrong?
Thank you very much for your answer.
Best regards,
Michele Bologna
--
Michele BOLOGNA
Email/GTalk: michele.bologna@gmail.com
Skype: michele-mb
PGP: 0x0BA55536
Web: www.mb.netsons.org
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: strange behaviour in ping when specifying timeout in msec
2009-08-05 23:27 strange behaviour in ping when specifying timeout in msec Michele BOLOGNA
@ 2009-08-10 19:09 ` Brent Cook
0 siblings, 0 replies; 2+ messages in thread
From: Brent Cook @ 2009-08-10 19:09 UTC (permalink / raw)
To: Michele BOLOGNA; +Cc: yoshfuji, netdev
On Wednesday 05 August 2009 06:27:14 pm Michele BOLOGNA wrote:
> Dear Mr. Yoshifuji,
> I recently noticed a strange behaviour in ping from iputils.
>
> First of all some information:
> mbologna@neptune:~$ ping -V
> ping utility, iputils-sss20071127
>
> Now, I want to specify a timeout and after it expires I would like
> that ping exits, regardless of the packets received, so I use the -W
> option:
>
> -W timeout
> Time to wait for a response, in seconds. The option affects
> only timeout in absense of any responses, otherwise ping waits for two
> RTTs.
If you check out the source to ping, you will see that the results of non-
integer arguments to -W is undefined, since atoi cannot detect errors. In your
case, its probably being interpreted as 0. You can enter almost any value for
-W without it showing an error, e.g. 'cat' or 'dog'.
case 'W':
lingertime = atoi(optarg);
if (lingertime < 0 || lingertime > INT_MAX/1000000) {
fprintf(stderr, "ping: bad linger time.\n");
exit(2);
}
lingertime *= 1000;
break;
Your best bet is perhaps to modify ping to parse time using strtof perhaps.
- Brent
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-08-10 19:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-05 23:27 strange behaviour in ping when specifying timeout in msec Michele BOLOGNA
2009-08-10 19:09 ` Brent Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).