aboutsummaryrefslogtreecommitdiff
path: root/plugins-root/check_icmp.c
diff options
context:
space:
mode:
authorGravatar Matthias Eble <psychotrahe@users.sourceforge.net> 2008-07-17 07:06:33 +0000
committerGravatar Matthias Eble <psychotrahe@users.sourceforge.net> 2008-07-17 07:06:33 +0000
commitc64070fd3f924b02a517117bba2dfe702d020a9b (patch)
treed72261eb17921f71d6070cfcdd1be2cb1dd4d291 /plugins-root/check_icmp.c
parentb336798e4c1c2fab5e4396e45af6f07ddae647f1 (diff)
downloadmonitoring-plugins-c64070fd3f924b02a517117bba2dfe702d020a9b.tar.gz
Add support for packet size modification (-b)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2026 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins-root/check_icmp.c')
-rw-r--r--plugins-root/check_icmp.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index f3e5f0d3..5fb9c364 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -203,7 +203,9 @@ extern char **environ;
static struct rta_host **table, *cursor, *list;
static threshold crit = {80, 500000}, warn = {40, 200000};
static int mode, protocols, sockets, debug = 0, timeout = 10;
-static unsigned short icmp_pkt_size, icmp_data_size = DEFAULT_PING_DATA_SIZE;
+static unsigned short icmp_data_size = DEFAULT_PING_DATA_SIZE;
+static unsigned short icmp_pkt_size = DEFAULT_PING_DATA_SIZE + ICMP_MINLEN;
+
static unsigned int icmp_sent = 0, icmp_recv = 0, icmp_lost = 0;
#define icmp_pkts_en_route (icmp_sent - (icmp_recv + icmp_lost))
static unsigned short targets_down = 0, targets = 0, packets = 0;
@@ -453,12 +455,22 @@ main(int argc, char **argv)
/* parse the arguments */
for(i = 1; i < argc; i++) {
while((arg = getopt(argc, argv, "vhVw:c:n:p:t:H:s:i:b:I:l:m:")) != EOF) {
+ long size;
switch(arg) {
case 'v':
debug++;
break;
case 'b':
- /* silently ignored for now */
+ size = strtol(optarg,NULL,0);
+ if (size >= (sizeof(struct icmp) + sizeof(struct icmp_ping_data)) &&
+ size <= MAX_PING_DATA + ICMP_MINLEN) {
+ icmp_pkt_size = size;
+ icmp_data_size = icmp_pkt_size - ICMP_MINLEN;
+ } else
+ usage_va("ICMP packet size must be between: %d and %d",
+ sizeof(struct icmp) + sizeof(struct icmp_ping_data),
+ MAX_PING_DATA + ICMP_MINLEN);
+
break;
case 'i':
pkt_interval = get_timevar(optarg);
@@ -587,13 +599,6 @@ main(int argc, char **argv)
}
}
- icmp_pkt_size = icmp_data_size + ICMP_MINLEN;
- if(debug > 2) printf("icmp_pkt_size = %u\n", icmp_pkt_size);
- if(icmp_pkt_size < sizeof(struct icmp) + sizeof(struct icmp_ping_data)) {
- icmp_pkt_size = sizeof(struct icmp) + sizeof(struct icmp_ping_data);
- }
- if(debug > 2) printf("icmp_pkt_size = %u\n", icmp_pkt_size);
-
if(debug) {
printf("crit = {%u, %u%%}, warn = {%u, %u%%}\n",
crit.rta, crit.pl, warn.rta, warn.pl);
@@ -1296,7 +1301,8 @@ print_help(void)
printf (" %s",_("timeout value (seconds, currently "));
printf ("%u)\n", timeout);
printf (" %s\n", "-b");
- printf (" %s\n", _("icmp packet size (currenly ignored)"));
+ printf (" %s", _("icmp packet size (bytes, currently "));
+ printf ("%u)\n", icmp_pkt_size);
printf (" %s\n", "-v");
printf (" %s\n", _("verbose"));