diff options
Diffstat (limited to 'plugins-root')
-rw-r--r-- | plugins-root/check_icmp.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 61198237..1f87b75f 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c | |||
@@ -213,7 +213,7 @@ static int mode, protocols, sockets, debug = 0, timeout = 10; | |||
213 | static unsigned short icmp_data_size = DEFAULT_PING_DATA_SIZE; | 213 | static unsigned short icmp_data_size = DEFAULT_PING_DATA_SIZE; |
214 | static unsigned short icmp_pkt_size = DEFAULT_PING_DATA_SIZE + ICMP_MINLEN; | 214 | static unsigned short icmp_pkt_size = DEFAULT_PING_DATA_SIZE + ICMP_MINLEN; |
215 | 215 | ||
216 | static unsigned int icmp_sent = 0, icmp_recv = 0, icmp_lost = 0; | 216 | static unsigned int icmp_sent = 0, icmp_recv = 0, icmp_lost = 0, ttl = 0; |
217 | #define icmp_pkts_en_route (icmp_sent - (icmp_recv + icmp_lost)) | 217 | #define icmp_pkts_en_route (icmp_sent - (icmp_recv + icmp_lost)) |
218 | static unsigned short targets_down = 0, targets = 0, packets = 0; | 218 | static unsigned short targets_down = 0, targets = 0, packets = 0; |
219 | #define targets_alive (targets - targets_down) | 219 | #define targets_alive (targets - targets_down) |
@@ -223,7 +223,6 @@ static pid_t pid; | |||
223 | static struct timezone tz; | 223 | static struct timezone tz; |
224 | static struct timeval prog_start; | 224 | static struct timeval prog_start; |
225 | static unsigned long long max_completion_time = 0; | 225 | static unsigned long long max_completion_time = 0; |
226 | static unsigned char ttl = 0; /* outgoing ttl */ | ||
227 | static unsigned int warn_down = 1, crit_down = 1; /* host down threshold values */ | 226 | static unsigned int warn_down = 1, crit_down = 1; /* host down threshold values */ |
228 | static int min_hosts_alive = -1; | 227 | static int min_hosts_alive = -1; |
229 | float pkt_backoff_factor = 1.5; | 228 | float pkt_backoff_factor = 1.5; |
@@ -452,6 +451,14 @@ main(int argc, char **argv) | |||
452 | packets = 5; | 451 | packets = 5; |
453 | } | 452 | } |
454 | 453 | ||
454 | /* support "--help" and "--version" */ | ||
455 | if(argc == 2) { | ||
456 | if(!strcmp(argv[1], "--help")) | ||
457 | strcpy(argv[1], "-h"); | ||
458 | if(!strcmp(argv[1], "--version")) | ||
459 | strcpy(argv[1], "-V"); | ||
460 | } | ||
461 | |||
455 | /* Parse protocol arguments first */ | 462 | /* Parse protocol arguments first */ |
456 | for(i = 1; i < argc; i++) { | 463 | for(i = 1; i < argc; i++) { |
457 | while((arg = getopt(argc, argv, opts_str)) != EOF) { | 464 | while((arg = getopt(argc, argv, opts_str)) != EOF) { |
@@ -520,7 +527,7 @@ main(int argc, char **argv) | |||
520 | add_target(optarg); | 527 | add_target(optarg); |
521 | break; | 528 | break; |
522 | case 'l': | 529 | case 'l': |
523 | ttl = (unsigned char)strtoul(optarg, NULL, 0); | 530 | ttl = (int)strtoul(optarg, NULL, 0); |
524 | break; | 531 | break; |
525 | case 'm': | 532 | case 'm': |
526 | min_hosts_alive = (int)strtoul(optarg, NULL, 0); | 533 | min_hosts_alive = (int)strtoul(optarg, NULL, 0); |
@@ -556,14 +563,6 @@ main(int argc, char **argv) | |||
556 | /* Parse extra opts if any */ | 563 | /* Parse extra opts if any */ |
557 | argv=np_extra_opts(&argc, argv, progname); | 564 | argv=np_extra_opts(&argc, argv, progname); |
558 | 565 | ||
559 | /* support "--help" and "--version" */ | ||
560 | if(argc == 2) { | ||
561 | if(!strcmp(argv[1], "--help")) | ||
562 | strcpy(argv[1], "-h"); | ||
563 | if(!strcmp(argv[1], "--version")) | ||
564 | strcpy(argv[1], "-V"); | ||
565 | } | ||
566 | |||
567 | argv = &argv[optind]; | 566 | argv = &argv[optind]; |
568 | while(*argv) { | 567 | while(*argv) { |
569 | add_target(*argv); | 568 | add_target(*argv); |
@@ -948,6 +947,7 @@ static int | |||
948 | send_icmp_ping(int sock, struct rta_host *host) | 947 | send_icmp_ping(int sock, struct rta_host *host) |
949 | { | 948 | { |
950 | long int len; | 949 | long int len; |
950 | size_t addrlen; | ||
951 | struct icmp_ping_data data; | 951 | struct icmp_ping_data data; |
952 | struct msghdr hdr; | 952 | struct msghdr hdr; |
953 | struct iovec iov; | 953 | struct iovec iov; |
@@ -979,6 +979,7 @@ send_icmp_ping(int sock, struct rta_host *host) | |||
979 | 979 | ||
980 | if (address_family == AF_INET) { | 980 | if (address_family == AF_INET) { |
981 | struct icmp *icp = (struct icmp*)buf; | 981 | struct icmp *icp = (struct icmp*)buf; |
982 | addrlen = sizeof(struct sockaddr_in); | ||
982 | 983 | ||
983 | memcpy(&icp->icmp_data, &data, sizeof(data)); | 984 | memcpy(&icp->icmp_data, &data, sizeof(data)); |
984 | 985 | ||
@@ -995,7 +996,10 @@ send_icmp_ping(int sock, struct rta_host *host) | |||
995 | } | 996 | } |
996 | else { | 997 | else { |
997 | struct icmp6_hdr *icp6 = (struct icmp6_hdr*)buf; | 998 | struct icmp6_hdr *icp6 = (struct icmp6_hdr*)buf; |
999 | addrlen = sizeof(struct sockaddr_in6); | ||
1000 | |||
998 | memcpy(&icp6->icmp6_dataun.icmp6_un_data8[4], &data, sizeof(data)); | 1001 | memcpy(&icp6->icmp6_dataun.icmp6_un_data8[4], &data, sizeof(data)); |
1002 | |||
999 | icp6->icmp6_type = ICMP6_ECHO_REQUEST; | 1003 | icp6->icmp6_type = ICMP6_ECHO_REQUEST; |
1000 | icp6->icmp6_code = 0; | 1004 | icp6->icmp6_code = 0; |
1001 | icp6->icmp6_cksum = 0; | 1005 | icp6->icmp6_cksum = 0; |
@@ -1016,7 +1020,7 @@ send_icmp_ping(int sock, struct rta_host *host) | |||
1016 | 1020 | ||
1017 | memset(&hdr, 0, sizeof(hdr)); | 1021 | memset(&hdr, 0, sizeof(hdr)); |
1018 | hdr.msg_name = (struct sockaddr *)&host->saddr_in; | 1022 | hdr.msg_name = (struct sockaddr *)&host->saddr_in; |
1019 | hdr.msg_namelen = sizeof(struct sockaddr_storage); | 1023 | hdr.msg_namelen = addrlen; |
1020 | hdr.msg_iov = &iov; | 1024 | hdr.msg_iov = &iov; |
1021 | hdr.msg_iovlen = 1; | 1025 | hdr.msg_iovlen = 1; |
1022 | 1026 | ||