From: Remi Pommarel <repk@triplefau.lt>
To: Noah Peterson <noahbpeterson1997@gmail.com>
Cc: b.a.t.m.a.n@lists.open-mesh.org
Subject: Re: [PATCH v5 1/1] batctl: ping: Add subsecond precision to ping interval
Date: Mon, 6 Jan 2025 14:49:23 +0100 [thread overview]
Message-ID: <Z3vfYxPPM79TO3gB@pilgrim> (raw)
In-Reply-To: <20250105000908.66343-2-NoahBPeterson1997@gmail.com>
Hi,
On Sat, Jan 04, 2025 at 06:09:08PM -0600, Noah Peterson wrote:
> Modify the batctl ping utility to accept both integer and floating-point
> values for the interval between sending pings. This enhancement allows
> specifying intervals with subsecond precision.
>
> For example:
> `sudo batctl ping aa:bb:cc:dd:ee:ff -i 0.5`
>
> Signed-off-by: Noah Peterson <noahbpeterson1997@gmail.com>
> ---
> v5: Fixing whitespace misalignment, correcting changelogs, removing old
> variable declaration, as noted by Sven <sven@narfation.org>
> v4: Rebasing on latest commit, reformatting into reverse X-mas tree order based
> on feedback from Sven <sven@narfation.org>
> v3: Reformatting code based on comments by Sven
> <sven@narfation.org>
> v2: Fixing use-after-free, adding a missing header file, noted by Sven
> <sven@narfation.org>
> ---
> ping.c | 27 ++++++++++++++++++++-------
> 1 file changed, 20 insertions(+), 7 deletions(-)
>
> diff --git a/ping.c b/ping.c
> index 14d9c21..6fd11b2 100644
> --- a/ping.c
> +++ b/ping.c
> @@ -19,6 +19,7 @@
> #include <stdint.h>
> #include <sys/select.h>
> #include <sys/time.h>
> +#include <time.h>
> #include <netinet/if_ether.h>
>
> #include "batadv_packet_compat.h"
> @@ -58,18 +59,21 @@ static int ping(struct state *state, int argc, char **argv)
> struct batadv_icmp_packet_rr icmp_packet_out;
> struct batadv_icmp_packet_rr icmp_packet_in;
> uint8_t last_rr[BATADV_RR_LEN][ETH_ALEN];
> + struct timespec loop_interval = {0, 0};
> struct ether_addr *dst_mac = NULL;
> struct ether_addr *rr_mac = NULL;
> int disable_translate_mac = 0;
> + double fractional_part = 0.0;
> unsigned int seq_counter = 0;
> unsigned int packets_out = 0;
> unsigned int packets_in = 0;
> + double ping_interval = 0.0;
> + double integral_part = 0.0;
> unsigned int packets_loss;
> struct bat_host *bat_host;
> struct bat_host *rr_host;
> uint8_t last_rr_cur = 0;
> int ret = EXIT_FAILURE;
> - int loop_interval = 0;
> int loop_count = -1;
> int found_args = 1;
> size_t packet_len;
> @@ -86,6 +90,7 @@ static int ping(struct state *state, int argc, char **argv)
> int timeout = 1;
> int optchar;
> int rr = 0;
> + char *end;
> int res;
> int i;
>
> @@ -101,9 +106,17 @@ static int ping(struct state *state, int argc, char **argv)
> ping_usage();
> return EXIT_SUCCESS;
> case 'i':
> - loop_interval = strtol(optarg, NULL, 10);
> - if (loop_interval < 1)
> - loop_interval = 1;
> + errno = 0;
> + ping_interval = strtod(optarg, &end);
> + if (errno) {
> + fprintf(stderr, "Error - invalid ping interval '%s'\n", optarg);
> + goto out;
> + } else {
> + ping_interval = fmax(ping_interval, 0.001);
> + }
If you are going to floor to 1 millisecond anyway why didn't you use
msleep() (or fsleep() if you needed precision) then ? This would avoid
the conversion to timespec and hence the use of modf().
Regards,
--
Remi
prev parent reply other threads:[~2025-01-06 13:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-05 0:09 [PATCH v5 0/1] batctl: ping: Add subsecond precision to ping interval Noah Peterson
2025-01-05 0:09 ` [PATCH v5 1/1] " Noah Peterson
2025-01-05 7:12 ` Sven Eckelmann
2025-01-05 8:47 ` Sven Eckelmann
2025-01-06 13:49 ` Remi Pommarel [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z3vfYxPPM79TO3gB@pilgrim \
--to=repk@triplefau.lt \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
--cc=noahbpeterson1997@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.