summaryrefslogtreecommitdiffstats
path: root/plugins/check_ping.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_ping.c')
-rw-r--r--plugins/check_ping.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/plugins/check_ping.c b/plugins/check_ping.c
index ba7af37..de173f9 100644
--- a/plugins/check_ping.c
+++ b/plugins/check_ping.c
@@ -44,7 +44,8 @@ const char *email = "devel@monitoring-plugins.org";
44 44
45enum { 45enum {
46 UNKNOWN_PACKET_LOSS = 200, /* 200% */ 46 UNKNOWN_PACKET_LOSS = 200, /* 200% */
47 DEFAULT_MAX_PACKETS = 5 /* default no. of ICMP ECHO packets */ 47 DEFAULT_MAX_PACKETS = 5, /* default no. of ICMP ECHO packets */
48 DEFAULT_PACKET_SIZE = 56 /* default size of ICMP ECHO packets */
48}; 49};
49 50
50int process_arguments (int, char **); 51int process_arguments (int, char **);
@@ -64,6 +65,7 @@ char **addresses = NULL;
64int n_addresses = 0; 65int n_addresses = 0;
65int max_addr = 1; 66int max_addr = 1;
66int max_packets = -1; 67int max_packets = -1;
68int packet_size = DEFAULT_PACKET_SIZE;
67int verbose = 0; 69int verbose = 0;
68 70
69float rta = UNKNOWN_TRIP_TIME; 71float rta = UNKNOWN_TRIP_TIME;
@@ -122,13 +124,21 @@ main (int argc, char **argv)
122 124
123 /* does the host address of number of packets argument come first? */ 125 /* does the host address of number of packets argument come first? */
124#ifdef PING_PACKETS_FIRST 126#ifdef PING_PACKETS_FIRST
125# ifdef PING_HAS_TIMEOUT 127# if defined(PING_HAS_TIMEOUT) && defined(PING_HAS_PACKETSIZE)
128 xasprintf (&cmd, rawcmd, timeout_interval, max_packets, packet_size, addresses[i]);
129# elif defined(PING_HAS_TIMEOUT)
126 xasprintf (&cmd, rawcmd, timeout_interval, max_packets, addresses[i]); 130 xasprintf (&cmd, rawcmd, timeout_interval, max_packets, addresses[i]);
131# elif defined(PING_HAS_PACKETSIZE)
132 xasprintf (&cmd, rawcmd, max_packets, packet_size, addresses[i]);
127# else 133# else
128 xasprintf (&cmd, rawcmd, max_packets, addresses[i]); 134 xasprintf (&cmd, rawcmd, max_packets, addresses[i]);
129# endif 135# endif
130#else 136#else
131 xasprintf (&cmd, rawcmd, addresses[i], max_packets); 137# ifdef PING_HAS_PACKETSIZE
138 xasprintf (&cmd, rawcmd, addresses[i], packet_size, max_packets);
139# else
140 xasprintf (&cmd, rawcmd, addresses[i], max_packets);
141# endif
132#endif 142#endif
133 143
134 if (verbose >= 2) 144 if (verbose >= 2)
@@ -202,6 +212,7 @@ process_arguments (int argc, char **argv)
202 static struct option longopts[] = { 212 static struct option longopts[] = {
203 STD_LONG_OPTS, 213 STD_LONG_OPTS,
204 {"packets", required_argument, 0, 'p'}, 214 {"packets", required_argument, 0, 'p'},
215 {"packetsize",required_argument, 0, 's'},
205 {"nohtml", no_argument, 0, 'n'}, 216 {"nohtml", no_argument, 0, 'n'},
206 {"link", no_argument, 0, 'L'}, 217 {"link", no_argument, 0, 'L'},
207 {"use-ipv4", no_argument, 0, '4'}, 218 {"use-ipv4", no_argument, 0, '4'},
@@ -220,7 +231,7 @@ process_arguments (int argc, char **argv)
220 } 231 }
221 232
222 while (1) { 233 while (1) {
223 c = getopt_long (argc, argv, "VvhnL46t:c:w:H:p:", longopts, &option); 234 c = getopt_long (argc, argv, "VvhnL46t:c:w:H:p:s:", longopts, &option);
224 235
225 if (c == -1 || c == EOF) 236 if (c == -1 || c == EOF)
226 break; 237 break;
@@ -277,6 +288,12 @@ process_arguments (int argc, char **argv)
277 else 288 else
278 usage2 (_("<max_packets> (%s) must be a non-negative number\n"), optarg); 289 usage2 (_("<max_packets> (%s) must be a non-negative number\n"), optarg);
279 break; 290 break;
291 case 's': /* number of packets to send */
292 if (is_intnonneg (optarg))
293 packet_size = atoi (optarg);
294 else
295 usage2 (_("<packet_size> (%s) must be a non-negative number\n"), optarg);
296 break;
280 case 'n': /* no HTML */ 297 case 'n': /* no HTML */
281 display_html = FALSE; 298 display_html = FALSE;
282 break; 299 break;
@@ -307,6 +324,7 @@ process_arguments (int argc, char **argv)
307 } 324 }
308 } 325 }
309 326
327 /* XXX shouldnt this be in function validate_arguments ? */
310 if (wpl == UNKNOWN_PACKET_LOSS) { 328 if (wpl == UNKNOWN_PACKET_LOSS) {
311 if (is_intpercent (argv[c]) == FALSE) { 329 if (is_intpercent (argv[c]) == FALSE) {
312 printf (_("<wpl> (%s) must be an integer percentage\n"), argv[c]); 330 printf (_("<wpl> (%s) must be an integer percentage\n"), argv[c]);
@@ -359,6 +377,7 @@ process_arguments (int argc, char **argv)
359 return ERROR; 377 return ERROR;
360 } 378 }
361 } 379 }
380 /* XXX END shouldnt this be in function validate_arguments ? */
362 381
363 return validate_arguments (); 382 return validate_arguments ();
364} 383}
@@ -387,6 +406,10 @@ validate_arguments ()
387 float max_seconds; 406 float max_seconds;
388 int i; 407 int i;
389 408
409 if (packet_size > 65528) {
410 printf (_("max packet size cannot be larger than 65528 Bytes"));
411 return ERROR;
412 }
390 if (wrta < 0.0) { 413 if (wrta < 0.0) {
391 printf (_("<wrta> was not set\n")); 414 printf (_("<wrta> was not set\n"));
392 return ERROR; 415 return ERROR;
@@ -591,6 +614,9 @@ print_help (void)
591 printf (" %s\n", "-p, --packets=INTEGER"); 614 printf (" %s\n", "-p, --packets=INTEGER");
592 printf (" %s ", _("number of ICMP ECHO packets to send")); 615 printf (" %s ", _("number of ICMP ECHO packets to send"));
593 printf (_("(Default: %d)\n"), DEFAULT_MAX_PACKETS); 616 printf (_("(Default: %d)\n"), DEFAULT_MAX_PACKETS);
617 printf (" %s\n", "-s, --packetsize=INTEGER");
618 printf (" %s ", _("size of ICMP ECHO packet to send"));
619 printf (_("(Default: %d)\n"), DEFAULT_PACKET_SIZE);
594 printf (" %s\n", "-L, --link"); 620 printf (" %s\n", "-L, --link");
595 printf (" %s\n", _("show HTML in the plugin output (obsoleted by urlize)")); 621 printf (" %s\n", _("show HTML in the plugin output (obsoleted by urlize)"));
596 622
@@ -615,5 +641,5 @@ print_usage (void)
615{ 641{
616 printf ("%s\n", _("Usage:")); 642 printf ("%s\n", _("Usage:"));
617 printf ("%s -H <host_address> -w <wrta>,<wpl>%% -c <crta>,<cpl>%%\n", progname); 643 printf ("%s -H <host_address> -w <wrta>,<wpl>%% -c <crta>,<cpl>%%\n", progname);
618 printf (" [-p packets] [-t timeout] [-4|-6]\n"); 644 printf (" [-p packets] [-s packetsize] [-t timeout] [-4|-6]\n");
619} 645}