From 458c7b54d2b3fb700fbcd601eb69b4e35b93ed4d Mon Sep 17 00:00:00 2001 From: Erik Auerswald Date: Sat, 8 Mar 2025 19:30:48 +0100 Subject: [PATCH] fix typo in S_BINDTODEVICE error message Also, add tests with -I. In the currently use GitHub CI system, only GNU/Linux supports this option. But, network device names other than "lo" change too often on GNU/Linux to know in advance what an interface might be called. This limits what can be reliably tested. --- CHANGELOG.md | 10 ++++---- ci/test-07-options-i-m.pl | 50 ++++++++++++++++++++++++++++++++++++++- src/fping.c | 4 ++-- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20c462e..f0cb020 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Next ==== +## New features + +- The -g, --generate option now also supports IPv6 addresses (#376, + thanks @auerswal) + ## Bugfixes and other changes - Fix fallback to SO\_TIMESTAMP if SO\_TIMESTAMPNS is not available (#375, @@ -10,10 +15,7 @@ Next than the static buffer are no longer interpreted as more than one line (#378, thanks @auerswal) -## New features - -- The -g, --generate option now also supports IPv6 addresses (#376, - thanks @auerswal) +- Typo fix in error message when SO\_BINDTODEVICE fails fping 5.3 (2025-01-02) ====================== diff --git a/ci/test-07-options-i-m.pl b/ci/test-07-options-i-m.pl index 426286a..0c0465f 100755 --- a/ci/test-07-options-i-m.pl +++ b/ci/test-07-options-i-m.pl @@ -1,9 +1,10 @@ #!/usr/bin/perl -w -use Test::Command tests => 16; +use Test::Command tests => 28; use Test::More; # -i n interval between sending ping packets (in millisec) (default 25) +# -I IFACE bind to a particular interface, not always available # -l loop sending pings forever # -k set fwmark on ping packets # -m ping multiple interfaces on target host @@ -17,6 +18,53 @@ $cmd->stdout_is_eq("127.0.0.1 is alive\n127.0.0.2 is alive\n"); $cmd->stderr_is_eq(""); } +# fping -I IFACE +SKIP: { +if($^O ne 'linux') { + skip '-I option functionality is only tested on Linux', 3; +} +my $cmd = Test::Command->new(cmd => 'fping -I lo 127.0.0.1'); +$cmd->exit_is_num(0); +$cmd->stdout_is_eq("127.0.0.1 is alive\n"); +$cmd->stderr_is_eq(""); +} + +# fping -I IFACE +SKIP: { +if($^O ne 'linux') { + skip '-I option functionality is only tested on Linux', 3; +} +if($ENV{SKIP_IPV6}) { + skip 'Skip IPv6 tests', 3; +} +my $cmd = Test::Command->new(cmd => 'fping -6 -I lo ::1'); +$cmd->exit_is_num(0); +$cmd->stdout_is_eq("::1 is alive\n"); +$cmd->stderr_is_eq(""); +} + +# fping -I IFACE +SKIP: { +if($^O ne 'linux') { + skip '-I option functionality is only tested on Linux', 3; +} +my $cmd = Test::Command->new(cmd => 'fping -I NotAnInterface 127.0.0.1'); +$cmd->exit_is_num(1); +$cmd->stdout_is_eq(""); +$cmd->stderr_like(qr{binding to specific interface \(SO_BINDTODEVICE\):.*\n}); +} + +# fping -I IFACE +SKIP: { +if($^O ne 'darwin') { + skip 'test for unsupported -I on macOS', 3; +} +my $cmd = Test::Command->new(cmd => 'fping -I lo0 127.0.0.1'); +$cmd->exit_is_num(3); +$cmd->stdout_is_eq("fping: cant bind to a particular net interface since SO_BINDTODEVICE is not supported on your os.\n"); +$cmd->stderr_is_eq(""); +} + # fping -l { my $cmd = Test::Command->new(cmd => '(sleep 2; pkill fping)& fping -p 900 -l 127.0.0.1'); diff --git a/src/fping.c b/src/fping.c index 93bf046..a7acb2f 100644 --- a/src/fping.c +++ b/src/fping.c @@ -881,14 +881,14 @@ int main(int argc, char **argv) #ifdef SO_BINDTODEVICE if (socket4 >= 0) { if (p_setsockopt(suid, socket4, SOL_SOCKET, SO_BINDTODEVICE, optparse_state.optarg, strlen(optparse_state.optarg))) { - perror("binding to specific interface (SO_BINTODEVICE)"); + perror("binding to specific interface (SO_BINDTODEVICE)"); exit(1); } } #ifdef IPV6 if (socket6 >= 0) { if (p_setsockopt(suid, socket6, SOL_SOCKET, SO_BINDTODEVICE, optparse_state.optarg, strlen(optparse_state.optarg))) { - perror("binding to specific interface (SO_BINTODEVICE), IPV6"); + perror("binding to specific interface (SO_BINDTODEVICE), IPV6"); exit(1); } } -- 2.43.0