summaryrefslogtreecommitdiffstats
path: root/web/attachments/436432-check_fping_ipv6_support.patch
blob: 121a527936f1201e6e935c6ea3b9ee065bda1754 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
diff --git a/configure.in b/configure.in
index 1d16bcd..fec55a0 100644
--- a/configure.in
+++ b/configure.in
@@ -1364,6 +1364,17 @@ else
 	AC_MSG_WARN([Get fping from http://www.fping.com in order to make check_fping plugin])
 fi
 
+AC_PATH_PROG(PATH_TO_FPING6,fping6)
+AC_ARG_WITH(fping6_command,
+            ACX_HELP_STRING([--with-fping6-command=PATH],
+                            [Path to fping6 command]), PATH_TO_FPING6=$withval)
+if test -n "$PATH_TO_FPING6"
+then
+	AC_DEFINE_UNQUOTED(PATH_TO_FPING6,"$PATH_TO_FPING6",[path to fping6])
+else
+	AC_MSG_WARN([Get fping6 from http://www.fping.com in order to make check_fping plugin])
+fi
+
 AC_PATH_PROG(PATH_TO_SSH,ssh)
 AC_ARG_WITH(ssh_command,
             ACX_HELP_STRING([--with-ssh-command=PATH],
diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index dd3f86d..d45e76b 100644
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
@@ -72,6 +72,7 @@ main (int argc, char **argv)
 /* normaly should be  int result = STATE_UNKNOWN; */
 
   int status = STATE_UNKNOWN;
+  char *fping_prog = NULL;
   char *server = NULL;
   char *command_line = NULL;
   char *input_buffer = NULL;
@@ -96,7 +97,16 @@ main (int argc, char **argv)
   if (packet_interval)
     asprintf(&option_string, "%s-p %d ", option_string, packet_interval);
 
-  asprintf (&command_line, "%s %s-b %d -c %d %s", PATH_TO_FPING,
+#ifdef USE_IPV6
+  if (address_family == AF_INET6)
+    fping_prog = strdup(PATH_TO_FPING6);
+  else
+    fping_prog = strdup(PATH_TO_FPING);
+#else
+  fping_prog = strdup(PATH_TO_FPING);
+#endif
+
+  asprintf (&command_line, "%s %s-b %d -c %d %s", fping_prog,
             option_string, packet_size, packet_count, server);
 
   if (verbose)
@@ -241,6 +251,8 @@ process_arguments (int argc, char **argv)
     {"verbose", no_argument, 0, 'v'},
     {"version", no_argument, 0, 'V'},
     {"help", no_argument, 0, 'h'},
+    {"use-ipv4", no_argument, 0, '4'},
+    {"use-ipv6", no_argument, 0, '6'},
     {0, 0, 0, 0}
   };
 
@@ -258,7 +270,7 @@ process_arguments (int argc, char **argv)
   }
 
   while (1) {
-    c = getopt_long (argc, argv, "+hVvH:c:w:b:n:T:i:", longopts, &option);
+    c = getopt_long (argc, argv, "+hVvH:c:w:b:n:T:i:46", longopts, &option);
 
     if (c == -1 || c == EOF || c == 1)
       break;
@@ -281,6 +293,16 @@ process_arguments (int argc, char **argv)
       }
       server_name = strscpy (server_name, optarg);
       break;
+    case '4':                 /* IPv4 only */
+      address_family = AF_INET;
+      break;
+    case '6':                 /* IPv6 only */
+#ifdef USE_IPV6
+      address_family = AF_INET6;
+#else
+      usage (_("IPv6 support not available\n"));
+#endif
+      break;
     case 'c':
       get_threshold (optarg, rv);
       if (rv[RTA]) {
@@ -402,6 +424,8 @@ print_help (void)
   printf (UT_HELP_VRSN);
   printf (UT_EXTRA_OPTS);
 
+  printf (UT_IPv46);
+
   printf (" %s\n", "-H, --hostname=HOST");
   printf ("    %s\n", _("name or IP Address of host to ping (IP Address bypasses name lookup, reducing system load)"));
   printf (" %s\n", "-w, --warning=THRESHOLD");
@@ -422,6 +446,9 @@ print_help (void)
   printf (" %s\n", _("which triggers a WARNING or CRITICAL state, and <pl> is the percentage of"));
   printf (" %s\n", _("packet loss to trigger an alarm state."));
 
+  printf ("\n");
+  printf (" %s\n", _("IPv4 is used by default. Specify -6 to use IPv6."));
+
   printf (UT_SUPPORT);
 }