From 4b7d4cb536f955fd0ed3ebaaf73f0e2b0709147d Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Tue, 19 Feb 2019 20:30:55 +0100 Subject: [PATCH] Allow decimal numbers for '-t', '-i', '-p', and '-Q'. fixes #133 --- CHANGELOG.md | 1 + src/fping.c | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bf8429..867c76a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ fping 4.2 (UNRELEASED) ## Bugfixes and other changes +- Allow decimal numbers for '-t', '-i', '-p', and '-Q' - Fix build with --disable-ipv6 (#134, thanks @Polynomial-C) - Fix hang with '-6', with ipv6 kernel module, but not loaded (#140, thanks @abelbeck) - Assume '-6' if the binary is named 'fping6' (this is mostly for special diff --git a/src/fping.c b/src/fping.c index 3c92e8a..c78e1f4 100644 --- a/src/fping.c +++ b/src/fping.c @@ -422,7 +422,7 @@ int main(int argc, char** argv) { 0, 0, 0 } }; - //while ((c = optparse(&optparse_state, "46ADMNRadeghlmnoqsuvzB:C:H:I:O:Q:S:T:b:c:f:i:p:r:t:")) != EOF) { + float opt_value_float; while ((c = optparse_long(&optparse_state, longopts, NULL)) != EOF) { switch (c) { case '4': @@ -467,10 +467,13 @@ int main(int argc, char** argv) break; case 't': - if (!(timeout = (unsigned int)atoi(optparse_state.optarg) * 100)) + if (!sscanf(optparse_state.optarg, "%f", &opt_value_float)) usage(1); + if (opt_value_float < 0) { + usage(1); + } + timeout = opt_value_float * 100; timeout_flag = 1; - break; case 'r': @@ -479,14 +482,21 @@ int main(int argc, char** argv) break; case 'i': - if (!sscanf(optparse_state.optarg, "%u", &interval)) + if (!sscanf(optparse_state.optarg, "%f", &opt_value_float)) usage(1); - interval *= 100; + if (opt_value_float < 0) { + usage(1); + } + interval = opt_value_float * 100; break; case 'p': - if (!(perhost_interval = (unsigned int)atoi(optparse_state.optarg) * 100)) + if (!sscanf(optparse_state.optarg, "%f", &opt_value_float)) usage(1); + if (opt_value_float < 0) { + usage(1); + } + perhost_interval = opt_value_float * 100; break; @@ -523,8 +533,12 @@ int main(int argc, char** argv) case 'Q': verbose_flag = 0; quiet_flag = 1; - if (!(report_interval = (unsigned int)atoi(optparse_state.optarg) * 100000)) + if (!sscanf(optparse_state.optarg, "%f", &opt_value_float)) usage(1); + if (opt_value_float < 0) { + usage(1); + } + report_interval = opt_value_float * 100000; break;