]> git.gsnw.org Git - fping.git/commitdiff
fix typo in S_BINDTODEVICE error message
authorErik Auerswald <auerswal@unix-ag.uni-kl.de>
Sat, 8 Mar 2025 18:30:48 +0000 (19:30 +0100)
committerErik Auerswald <auerswal@unix-ag.uni-kl.de>
Sun, 6 Apr 2025 15:24:15 +0000 (17:24 +0200)
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
ci/test-07-options-i-m.pl
src/fping.c

index 20c462ebc45dd3539b1d6c7c01138b0983820034..f0cb0207b88be04aef4cb406813ea437efbebf48 100644 (file)
@@ -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)
 ======================
index 426286a558098acd00c37c1f850b4517a5ca268a..0c0465f3e8edea9a9de5bc21cdaf27d7c867a0d0 100755 (executable)
@@ -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');
index 93bf046bb9c98f89e234038de426a7a2d6c370b7..a7acb2fb0e60c004424f9f775024e814659bf0e6 100644 (file)
@@ -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);
                 }
             }