summaryrefslogtreecommitdiffstats
path: root/plugins/check_icmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_icmp.c')
-rw-r--r--plugins/check_icmp.c94
1 files changed, 47 insertions, 47 deletions
diff --git a/plugins/check_icmp.c b/plugins/check_icmp.c
index cbd6864..4571682 100644
--- a/plugins/check_icmp.c
+++ b/plugins/check_icmp.c
@@ -310,19 +310,19 @@ int main(int argc, char **argv)
310 310
311 /* check if we are root */ 311 /* check if we are root */
312 if(geteuid()) { 312 if(geteuid()) {
313 printf("Root access needed (for raw sockets)\n"); 313 printf(_("Root access needed (for raw sockets)\n"));
314 exit(STATE_UNKNOWN); 314 exit(STATE_UNKNOWN);
315 } 315 }
316 316
317 /* confirm that ICMP is available on this machine */ 317 /* confirm that ICMP is available on this machine */
318 if((proto = getprotobyname("icmp")) == NULL) 318 if((proto = getprotobyname("icmp")) == NULL)
319 crash("icmp: unknown protocol"); 319 crash(_("icmp: unknown protocol"));
320 320
321 /* create raw socket for ICMP calls (ping) */ 321 /* create raw socket for ICMP calls (ping) */
322 sock = socket(AF_INET, SOCK_RAW, proto->p_proto); 322 sock = socket(AF_INET, SOCK_RAW, proto->p_proto);
323 323
324 if(sock < 0) 324 if(sock < 0)
325 crash("can't create raw socket"); 325 crash(_("Can't create raw socket"));
326 326
327 /* drop privileges now that we have the socket */ 327 /* drop privileges now that we have the socket */
328 if((uid = getuid())) { 328 if((uid = getuid())) {
@@ -334,7 +334,7 @@ int main(int argc, char **argv)
334 ident = getpid() & 0xFFFF; 334 ident = getpid() & 0xFFFF;
335 335
336 if(!(host_base_ptr = malloc(sizeof(struct host_name_list)))) { 336 if(!(host_base_ptr = malloc(sizeof(struct host_name_list)))) {
337 crash("Unable to allocate memory for host name list\n"); 337 crash(_("Unable to allocate memory for host name list\n"));
338 } 338 }
339 host_ptr = host_base_ptr; 339 host_ptr = host_base_ptr;
340 340
@@ -359,12 +359,12 @@ int main(int argc, char **argv)
359 switch (c) { 359 switch (c) {
360 case 'H': 360 case 'H':
361 if(!(host_ptr->entry = malloc(strlen(optarg) + 1))) { 361 if(!(host_ptr->entry = malloc(strlen(optarg) + 1))) {
362 crash("Failed to allocate memory for hostname"); 362 crash(_("Failed to allocate memory for hostname"));
363 } 363 }
364 memset(host_ptr->entry, 0, strlen(optarg) + 1); 364 memset(host_ptr->entry, 0, strlen(optarg) + 1);
365 host_ptr->entry = memcpy(host_ptr->entry, optarg, strlen(optarg)); 365 host_ptr->entry = memcpy(host_ptr->entry, optarg, strlen(optarg));
366 if(!(host_ptr->next = malloc(sizeof(struct host_name_list)))) 366 if(!(host_ptr->next = malloc(sizeof(struct host_name_list))))
367 crash("Failed to allocate memory for hostname"); 367 crash(_("Failed to allocate memory for hostname"));
368 host_ptr = host_ptr->next; 368 host_ptr = host_ptr->next;
369 host_ptr->next = NULL; 369 host_ptr->next = NULL;
370// add_name(optarg); 370// add_name(optarg);
@@ -375,35 +375,35 @@ int main(int argc, char **argv)
375 break; 375 break;
376 case 'w': 376 case 'w':
377 if(get_threshold(optarg, &warn)) { 377 if(get_threshold(optarg, &warn)) {
378 printf("Illegal threshold pair specified for -%c", c); 378 printf(_("Illegal threshold pair specified for -%c"), c);
379 print_usage(); 379 print_usage();
380 } 380 }
381 break; 381 break;
382 382
383 case 'c': 383 case 'c':
384 if(get_threshold(optarg, &crit)) { 384 if(get_threshold(optarg, &crit)) {
385 printf("Illegal threshold pair specified for -%c", c); 385 printf(_("Illegal threshold pair specified for -%c"), c);
386 print_usage(); 386 print_usage();
387 } 387 }
388 break; 388 break;
389 389
390 case 't': 390 case 't':
391 if(!(timeout = (u_int) strtoul(optarg, NULL, 0) * 100)) { 391 if(!(timeout = (u_int) strtoul(optarg, NULL, 0) * 100)) {
392 printf("option -%c requires integer argument\n", c); 392 printf(_("Option -%c requires integer argument\n"), c);
393 print_usage(); 393 print_usage();
394 } 394 }
395 break; 395 break;
396 396
397 case 'r': 397 case 'r':
398 if(!(retry = (u_int) strtoul(optarg, NULL, 0))) { 398 if(!(retry = (u_int) strtoul(optarg, NULL, 0))) {
399 printf("option -%c requires integer argument\n", c); 399 printf(_("Option -%c requires integer argument\n"), c);
400 print_usage(); 400 print_usage();
401 } 401 }
402 break; 402 break;
403 403
404 case 'i': 404 case 'i':
405 if(!(interval = (u_int) strtoul(optarg, NULL, 0) * 100)) { 405 if(!(interval = (u_int) strtoul(optarg, NULL, 0) * 100)) {
406 printf("option -%c requires positive non-zero integer argument\n", c); 406 printf(_("Option -%c requires positive non-zero integer argument\n"), c);
407 print_usage(); 407 print_usage();
408 } 408 }
409 break; 409 break;
@@ -411,14 +411,14 @@ int main(int argc, char **argv)
411 case 'p': 411 case 'p':
412 case 'n': 412 case 'n':
413 if(!(count = (u_int) strtoul(optarg, NULL, 0))) { 413 if(!(count = (u_int) strtoul(optarg, NULL, 0))) {
414 printf("option -%c requires positive non-zero integer argument\n", c); 414 printf(_("Option -%c requires positive non-zero integer argument\n"), c);
415 print_usage(); 415 print_usage();
416 } 416 }
417 break; 417 break;
418 418
419 case 'b': 419 case 'b':
420 if(!(ping_data_size = (u_int) strtoul(optarg, NULL, 0))) { 420 if(!(ping_data_size = (u_int) strtoul(optarg, NULL, 0))) {
421 printf("option -%c requires integer argument\n", c); 421 printf(_("Option -%c requires integer argument\n"), c);
422 print_usage(); 422 print_usage();
423 } 423 }
424 break; 424 break;
@@ -467,7 +467,7 @@ int main(int argc, char **argv)
467 break; 467 break;
468 468
469 default: 469 default:
470 printf("option flag -%c specified, but not recognized\n", c); 470 printf(_("Option flag -%c specified, but not recognized\n"), c);
471 print_usage(); 471 print_usage();
472 break; 472 break;
473 } 473 }
@@ -494,30 +494,30 @@ int main(int argc, char **argv)
494 else if(timeout < warn.rta) timeout = warn.rta; 494 else if(timeout < warn.rta) timeout = warn.rta;
495 495
496 if((interval < MIN_INTERVAL * 100 || retry > MAX_RETRY) && getuid()) { 496 if((interval < MIN_INTERVAL * 100 || retry > MAX_RETRY) && getuid()) {
497 printf("%s: these options are too risky for mere mortals.\n", prog); 497 printf(_("%s: these options are too risky for mere mortals.\n"), prog);
498 printf("%s: You need i >= %u and r < %u\n", 498 printf(_("%s: You need i >= %u and r < %u\n"),
499 prog, MIN_INTERVAL, MAX_RETRY); 499 prog, MIN_INTERVAL, MAX_RETRY);
500 printf("Current settings; i = %d, r = %d\n", 500 printf(_("Current settings; i = %d, r = %d\n"),
501 interval / 100, retry); 501 interval / 100, retry);
502 print_usage(); 502 print_usage();
503 } 503 }
504 504
505 if((ping_data_size > MAX_PING_DATA) || (ping_data_size < MIN_PING_DATA)) { 505 if((ping_data_size > MAX_PING_DATA) || (ping_data_size < MIN_PING_DATA)) {
506 printf("%s: data size %u not valid, must be between %u and %u\n", 506 printf(_("%s: data size %u not valid, must be between %u and %u\n"),
507 prog, ping_data_size, MIN_PING_DATA, MAX_PING_DATA); 507 prog, ping_data_size, MIN_PING_DATA, MAX_PING_DATA);
508 print_usage(); 508 print_usage();
509 509
510 } 510 }
511 511
512 if((backoff > MAX_BACKOFF_FACTOR) || (backoff < MIN_BACKOFF_FACTOR)) { 512 if((backoff > MAX_BACKOFF_FACTOR) || (backoff < MIN_BACKOFF_FACTOR)) {
513 printf("%s: backoff factor %.1f not valid, must be between %.1f and %.1f\n", 513 printf(_("%s: backoff factor %.1f not valid, must be between %.1f and %.1f\n"),
514 prog, backoff, MIN_BACKOFF_FACTOR, MAX_BACKOFF_FACTOR); 514 prog, backoff, MIN_BACKOFF_FACTOR, MAX_BACKOFF_FACTOR);
515 print_usage(); 515 print_usage();
516 516
517 } 517 }
518 518
519 if(count > MAX_COUNT) { 519 if(count > MAX_COUNT) {
520 printf("%s: count %u not valid, must be less than %u\n", 520 printf(_("%s: count %u not valid, must be less than %u\n"),
521 prog, count, MAX_COUNT); 521 prog, count, MAX_COUNT);
522 print_usage(); 522 print_usage();
523 } 523 }
@@ -536,19 +536,19 @@ int main(int argc, char **argv)
536 536
537 /* generate requires command line parameters beyond the switches */ 537 /* generate requires command line parameters beyond the switches */
538 if(generate_flag && !*argv) { 538 if(generate_flag && !*argv) {
539 printf("generate flag requires command line parameters beyond switches\n"); 539 printf(_("Generate flag requires command line parameters beyond switches\n"));
540 print_usage(); 540 print_usage();
541 } 541 }
542 542
543 if(*argv && !generate_flag) { 543 if(*argv && !generate_flag) {
544 while(*argv) { 544 while(*argv) {
545 if(!(host_ptr->entry = malloc(strlen(*argv) + 1))) { 545 if(!(host_ptr->entry = malloc(strlen(*argv) + 1))) {
546 crash("Failed to allocate memory for hostname"); 546 crash(_("Failed to allocate memory for hostname"));
547 } 547 }
548 memset(host_ptr->entry, 0, strlen(*argv) + 1); 548 memset(host_ptr->entry, 0, strlen(*argv) + 1);
549 host_ptr->entry = memcpy(host_ptr->entry, *argv, strlen(*argv)); 549 host_ptr->entry = memcpy(host_ptr->entry, *argv, strlen(*argv));
550 if(!(host_ptr->next = malloc(sizeof(struct host_name_list)))) 550 if(!(host_ptr->next = malloc(sizeof(struct host_name_list))))
551 crash("Failed to allocate memory for hostname"); 551 crash(_("Failed to allocate memory for hostname"));
552 host_ptr = host_ptr->next; 552 host_ptr = host_ptr->next;
553 host_ptr->next = NULL; 553 host_ptr->next = NULL;
554 554
@@ -565,13 +565,13 @@ int main(int argc, char **argv)
565 } 565 }
566 566
567 if(!num_hosts) { 567 if(!num_hosts) {
568 printf("No hosts to work with!\n\n"); 568 printf(_("No hosts to work with!\n\n"));
569 print_usage(); 569 print_usage();
570 } 570 }
571 571
572 /* allocate array to hold outstanding ping requests */ 572 /* allocate array to hold outstanding ping requests */
573 table = (HOST_ENTRY **) malloc(sizeof(HOST_ENTRY *) * num_hosts); 573 table = (HOST_ENTRY **) malloc(sizeof(HOST_ENTRY *) * num_hosts);
574 if(!table) crash("Can't malloc array of hosts"); 574 if(!table) crash(_("Can't malloc array of hosts"));
575 575
576 cursor = rrlist; 576 cursor = rrlist;
577 577
@@ -703,7 +703,7 @@ void finish()
703 warn.pl, crit.pl); 703 warn.pl, crit.pl);
704 } 704 }
705 else { 705 else {
706 printf("%s is down (lost 100%%)", h->host); 706 printf(_("%s is down (lost 100%%)"), h->host);
707 } 707 }
708 } 708 }
709 else { 709 else {
@@ -754,7 +754,7 @@ void finish()
754 } 754 }
755 755
756 if(num_noaddress) { 756 if(num_noaddress) {
757 printf("No hostaddress specified.\n"); 757 printf(_("No hostaddress specified.\n"));
758 print_usage(); 758 print_usage();
759 } 759 }
760 else if(num_alive != num_hosts) { 760 else if(num_alive != num_hosts) {
@@ -765,10 +765,10 @@ void finish()
765 765
766 if(num_hosts > 1) { 766 if(num_hosts > 1) {
767 if(num_alive == num_hosts) { 767 if(num_alive == num_hosts) {
768 printf("OK - All %d hosts are alive\n", num_hosts); 768 printf(_("OK - All %d hosts are alive\n"), num_hosts);
769 } 769 }
770 else { 770 else {
771 printf("CRITICAL - %d of %d hosts are alive\n", num_alive, num_hosts); 771 printf(_("CRITICAL - %d of %d hosts are alive\n"), num_alive, num_hosts);
772 } 772 }
773 } 773 }
774 exit(fin_stat); 774 exit(fin_stat);
@@ -784,7 +784,7 @@ void send_ping(int lsock, HOST_ENTRY *h)
784 784
785 buffer = (char *)malloc((size_t) ping_pkt_size); 785 buffer = (char *)malloc((size_t) ping_pkt_size);
786 if(!buffer) 786 if(!buffer)
787 crash("can't malloc ping packet"); 787 crash(_("Can't malloc ping packet"));
788 788
789 memset(buffer, 0, ping_pkt_size * sizeof(char)); 789 memset(buffer, 0, ping_pkt_size * sizeof(char));
790 icp = (struct icmp *)buffer; 790 icp = (struct icmp *)buffer;
@@ -808,7 +808,7 @@ void send_ping(int lsock, HOST_ENTRY *h)
808 808
809 if(n < 0 || (unsigned int)n != ping_pkt_size) { 809 if(n < 0 || (unsigned int)n != ping_pkt_size) {
810 if(unreachable_flag) { 810 if(unreachable_flag) {
811 printf("%s error while sending ping: %s\n", 811 printf(_("%s error while sending ping: %s\n"),
812 h->host, strerror(errno)); 812 h->host, strerror(errno));
813 } /* IF */ 813 } /* IF */
814 814
@@ -860,7 +860,7 @@ int wait_for_reply(int lsock)
860#endif /* defined(__alpha__) && __STDC__ */ 860#endif /* defined(__alpha__) && __STDC__ */
861 861
862 if(result < hlen + ICMP_MINLEN) { 862 if(result < hlen + ICMP_MINLEN) {
863 printf("received packet too short for ICMP (%d bytes from %s)\n", result, 863 printf(_("Received packet too short for ICMP (%d bytes from %s)\n"), result,
864 inet_ntoa(response_addr.sin_addr)); 864 inet_ntoa(response_addr.sin_addr));
865 865
866 return (1); /* too short */ 866 return (1); /* too short */
@@ -903,7 +903,7 @@ int wait_for_reply(int lsock)
903 /* note reply time in array, probably */ 903 /* note reply time in array, probably */
904 if((this_count >= 0) && ((unsigned int)this_count < trials)) { 904 if((this_count >= 0) && ((unsigned int)this_count < trials)) {
905 if(h->resp_times[this_count] != RESP_WAITING) { 905 if(h->resp_times[this_count] != RESP_WAITING) {
906 printf("%s : duplicate for [%d], %d bytes, %s ms", 906 printf(_("%s : duplicate for [%d], %d bytes, %s ms"),
907 h->host, this_count, result, sprint_tm(this_reply)); 907 h->host, this_count, result, sprint_tm(this_reply));
908 908
909 if(response_addr.sin_addr.s_addr != h->saddr.sin_addr.s_addr) 909 if(response_addr.sin_addr.s_addr != h->saddr.sin_addr.s_addr)
@@ -913,7 +913,7 @@ int wait_for_reply(int lsock)
913 } /* IF */ 913 } /* IF */
914 else { 914 else {
915 /* count is out of bounds?? */ 915 /* count is out of bounds?? */
916 printf("%s : duplicate for [%d], %d bytes, %s ms\n", 916 printf(_("%s : duplicate for [%d], %d bytes, %s ms\n"),
917 h->host, this_count, result, sprint_tm(this_reply)); 917 h->host, this_count, result, sprint_tm(this_reply));
918 } /* ELSE */ 918 } /* ELSE */
919 919
@@ -942,12 +942,12 @@ int handle_random_icmp(struct icmp *p, struct sockaddr_in *addr)
942 h = table[sent_icmp->icmp_seq]; 942 h = table[sent_icmp->icmp_seq];
943 943
944 if(p->icmp_code > ICMP_UNREACH_MAXTYPE) { 944 if(p->icmp_code > ICMP_UNREACH_MAXTYPE) {
945 printf("ICMP Unreachable (Invalid Code) from %s for ICMP Echo sent to %s", 945 printf(_("ICMP Unreachable (Invalid Code) from %s for ICMP Echo sent to %s"),
946 inet_ntoa(addr->sin_addr), h->host); 946 inet_ntoa(addr->sin_addr), h->host);
947 947
948 } /* IF */ 948 } /* IF */
949 else { 949 else {
950 printf("ICMP Unreachable from %s for ICMP Echo sent to %s", 950 printf(_("ICMP Unreachable from %s for ICMP Echo sent to %s"),
951 inet_ntoa(addr->sin_addr), h->host); 951 inet_ntoa(addr->sin_addr), h->host);
952 952
953 } /* ELSE */ 953 } /* ELSE */
@@ -971,7 +971,7 @@ int handle_random_icmp(struct icmp *p, struct sockaddr_in *addr)
971 (sent_icmp->icmp_seq < (n_short) num_hosts)) { 971 (sent_icmp->icmp_seq < (n_short) num_hosts)) {
972 /* this is a response to a ping we sent */ 972 /* this is a response to a ping we sent */
973 h = table[sent_icmp->icmp_seq]; 973 h = table[sent_icmp->icmp_seq];
974 printf("ICMP Unreachable from %s for ICMP Echo sent to %s", 974 printf(_("ICMP Unreachable from %s for ICMP Echo sent to %s"),
975 inet_ntoa(addr->sin_addr), h->host); 975 inet_ntoa(addr->sin_addr), h->host);
976 976
977 if(inet_addr(h->host) == INADDR_NONE) 977 if(inet_addr(h->host) == INADDR_NONE)
@@ -1056,7 +1056,7 @@ void add_name(char *name)
1056 } /* IF */ 1056 } /* IF */
1057 1057
1058 if(host_ent == NULL) { 1058 if(host_ent == NULL) {
1059 printf("%s address not found\n", name); 1059 printf(_("%s address not found\n"), name);
1060 num_noaddress++; 1060 num_noaddress++;
1061 return; 1061 return;
1062 } /* IF */ 1062 } /* IF */
@@ -1064,7 +1064,7 @@ void add_name(char *name)
1064 1064
1065 host_add = (struct in_addr *)*(host_ent->h_addr_list); 1065 host_add = (struct in_addr *)*(host_ent->h_addr_list);
1066 if(host_add == NULL) { 1066 if(host_add == NULL) {
1067 printf("%s has no address data\n", name); 1067 printf(_("%s has no address data\n"), name);
1068 num_noaddress++; 1068 num_noaddress++;
1069 return; 1069 return;
1070 } /* IF */ 1070 } /* IF */
@@ -1097,7 +1097,7 @@ char *na_cat(char *name, struct in_addr ipaddr)
1097 nm = (char *)malloc(strlen(name) + strlen(as) + 4); 1097 nm = (char *)malloc(strlen(name) + strlen(as) + 4);
1098 1098
1099 if(!nm) 1099 if(!nm)
1100 crash("can't allocate some space for a string"); 1100 crash(_("Can't allocate some space for a string"));
1101 1101
1102 strcpy(nm, name); 1102 strcpy(nm, name);
1103 strcat(nm, " ("); 1103 strcat(nm, " (");
@@ -1116,7 +1116,7 @@ void add_addr(char *name, char *host, struct in_addr ipaddr)
1116 int *i; 1116 int *i;
1117 1117
1118 if(!(p = (HOST_ENTRY *) malloc(sizeof(HOST_ENTRY)))) { 1118 if(!(p = (HOST_ENTRY *) malloc(sizeof(HOST_ENTRY)))) {
1119 crash("can't allocate HOST_ENTRY"); 1119 crash(_("Can't allocate HOST_ENTRY"));
1120 } 1120 }
1121 1121
1122 memset((char *)p, 0, sizeof(HOST_ENTRY)); 1122 memset((char *)p, 0, sizeof(HOST_ENTRY));
@@ -1129,7 +1129,7 @@ void add_addr(char *name, char *host, struct in_addr ipaddr)
1129 1129
1130 /* array for response time results */ 1130 /* array for response time results */
1131 if(!(i = (int *)malloc(trials * sizeof(int)))) { 1131 if(!(i = (int *)malloc(trials * sizeof(int)))) {
1132 crash("can't allocate resp_times array"); 1132 crash(_("Can't allocate resp_times array"));
1133 } 1133 }
1134 1134
1135 for(n = 1; n < trials; n++) 1135 for(n = 1; n < trials; n++)
@@ -1193,7 +1193,7 @@ char *cpystr(char *string)
1193 1193
1194 if(string) { 1194 if(string) {
1195 dst = (char *)malloc(1 + strlen(string)); 1195 dst = (char *)malloc(1 + strlen(string));
1196 if(!dst) crash("malloc() failed!"); 1196 if(!dst) crash(_("malloc() failed!"));
1197 1197
1198 strcpy(dst, string); 1198 strcpy(dst, string);
1199 return dst; 1199 return dst;
@@ -1210,7 +1210,7 @@ void crash(char *msg)
1210 if(errno) 1210 if(errno)
1211 printf("%s: %s : %s\n", prog, msg, strerror(errno)); 1211 printf("%s: %s : %s\n", prog, msg, strerror(errno));
1212 if(h_errno) 1212 if(h_errno)
1213 printf("%s: %s : A network error occurred\n", prog, msg); 1213 printf(_("%s: %s : A network error occurred\n"), prog, msg);
1214 } 1214 }
1215 else printf("%s: %s\n", prog, msg); 1215 else printf("%s: %s\n", prog, msg);
1216 1216
@@ -1276,7 +1276,7 @@ void u_sleep(int u_sec)
1276 FD_ZERO(&readset); 1276 FD_ZERO(&readset);
1277 nfound = select(0, &readset, &writeset, NULL, &to); 1277 nfound = select(0, &readset, &writeset, NULL, &to);
1278 if(nfound < 0) 1278 if(nfound < 0)
1279 crash("select() in u_sleep:"); 1279 crash(_("select() in u_sleep:"));
1280 1280
1281 return; 1281 return;
1282} /* u_sleep() */ 1282} /* u_sleep() */
@@ -1306,14 +1306,14 @@ int recvfrom_wto(int lsock, char *buf, int len, struct sockaddr *saddr, int timo
1306 FD_ZERO(&writeset); 1306 FD_ZERO(&writeset);
1307 FD_SET(lsock, &readset); 1307 FD_SET(lsock, &readset);
1308 nfound = select(lsock + 1, &readset, &writeset, NULL, &to); 1308 nfound = select(lsock + 1, &readset, &writeset, NULL, &to);
1309 if(nfound < 0) crash("select() in recvfrom_wto"); 1309 if(nfound < 0) crash(_("select() in recvfrom_wto"));
1310 1310
1311 if(nfound == 0) return -1; /* timeout */ 1311 if(nfound == 0) return -1; /* timeout */
1312 1312
1313 if(nfound) { 1313 if(nfound) {
1314 slen = sizeof(struct sockaddr); 1314 slen = sizeof(struct sockaddr);
1315 n = recvfrom(sock, buf, len, 0, saddr, &slen); 1315 n = recvfrom(sock, buf, len, 0, saddr, &slen);
1316 if(n < 0) crash("recvfrom"); 1316 if(n < 0) crash(_("recvfrom"));
1317 return(n); 1317 return(n);
1318 } 1318 }
1319 1319