1 /*****************************************************************************
2 *
3 * Nagios check_icmp plugin
4 *
5 * License: GPL
6 * Copyright (c) 2005-2008 Nagios Plugins Development Team
7 * Original Author : Andreas Ericsson <ae@op5.se>
8 *
9 * Description:
10 *
11 * This file contains the check_icmp plugin
12 *
13 * Relevant RFC's: 792 (ICMP), 791 (IP)
14 *
15 * This program was modeled somewhat after the check_icmp program,
16 * which was in turn a hack of fping (www.fping.org) but has been
17 * completely rewritten since to generate higher precision rta values,
18 * and support several different modes as well as setting ttl to control.
19 * redundant routes. The only remainders of fping is currently a few
20 * function names.
21 *
22 *
23 * This program is free software: you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation, either version 3 of the License, or
26 * (at your option) any later version.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program. If not, see <http://www.gnu.org/licenses/>.
35 *
36 *
37 *****************************************************************************/
39 /* progname may change */
40 /* char *progname = "check_icmp"; */
41 char *progname;
42 const char *copyright = "2005-2008";
43 const char *email = "nagiosplug-devel@lists.sourceforge.net";
45 /** nagios plugins basic includes */
46 #include "common.h"
47 #include "netutils.h"
48 #include "utils.h"
50 #if HAVE_SYS_SOCKIO_H
51 #include <sys/sockio.h>
52 #endif
53 #include <sys/ioctl.h>
54 #include <sys/time.h>
55 #include <sys/types.h>
56 #include <stdio.h>
57 #include <stdlib.h>
58 #include <stdarg.h>
59 #include <unistd.h>
60 #include <stddef.h>
61 #include <errno.h>
62 #include <string.h>
63 #include <ctype.h>
64 #include <netdb.h>
65 #include <sys/socket.h>
66 #include <net/if.h>
67 #include <netinet/in_systm.h>
68 #include <netinet/in.h>
69 #include <netinet/ip.h>
70 #include <netinet/ip_icmp.h>
71 #include <arpa/inet.h>
72 #include <signal.h>
75 /** sometimes undefined system macros (quite a few, actually) **/
76 #ifndef MAXTTL
77 # define MAXTTL 255
78 #endif
79 #ifndef INADDR_NONE
80 # define INADDR_NONE (in_addr_t)(-1)
81 #endif
83 #ifndef SOL_IP
84 #define SOL_IP 0
85 #endif
87 /* we bundle these in one #ifndef, since they're all from BSD
88 * Put individual #ifndef's around those that bother you */
89 #ifndef ICMP_UNREACH_NET_UNKNOWN
90 # define ICMP_UNREACH_NET_UNKNOWN 6
91 # define ICMP_UNREACH_HOST_UNKNOWN 7
92 # define ICMP_UNREACH_ISOLATED 8
93 # define ICMP_UNREACH_NET_PROHIB 9
94 # define ICMP_UNREACH_HOST_PROHIB 10
95 # define ICMP_UNREACH_TOSNET 11
96 # define ICMP_UNREACH_TOSHOST 12
97 #endif
98 /* tru64 has the ones above, but not these */
99 #ifndef ICMP_UNREACH_FILTER_PROHIB
100 # define ICMP_UNREACH_FILTER_PROHIB 13
101 # define ICMP_UNREACH_HOST_PRECEDENCE 14
102 # define ICMP_UNREACH_PRECEDENCE_CUTOFF 15
103 #endif
105 #ifndef DBL_MAX
106 # define DBL_MAX 9.9999999999e999
107 #endif
109 typedef unsigned short range_t; /* type for get_range() -- unimplemented */
111 typedef struct rta_host {
112 unsigned short id; /* id in **table, and icmp pkts */
113 char *name; /* arg used for adding this host */
114 char *msg; /* icmp error message, if any */
115 struct sockaddr_in saddr_in; /* the address of this host */
116 struct in_addr error_addr; /* stores address of error replies */
117 unsigned long long time_waited; /* total time waited, in usecs */
118 unsigned int icmp_sent, icmp_recv, icmp_lost; /* counters */
119 unsigned char icmp_type, icmp_code; /* type and code from errors */
120 unsigned short flags; /* control/status flags */
121 double rta; /* measured RTA */
122 double rtmax; /* max rtt */
123 double rtmin; /* min rtt */
124 unsigned char pl; /* measured packet loss */
125 struct rta_host *next; /* linked list */
126 } rta_host;
128 #define FLAG_LOST_CAUSE 0x01 /* decidedly dead target. */
130 /* threshold structure. all values are maximum allowed, exclusive */
131 typedef struct threshold {
132 unsigned char pl; /* max allowed packet loss in percent */
133 unsigned int rta; /* roundtrip time average, microseconds */
134 } threshold;
136 /* the data structure */
137 typedef struct icmp_ping_data {
138 struct timeval stime; /* timestamp (saved in protocol struct as well) */
139 unsigned short ping_id;
140 } icmp_ping_data;
142 /* the different modes of this program are as follows:
143 * MODE_RTA: send all packets no matter what (mimic check_icmp and check_ping)
144 * MODE_HOSTCHECK: Return immediately upon any sign of life
145 * In addition, sends packets to ALL addresses assigned
146 * to this host (as returned by gethostbyname() or
147 * gethostbyaddr() and expects one host only to be checked at
148 * a time. Therefore, any packet response what so ever will
149 * count as a sign of life, even when received outside
150 * crit.rta limit. Do not misspell any additional IP's.
151 * MODE_ALL: Requires packets from ALL requested IP to return OK (default).
152 * MODE_ICMP: implement something similar to check_icmp (MODE_RTA without
153 * tcp and udp args does this)
154 */
155 #define MODE_RTA 0
156 #define MODE_HOSTCHECK 1
157 #define MODE_ALL 2
158 #define MODE_ICMP 3
160 /* the different ping types we can do
161 * TODO: investigate ARP ping as well */
162 #define HAVE_ICMP 1
163 #define HAVE_UDP 2
164 #define HAVE_TCP 4
165 #define HAVE_ARP 8
167 #define MIN_PING_DATA_SIZE sizeof(struct icmp_ping_data)
168 #define MAX_IP_PKT_SIZE 65536 /* (theoretical) max IP packet size */
169 #define IP_HDR_SIZE 20
170 #define MAX_PING_DATA (MAX_IP_PKT_SIZE - IP_HDR_SIZE - ICMP_MINLEN)
171 #define DEFAULT_PING_DATA_SIZE (MIN_PING_DATA_SIZE + 44)
173 /* various target states */
174 #define TSTATE_INACTIVE 0x01 /* don't ping this host anymore */
175 #define TSTATE_WAITING 0x02 /* unanswered packets on the wire */
176 #define TSTATE_ALIVE 0x04 /* target is alive (has answered something) */
177 #define TSTATE_UNREACH 0x08
179 /** prototypes **/
180 void print_help (void);
181 void print_usage (void);
182 static u_int get_timevar(const char *);
183 static u_int get_timevaldiff(struct timeval *, struct timeval *);
184 static in_addr_t get_ip_address(const char *);
185 static int wait_for_reply(int, u_int);
186 static int recvfrom_wto(int, char *, unsigned int, struct sockaddr *, u_int *);
187 static int send_icmp_ping(int, struct rta_host *);
188 static int get_threshold(char *str, threshold *th);
189 static void run_checks(void);
190 static void set_source_ip(char *);
191 static int add_target(char *);
192 static int add_target_ip(char *, struct in_addr *);
193 static int handle_random_icmp(char *, struct sockaddr_in *);
194 static unsigned short icmp_checksum(unsigned short *, int);
195 static void finish(int);
196 static void crash(const char *, ...);
198 /** external **/
199 extern int optind, opterr, optopt;
200 extern char *optarg;
201 extern char **environ;
203 /** global variables **/
204 static struct rta_host **table, *cursor, *list;
205 static threshold crit = {80, 500000}, warn = {40, 200000};
206 static int mode, protocols, sockets, debug = 0, timeout = 10;
207 static unsigned short icmp_data_size = DEFAULT_PING_DATA_SIZE;
208 static unsigned short icmp_pkt_size = DEFAULT_PING_DATA_SIZE + ICMP_MINLEN;
210 static unsigned int icmp_sent = 0, icmp_recv = 0, icmp_lost = 0;
211 #define icmp_pkts_en_route (icmp_sent - (icmp_recv + icmp_lost))
212 static unsigned short targets_down = 0, targets = 0, packets = 0;
213 #define targets_alive (targets - targets_down)
214 static unsigned int retry_interval, pkt_interval, target_interval;
215 static int icmp_sock, tcp_sock, udp_sock, status = STATE_OK;
216 static pid_t pid;
217 static struct timezone tz;
218 static struct timeval prog_start;
219 static unsigned long long max_completion_time = 0;
220 static unsigned char ttl = 0; /* outgoing ttl */
221 static unsigned int warn_down = 1, crit_down = 1; /* host down threshold values */
222 static int min_hosts_alive = -1;
223 float pkt_backoff_factor = 1.5;
224 float target_backoff_factor = 1.5;
226 /** code start **/
227 static void
228 crash(const char *fmt, ...)
229 {
230 va_list ap;
232 printf("%s: ", progname);
234 va_start(ap, fmt);
235 vprintf(fmt, ap);
236 va_end(ap);
238 if(errno) printf(": %s", strerror(errno));
239 puts("");
241 exit(3);
242 }
245 static const char *
246 get_icmp_error_msg(unsigned char icmp_type, unsigned char icmp_code)
247 {
248 const char *msg = "unreachable";
250 if(debug > 1) printf("get_icmp_error_msg(%u, %u)\n", icmp_type, icmp_code);
251 switch(icmp_type) {
252 case ICMP_UNREACH:
253 switch(icmp_code) {
254 case ICMP_UNREACH_NET: msg = "Net unreachable"; break;
255 case ICMP_UNREACH_HOST: msg = "Host unreachable"; break;
256 case ICMP_UNREACH_PROTOCOL: msg = "Protocol unreachable (firewall?)"; break;
257 case ICMP_UNREACH_PORT: msg = "Port unreachable (firewall?)"; break;
258 case ICMP_UNREACH_NEEDFRAG: msg = "Fragmentation needed"; break;
259 case ICMP_UNREACH_SRCFAIL: msg = "Source route failed"; break;
260 case ICMP_UNREACH_ISOLATED: msg = "Source host isolated"; break;
261 case ICMP_UNREACH_NET_UNKNOWN: msg = "Unknown network"; break;
262 case ICMP_UNREACH_HOST_UNKNOWN: msg = "Unknown host"; break;
263 case ICMP_UNREACH_NET_PROHIB: msg = "Network denied (firewall?)"; break;
264 case ICMP_UNREACH_HOST_PROHIB: msg = "Host denied (firewall?)"; break;
265 case ICMP_UNREACH_TOSNET: msg = "Bad TOS for network (firewall?)"; break;
266 case ICMP_UNREACH_TOSHOST: msg = "Bad TOS for host (firewall?)"; break;
267 case ICMP_UNREACH_FILTER_PROHIB: msg = "Prohibited by filter (firewall)"; break;
268 case ICMP_UNREACH_HOST_PRECEDENCE: msg = "Host precedence violation"; break;
269 case ICMP_UNREACH_PRECEDENCE_CUTOFF: msg = "Precedence cutoff"; break;
270 default: msg = "Invalid code"; break;
271 }
272 break;
274 case ICMP_TIMXCEED:
275 /* really 'out of reach', or non-existant host behind a router serving
276 * two different subnets */
277 switch(icmp_code) {
278 case ICMP_TIMXCEED_INTRANS: msg = "Time to live exceeded in transit"; break;
279 case ICMP_TIMXCEED_REASS: msg = "Fragment reassembly time exceeded"; break;
280 default: msg = "Invalid code"; break;
281 }
282 break;
284 case ICMP_SOURCEQUENCH: msg = "Transmitting too fast"; break;
285 case ICMP_REDIRECT: msg = "Redirect (change route)"; break;
286 case ICMP_PARAMPROB: msg = "Bad IP header (required option absent)"; break;
288 /* the following aren't error messages, so ignore */
289 case ICMP_TSTAMP:
290 case ICMP_TSTAMPREPLY:
291 case ICMP_IREQ:
292 case ICMP_IREQREPLY:
293 case ICMP_MASKREQ:
294 case ICMP_MASKREPLY:
295 default: msg = ""; break;
296 }
298 return msg;
299 }
301 static int
302 handle_random_icmp(char *packet, struct sockaddr_in *addr)
303 {
304 struct icmp p, sent_icmp;
305 struct rta_host *host = NULL;
307 memcpy(&p, packet, sizeof(p));
308 if(p.icmp_type == ICMP_ECHO && p.icmp_id == pid) {
309 /* echo request from us to us (pinging localhost) */
310 return 0;
311 }
313 if(debug) printf("handle_random_icmp(%p, %p)\n", (void *)&p, (void *)addr);
315 /* only handle a few types, since others can't possibly be replies to
316 * us in a sane network (if it is anyway, it will be counted as lost
317 * at summary time, but not as quickly as a proper response */
318 /* TIMXCEED can be an unreach from a router with multiple IP's which
319 * serves two different subnets on the same interface and a dead host
320 * on one net is pinged from the other. The router will respond to
321 * itself and thus set TTL=0 so as to not loop forever. Even when
322 * TIMXCEED actually sends a proper icmp response we will have passed
323 * too many hops to have a hope of reaching it later, in which case it
324 * indicates overconfidence in the network, poor routing or both. */
325 if(p.icmp_type != ICMP_UNREACH && p.icmp_type != ICMP_TIMXCEED &&
326 p.icmp_type != ICMP_SOURCEQUENCH && p.icmp_type != ICMP_PARAMPROB)
327 {
328 return 0;
329 }
331 /* might be for us. At least it holds the original package (according
332 * to RFC 792). If it isn't, just ignore it */
333 memcpy(&sent_icmp, packet + 28, sizeof(sent_icmp));
334 if(sent_icmp.icmp_type != ICMP_ECHO || sent_icmp.icmp_id != pid ||
335 sent_icmp.icmp_seq >= targets)
336 {
337 if(debug) printf("Packet is no response to a packet we sent\n");
338 return 0;
339 }
341 /* it is indeed a response for us */
342 host = table[sent_icmp.icmp_seq];
343 if(debug) {
344 printf("Received \"%s\" from %s for ICMP ECHO sent to %s.\n",
345 get_icmp_error_msg(p.icmp_type, p.icmp_code),
346 inet_ntoa(addr->sin_addr), host->name);
347 }
349 icmp_lost++;
350 host->icmp_lost++;
351 /* don't spend time on lost hosts any more */
352 if(host->flags & FLAG_LOST_CAUSE) return 0;
354 /* source quench means we're sending too fast, so increase the
355 * interval and mark this packet lost */
356 if(p.icmp_type == ICMP_SOURCEQUENCH) {
357 pkt_interval *= pkt_backoff_factor;
358 target_interval *= target_backoff_factor;
359 }
360 else {
361 targets_down++;
362 host->flags |= FLAG_LOST_CAUSE;
363 }
364 host->icmp_type = p.icmp_type;
365 host->icmp_code = p.icmp_code;
366 host->error_addr.s_addr = addr->sin_addr.s_addr;
368 return 0;
369 }
371 int
372 main(int argc, char **argv)
373 {
374 int i;
375 char *ptr;
376 long int arg;
377 int icmp_sockerrno, udp_sockerrno, tcp_sockerrno;
378 int result;
379 struct rta_host *host;
381 setlocale (LC_ALL, "");
382 bindtextdomain (PACKAGE, LOCALEDIR);
383 textdomain (PACKAGE);
385 /* print a helpful error message if geteuid != 0 */
386 np_warn_if_not_root();
388 /* we only need to be setsuid when we get the sockets, so do
389 * that before pointer magic (esp. on network data) */
390 icmp_sockerrno = udp_sockerrno = tcp_sockerrno = sockets = 0;
392 if((icmp_sock = socket(PF_INET, SOCK_RAW, IPPROTO_ICMP)) != -1)
393 sockets |= HAVE_ICMP;
394 else icmp_sockerrno = errno;
396 /* if((udp_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) != -1) */
397 /* sockets |= HAVE_UDP; */
398 /* else udp_sockerrno = errno; */
400 /* if((tcp_sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) != -1) */
401 /* sockets |= HAVE_TCP; */
402 /* else tcp_sockerrno = errno; */
404 /* now drop privileges (no effect if not setsuid or geteuid() == 0) */
405 setuid(getuid());
407 /* POSIXLY_CORRECT might break things, so unset it (the portable way) */
408 environ = NULL;
410 /* use the pid to mark packets as ours */
411 /* Some systems have 32-bit pid_t so mask off only 16 bits */
412 pid = getpid() & 0xffff;
413 /* printf("pid = %u\n", pid); */
415 /* get calling name the old-fashioned way for portability instead
416 * of relying on the glibc-ism __progname */
417 ptr = strrchr(argv[0], '/');
418 if(ptr) progname = &ptr[1];
419 else progname = argv[0];
421 /* now set defaults. Use progname to set them initially (allows for
422 * superfast check_host program when target host is up */
423 cursor = list = NULL;
424 table = NULL;
426 mode = MODE_RTA;
427 crit.rta = 500000;
428 crit.pl = 80;
429 warn.rta = 200000;
430 warn.pl = 40;
431 protocols = HAVE_ICMP | HAVE_UDP | HAVE_TCP;
432 pkt_interval = 80000; /* 80 msec packet interval by default */
433 packets = 5;
435 if(!strcmp(progname, "check_icmp") || !strcmp(progname, "check_ping")) {
436 mode = MODE_ICMP;
437 protocols = HAVE_ICMP;
438 }
439 else if(!strcmp(progname, "check_host")) {
440 mode = MODE_HOSTCHECK;
441 pkt_interval = 1000000;
442 packets = 5;
443 crit.rta = warn.rta = 1000000;
444 crit.pl = warn.pl = 100;
445 }
446 else if(!strcmp(progname, "check_rta_multi")) {
447 mode = MODE_ALL;
448 target_interval = 0;
449 pkt_interval = 50000;
450 packets = 5;
451 }
453 /* Parse extra opts if any */
454 argv=np_extra_opts(&argc, argv, progname);
456 /* parse the arguments */
457 for(i = 1; i < argc; i++) {
458 while((arg = getopt(argc, argv, "vhVw:c:n:p:t:H:s:i:b:I:l:m:")) != EOF) {
459 long size;
460 switch(arg) {
461 case 'v':
462 debug++;
463 break;
464 case 'b':
465 size = strtol(optarg,NULL,0);
466 if (size >= (sizeof(struct icmp) + sizeof(struct icmp_ping_data)) &&
467 size < MAX_PING_DATA) {
468 icmp_data_size = size;
469 icmp_pkt_size = size + ICMP_MINLEN;
470 } else
471 usage_va("ICMP data length must be between: %d and %d",
472 sizeof(struct icmp) + sizeof(struct icmp_ping_data),
473 MAX_PING_DATA - 1);
475 break;
476 case 'i':
477 pkt_interval = get_timevar(optarg);
478 break;
479 case 'I':
480 target_interval = get_timevar(optarg);
481 break;
482 case 'w':
483 get_threshold(optarg, &warn);
484 break;
485 case 'c':
486 get_threshold(optarg, &crit);
487 break;
488 case 'n':
489 case 'p':
490 packets = strtoul(optarg, NULL, 0);
491 break;
492 case 't':
493 timeout = strtoul(optarg, NULL, 0);
494 if(!timeout) timeout = 10;
495 break;
496 case 'H':
497 add_target(optarg);
498 break;
499 case 'l':
500 ttl = (unsigned char)strtoul(optarg, NULL, 0);
501 break;
502 case 'm':
503 min_hosts_alive = (int)strtoul(optarg, NULL, 0);
504 break;
505 case 'd': /* implement later, for cluster checks */
506 warn_down = (unsigned char)strtoul(optarg, &ptr, 0);
507 if(ptr) {
508 crit_down = (unsigned char)strtoul(ptr + 1, NULL, 0);
509 }
510 break;
511 case 's': /* specify source IP address */
512 set_source_ip(optarg);
513 break;
514 case 'V': /* version */
515 print_revision (progname, NP_VERSION);
516 exit (STATE_OK);
517 case 'h': /* help */
518 print_help ();
519 exit (STATE_OK);
520 }
521 }
522 }
524 argv = &argv[optind];
525 while(*argv) {
526 add_target(*argv);
527 argv++;
528 }
529 if(!targets) {
530 errno = 0;
531 crash("No hosts to check");
532 exit(3);
533 }
535 if(!sockets) {
536 if(icmp_sock == -1) {
537 errno = icmp_sockerrno;
538 crash("Failed to obtain ICMP socket");
539 return -1;
540 }
541 /* if(udp_sock == -1) { */
542 /* errno = icmp_sockerrno; */
543 /* crash("Failed to obtain UDP socket"); */
544 /* return -1; */
545 /* } */
546 /* if(tcp_sock == -1) { */
547 /* errno = icmp_sockerrno; */
548 /* crash("Failed to obtain TCP socker"); */
549 /* return -1; */
550 /* } */
551 }
552 if(!ttl) ttl = 64;
554 if(icmp_sock) {
555 result = setsockopt(icmp_sock, SOL_IP, IP_TTL, &ttl, sizeof(ttl));
556 if(debug) {
557 if(result == -1) printf("setsockopt failed\n");
558 else printf("ttl set to %u\n", ttl);
559 }
560 }
562 /* stupid users should be able to give whatever thresholds they want
563 * (nothing will break if they do), but some anal plugin maintainer
564 * will probably add some printf() thing here later, so it might be
565 * best to at least show them where to do it. ;) */
566 if(warn.pl > crit.pl) warn.pl = crit.pl;
567 if(warn.rta > crit.rta) warn.rta = crit.rta;
568 if(warn_down > crit_down) crit_down = warn_down;
570 signal(SIGINT, finish);
571 signal(SIGHUP, finish);
572 signal(SIGTERM, finish);
573 signal(SIGALRM, finish);
574 if(debug) printf("Setting alarm timeout to %u seconds\n", timeout);
575 alarm(timeout);
577 /* make sure we don't wait any longer than necessary */
578 gettimeofday(&prog_start, &tz);
579 max_completion_time =
580 ((targets * packets * pkt_interval) + (targets * target_interval)) +
581 (targets * packets * crit.rta) + crit.rta;
583 if(debug) {
584 printf("packets: %u, targets: %u\n"
585 "target_interval: %0.3f, pkt_interval %0.3f\n"
586 "crit.rta: %0.3f\n"
587 "max_completion_time: %0.3f\n",
588 packets, targets,
589 (float)target_interval / 1000, (float)pkt_interval / 1000,
590 (float)crit.rta / 1000,
591 (float)max_completion_time / 1000);
592 }
594 if(debug) {
595 if(max_completion_time > (u_int)timeout * 1000000) {
596 printf("max_completion_time: %llu timeout: %u\n",
597 max_completion_time, timeout);
598 printf("Timout must be at lest %llu\n",
599 max_completion_time / 1000000 + 1);
600 }
601 }
603 if(debug) {
604 printf("crit = {%u, %u%%}, warn = {%u, %u%%}\n",
605 crit.rta, crit.pl, warn.rta, warn.pl);
606 printf("pkt_interval: %u target_interval: %u retry_interval: %u\n",
607 pkt_interval, target_interval, retry_interval);
608 printf("icmp_pkt_size: %u timeout: %u\n",
609 icmp_pkt_size, timeout);
610 }
612 if(packets > 20) {
613 errno = 0;
614 crash("packets is > 20 (%d)", packets);
615 }
617 if(min_hosts_alive < -1) {
618 errno = 0;
619 crash("minimum alive hosts is negative (%i)", min_hosts_alive);
620 }
622 host = list;
623 table = malloc(sizeof(struct rta_host **) * (argc - 1));
624 i = 0;
625 while(host) {
626 host->id = i;
627 table[i] = host;
628 host = host->next;
629 i++;
630 }
632 run_checks();
634 errno = 0;
635 finish(0);
637 return(0);
638 }
640 static void
641 run_checks()
642 {
643 u_int i, t, result;
644 u_int final_wait, time_passed;
646 /* this loop might actually violate the pkt_interval or target_interval
647 * settings, but only if there aren't any packets on the wire which
648 * indicates that the target can handle an increased packet rate */
649 for(i = 0; i < packets; i++) {
650 for(t = 0; t < targets; t++) {
651 /* don't send useless packets */
652 if(!targets_alive) finish(0);
653 if(table[t]->flags & FLAG_LOST_CAUSE) {
654 if(debug) printf("%s is a lost cause. not sending any more\n",
655 table[t]->name);
656 continue;
657 }
659 /* we're still in the game, so send next packet */
660 (void)send_icmp_ping(icmp_sock, table[t]);
661 result = wait_for_reply(icmp_sock, target_interval);
662 }
663 result = wait_for_reply(icmp_sock, pkt_interval * targets);
664 }
666 if(icmp_pkts_en_route && targets_alive) {
667 time_passed = get_timevaldiff(NULL, NULL);
668 final_wait = max_completion_time - time_passed;
670 if(debug) {
671 printf("time_passed: %u final_wait: %u max_completion_time: %llu\n",
672 time_passed, final_wait, max_completion_time);
673 }
674 if(time_passed > max_completion_time) {
675 if(debug) printf("Time passed. Finishing up\n");
676 finish(0);
677 }
679 /* catch the packets that might come in within the timeframe, but
680 * haven't yet */
681 if(debug) printf("Waiting for %u micro-seconds (%0.3f msecs)\n",
682 final_wait, (float)final_wait / 1000);
683 result = wait_for_reply(icmp_sock, final_wait);
684 }
685 }
687 /* response structure:
688 * ip header : 20 bytes
689 * icmp header : 28 bytes
690 * icmp echo reply : the rest
691 */
692 static int
693 wait_for_reply(int sock, u_int t)
694 {
695 int n, hlen;
696 static char buf[4096];
697 struct sockaddr_in resp_addr;
698 struct ip *ip;
699 struct icmp icp;
700 struct rta_host *host;
701 struct icmp_ping_data data;
702 struct timeval wait_start, now;
703 u_int tdiff, i, per_pkt_wait;
705 /* if we can't listen or don't have anything to listen to, just return */
706 if(!t || !icmp_pkts_en_route) return 0;
708 gettimeofday(&wait_start, &tz);
710 i = t;
711 per_pkt_wait = t / icmp_pkts_en_route;
712 while(icmp_pkts_en_route && get_timevaldiff(&wait_start, NULL) < i) {
713 t = per_pkt_wait;
715 /* wrap up if all targets are declared dead */
716 if(!targets_alive ||
717 get_timevaldiff(&prog_start, NULL) >= max_completion_time ||
718 (mode == MODE_HOSTCHECK && targets_down))
719 {
720 finish(0);
721 }
723 /* reap responses until we hit a timeout */
724 n = recvfrom_wto(sock, buf, sizeof(buf),
725 (struct sockaddr *)&resp_addr, &t);
726 if(!n) {
727 if(debug > 1) {
728 printf("recvfrom_wto() timed out during a %u usecs wait\n",
729 per_pkt_wait);
730 }
731 continue; /* timeout for this one, so keep trying */
732 }
733 if(n < 0) {
734 if(debug) printf("recvfrom_wto() returned errors\n");
735 return n;
736 }
738 ip = (struct ip *)buf;
739 if(debug > 1) printf("received %u bytes from %s\n",
740 ntohs(ip->ip_len), inet_ntoa(resp_addr.sin_addr));
742 /* obsolete. alpha on tru64 provides the necessary defines, but isn't broken */
743 /* #if defined( __alpha__ ) && __STDC__ && !defined( __GLIBC__ ) */
744 /* alpha headers are decidedly broken. Using an ansi compiler,
745 * they provide ip_vhl instead of ip_hl and ip_v, so we mask
746 * off the bottom 4 bits */
747 /* hlen = (ip->ip_vhl & 0x0f) << 2; */
748 /* #else */
749 hlen = ip->ip_hl << 2;
750 /* #endif */
752 if(n < (hlen + ICMP_MINLEN)) {
753 crash("received packet too short for ICMP (%d bytes, expected %d) from %s\n",
754 n, hlen + icmp_pkt_size, inet_ntoa(resp_addr.sin_addr));
755 }
756 /* else if(debug) { */
757 /* printf("ip header size: %u, packet size: %u (expected %u, %u)\n", */
758 /* hlen, ntohs(ip->ip_len) - hlen, */
759 /* sizeof(struct ip), icmp_pkt_size); */
760 /* } */
762 /* check the response */
763 memcpy(&icp, buf + hlen, sizeof(icp));
765 if(icp.icmp_id != pid) {
766 handle_random_icmp(buf + hlen, &resp_addr);
767 continue;
768 }
770 if(icp.icmp_type != ICMP_ECHOREPLY || icp.icmp_seq >= targets) {
771 if(debug > 2) printf("not a proper ICMP_ECHOREPLY\n");
772 handle_random_icmp(buf + hlen, &resp_addr);
773 continue;
774 }
776 /* this is indeed a valid response */
777 memcpy(&data, icp.icmp_data, sizeof(data));
779 host = table[icp.icmp_seq];
780 gettimeofday(&now, &tz);
781 tdiff = get_timevaldiff(&data.stime, &now);
783 host->time_waited += tdiff;
784 host->icmp_recv++;
785 icmp_recv++;
786 if (tdiff > host->rtmax)
787 host->rtmax = tdiff;
788 if (tdiff < host->rtmin)
789 host->rtmin = tdiff;
791 if(debug) {
792 printf("%0.3f ms rtt from %s, outgoing ttl: %u, incoming ttl: %u, max: %0.3f, min: %0.3f\n",
793 (float)tdiff / 1000, inet_ntoa(resp_addr.sin_addr),
794 ttl, ip->ip_ttl, (float)host->rtmax / 1000, (float)host->rtmin / 1000);
795 }
797 /* if we're in hostcheck mode, exit with limited printouts */
798 if(mode == MODE_HOSTCHECK) {
799 printf("OK - %s responds to ICMP. Packet %u, rta %0.3fms|"
800 "pkt=%u;;0;%u rta=%0.3f;%0.3f;%0.3f;;\n",
801 host->name, icmp_recv, (float)tdiff / 1000,
802 icmp_recv, packets, (float)tdiff / 1000,
803 (float)warn.rta / 1000, (float)crit.rta / 1000);
804 exit(STATE_OK);
805 }
806 }
808 return 0;
809 }
811 /* the ping functions */
812 static int
813 send_icmp_ping(int sock, struct rta_host *host)
814 {
815 static union {
816 char *buf; /* re-use so we prevent leaks */
817 struct icmp *icp;
818 u_short *cksum_in;
819 } packet = { NULL };
820 long int len;
821 struct icmp_ping_data data;
822 struct timeval tv;
823 struct sockaddr *addr;
825 if(sock == -1) {
826 errno = 0;
827 crash("Attempt to send on bogus socket");
828 return -1;
829 }
830 addr = (struct sockaddr *)&host->saddr_in;
832 if(!packet.buf) {
833 if (!(packet.buf = malloc(icmp_pkt_size))) {
834 crash("send_icmp_ping(): failed to malloc %d bytes for send buffer",
835 icmp_pkt_size);
836 return -1; /* might be reached if we're in debug mode */
837 }
838 }
839 memset(packet.buf, 0, icmp_pkt_size);
841 if((gettimeofday(&tv, &tz)) == -1) return -1;
843 data.ping_id = 10; /* host->icmp.icmp_sent; */
844 memcpy(&data.stime, &tv, sizeof(tv));
845 memcpy(&packet.icp->icmp_data, &data, sizeof(data));
846 packet.icp->icmp_type = ICMP_ECHO;
847 packet.icp->icmp_code = 0;
848 packet.icp->icmp_cksum = 0;
849 packet.icp->icmp_id = pid;
850 packet.icp->icmp_seq = host->id;
851 packet.icp->icmp_cksum = icmp_checksum(packet.cksum_in, icmp_pkt_size);
853 len = sendto(sock, packet.buf, icmp_pkt_size, 0, (struct sockaddr *)addr,
854 sizeof(struct sockaddr));
856 if(len < 0 || (unsigned int)len != icmp_pkt_size) {
857 if(debug) printf("Failed to send ping to %s\n",
858 inet_ntoa(host->saddr_in.sin_addr));
859 return -1;
860 }
862 icmp_sent++;
863 host->icmp_sent++;
865 return 0;
866 }
868 static int
869 recvfrom_wto(int sock, char *buf, unsigned int len, struct sockaddr *saddr,
870 u_int *timo)
871 {
872 u_int slen;
873 int n;
874 struct timeval to, then, now;
875 fd_set rd, wr;
877 if(!*timo) {
878 if(debug) printf("*timo is not\n");
879 return 0;
880 }
882 to.tv_sec = *timo / 1000000;
883 to.tv_usec = (*timo - (to.tv_sec * 1000000));
885 FD_ZERO(&rd);
886 FD_ZERO(&wr);
887 FD_SET(sock, &rd);
888 errno = 0;
889 gettimeofday(&then, &tz);
890 n = select(sock + 1, &rd, &wr, NULL, &to);
891 if(n < 0) crash("select() in recvfrom_wto");
892 gettimeofday(&now, &tz);
893 *timo = get_timevaldiff(&then, &now);
895 if(!n) return 0; /* timeout */
897 slen = sizeof(struct sockaddr);
899 return recvfrom(sock, buf, len, 0, saddr, &slen);
900 }
902 static void
903 finish(int sig)
904 {
905 u_int i = 0;
906 unsigned char pl;
907 double rta;
908 struct rta_host *host;
909 const char *status_string[] =
910 {"OK", "WARNING", "CRITICAL", "UNKNOWN", "DEPENDENT"};
911 int hosts_ok = 0;
912 int hosts_warn = 0;
914 alarm(0);
915 if(debug > 1) printf("finish(%d) called\n", sig);
917 if(icmp_sock != -1) close(icmp_sock);
918 if(udp_sock != -1) close(udp_sock);
919 if(tcp_sock != -1) close(tcp_sock);
921 if(debug) {
922 printf("icmp_sent: %u icmp_recv: %u icmp_lost: %u\n",
923 icmp_sent, icmp_recv, icmp_lost);
924 printf("targets: %u targets_alive: %u\n", targets, targets_alive);
925 }
927 /* iterate thrice to calculate values, give output, and print perfparse */
928 host = list;
929 while(host) {
930 if(!host->icmp_recv) {
931 /* rta 0 is ofcourse not entirely correct, but will still show up
932 * conspicuosly as missing entries in perfparse and cacti */
933 pl = 100;
934 rta = 0;
935 status = STATE_CRITICAL;
936 /* up the down counter if not already counted */
937 if(!(host->flags & FLAG_LOST_CAUSE) && targets_alive) targets_down++;
938 }
939 else {
940 pl = ((host->icmp_sent - host->icmp_recv) * 100) / host->icmp_sent;
941 rta = (double)host->time_waited / host->icmp_recv;
942 }
943 host->pl = pl;
944 host->rta = rta;
945 if(pl >= crit.pl || rta >= crit.rta) {
946 status = STATE_CRITICAL;
947 }
948 else if(!status && (pl >= warn.pl || rta >= warn.rta)) {
949 status = STATE_WARNING;
950 hosts_warn++;
951 }
952 else {
953 hosts_ok++;
954 }
956 host = host->next;
957 }
958 /* this is inevitable */
959 if(!targets_alive) status = STATE_CRITICAL;
960 if(min_hosts_alive > -1) {
961 if(hosts_ok >= min_hosts_alive) status = STATE_OK;
962 else if((hosts_ok + hosts_warn) >= min_hosts_alive) status = STATE_WARNING;
963 }
964 printf("%s - ", status_string[status]);
966 host = list;
967 while(host) {
968 if(debug) puts("");
969 if(i) {
970 if(i < targets) printf(" :: ");
971 else printf("\n");
972 }
973 i++;
974 if(!host->icmp_recv) {
975 status = STATE_CRITICAL;
976 if(host->flags & FLAG_LOST_CAUSE) {
977 printf("%s: %s @ %s. rta nan, lost %d%%",
978 host->name,
979 get_icmp_error_msg(host->icmp_type, host->icmp_code),
980 inet_ntoa(host->error_addr),
981 100);
982 }
983 else { /* not marked as lost cause, so we have no flags for it */
984 printf("%s: rta nan, lost 100%%", host->name);
985 }
986 }
987 else { /* !icmp_recv */
988 printf("%s: rta %0.3fms, lost %u%%",
989 host->name, host->rta / 1000, host->pl);
990 }
992 host = host->next;
993 }
995 /* iterate once more for pretty perfparse output */
996 printf("|");
997 i = 0;
998 host = list;
999 while(host) {
1000 if(debug) puts("");
1001 printf("%srta=%0.3fms;%0.3f;%0.3f;0; %spl=%u%%;%u;%u;; %srtmax=%0.3fms;;;; %srtmin=%0.3fms;;;; ",
1002 (targets > 1) ? host->name : "",
1003 host->rta / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000,
1004 (targets > 1) ? host->name : "", host->pl, warn.pl, crit.pl,
1005 (targets > 1) ? host->name : "", (float)host->rtmax / 1000,
1006 (targets > 1) ? host->name : "", (host->rtmin < DBL_MAX) ? (float)host->rtmin / 1000 : (float)0);
1008 host = host->next;
1009 }
1011 if(min_hosts_alive > -1) {
1012 if(hosts_ok >= min_hosts_alive) status = STATE_OK;
1013 else if((hosts_ok + hosts_warn) >= min_hosts_alive) status = STATE_WARNING;
1014 }
1016 /* finish with an empty line */
1017 puts("");
1018 if(debug) printf("targets: %u, targets_alive: %u, hosts_ok: %u, hosts_warn: %u, min_hosts_alive: %i\n",
1019 targets, targets_alive, hosts_ok, hosts_warn, min_hosts_alive);
1021 exit(status);
1022 }
1024 static u_int
1025 get_timevaldiff(struct timeval *early, struct timeval *later)
1026 {
1027 u_int ret;
1028 struct timeval now;
1030 if(!later) {
1031 gettimeofday(&now, &tz);
1032 later = &now;
1033 }
1034 if(!early) early = &prog_start;
1036 /* if early > later we return 0 so as to indicate a timeout */
1037 if(early->tv_sec > early->tv_sec ||
1038 (early->tv_sec == later->tv_sec && early->tv_usec > later->tv_usec))
1039 {
1040 return 0;
1041 }
1043 ret = (later->tv_sec - early->tv_sec) * 1000000;
1044 ret += later->tv_usec - early->tv_usec;
1046 return ret;
1047 }
1049 static int
1050 add_target_ip(char *arg, struct in_addr *in)
1051 {
1052 struct rta_host *host;
1054 /* disregard obviously stupid addresses */
1055 if(in->s_addr == INADDR_NONE || in->s_addr == INADDR_ANY)
1056 return -1;
1058 /* no point in adding two identical IP's, so don't. ;) */
1059 host = list;
1060 while(host) {
1061 if(host->saddr_in.sin_addr.s_addr == in->s_addr) {
1062 if(debug) printf("Identical IP already exists. Not adding %s\n", arg);
1063 return -1;
1064 }
1065 host = host->next;
1066 }
1068 /* add the fresh ip */
1069 host = malloc(sizeof(struct rta_host));
1070 if(!host) {
1071 crash("add_target_ip(%s, %s): malloc(%d) failed",
1072 arg, inet_ntoa(*in), sizeof(struct rta_host));
1073 }
1074 memset(host, 0, sizeof(struct rta_host));
1076 /* set the values. use calling name for output */
1077 host->name = strdup(arg);
1079 /* fill out the sockaddr_in struct */
1080 host->saddr_in.sin_family = AF_INET;
1081 host->saddr_in.sin_addr.s_addr = in->s_addr;
1083 host->rtmin = DBL_MAX;
1085 if(!list) list = cursor = host;
1086 else cursor->next = host;
1088 cursor = host;
1089 targets++;
1091 return 0;
1092 }
1094 /* wrapper for add_target_ip */
1095 static int
1096 add_target(char *arg)
1097 {
1098 int i;
1099 struct hostent *he;
1100 struct in_addr *in, ip;
1102 /* don't resolve if we don't have to */
1103 if((ip.s_addr = inet_addr(arg)) != INADDR_NONE) {
1104 /* don't add all ip's if we were given a specific one */
1105 return add_target_ip(arg, &ip);
1106 /* he = gethostbyaddr((char *)in, sizeof(struct in_addr), AF_INET); */
1107 /* if(!he) return add_target_ip(arg, in); */
1108 }
1109 else {
1110 errno = 0;
1111 he = gethostbyname(arg);
1112 if(!he) {
1113 errno = 0;
1114 crash("Failed to resolve %s", arg);
1115 return -1;
1116 }
1117 }
1119 /* possibly add all the IP's as targets */
1120 for(i = 0; he->h_addr_list[i]; i++) {
1121 in = (struct in_addr *)he->h_addr_list[i];
1122 add_target_ip(arg, in);
1124 /* this is silly, but it works */
1125 if(mode == MODE_HOSTCHECK || mode == MODE_ALL) {
1126 if(debug > 2) printf("mode: %d\n", mode);
1127 continue;
1128 }
1129 break;
1130 }
1132 return 0;
1133 }
1135 static void
1136 set_source_ip(char *arg)
1137 {
1138 struct sockaddr_in src;
1140 memset(&src, 0, sizeof(src));
1141 src.sin_family = AF_INET;
1142 if((src.sin_addr.s_addr = inet_addr(arg)) == INADDR_NONE)
1143 src.sin_addr.s_addr = get_ip_address(arg);
1144 if(bind(icmp_sock, (struct sockaddr *)&src, sizeof(src)) == -1)
1145 crash("Cannot bind to IP address %s", arg);
1146 }
1148 /* TODO: Move this to netutils.c and also change check_dhcp to use that. */
1149 static in_addr_t
1150 get_ip_address(const char *ifname)
1151 {
1152 #if defined(SIOCGIFADDR)
1153 struct ifreq ifr;
1154 struct sockaddr_in ip;
1156 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
1157 ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
1158 if(ioctl(icmp_sock, SIOCGIFADDR, &ifr) == -1)
1159 crash("Cannot determine IP address of interface %s", ifname);
1160 memcpy(&ip, &ifr.ifr_addr, sizeof(ip));
1161 return ip.sin_addr.s_addr;
1162 #else
1163 errno = 0;
1164 crash("Cannot get interface IP address on this platform.");
1165 #endif
1166 }
1168 /*
1169 * u = micro
1170 * m = milli
1171 * s = seconds
1172 * return value is in microseconds
1173 */
1174 static u_int
1175 get_timevar(const char *str)
1176 {
1177 char p, u, *ptr;
1178 unsigned int len;
1179 u_int i, d; /* integer and decimal, respectively */
1180 u_int factor = 1000; /* default to milliseconds */
1182 if(!str) return 0;
1183 len = strlen(str);
1184 if(!len) return 0;
1186 /* unit might be given as ms|m (millisec),
1187 * us|u (microsec) or just plain s, for seconds */
1188 u = p = '\0';
1189 u = str[len - 1];
1190 if(len >= 2 && !isdigit((int)str[len - 2])) p = str[len - 2];
1191 if(p && u == 's') u = p;
1192 else if(!p) p = u;
1193 if(debug > 2) printf("evaluating %s, u: %c, p: %c\n", str, u, p);
1195 if(u == 'u') factor = 1; /* microseconds */
1196 else if(u == 'm') factor = 1000; /* milliseconds */
1197 else if(u == 's') factor = 1000000; /* seconds */
1198 if(debug > 2) printf("factor is %u\n", factor);
1200 i = strtoul(str, &ptr, 0);
1201 if(!ptr || *ptr != '.' || strlen(ptr) < 2 || factor == 1)
1202 return i * factor;
1204 /* time specified in usecs can't have decimal points, so ignore them */
1205 if(factor == 1) return i;
1207 d = strtoul(ptr + 1, NULL, 0);
1209 /* d is decimal, so get rid of excess digits */
1210 while(d >= factor) d /= 10;
1212 /* the last parenthesis avoids floating point exceptions. */
1213 return ((i * factor) + (d * (factor / 10)));
1214 }
1216 /* not too good at checking errors, but it'll do (main() should barfe on -1) */
1217 static int
1218 get_threshold(char *str, threshold *th)
1219 {
1220 char *p = NULL, i = 0;
1222 if(!str || !strlen(str) || !th) return -1;
1224 /* pointer magic slims code by 10 lines. i is bof-stop on stupid libc's */
1225 p = &str[strlen(str) - 1];
1226 while(p != &str[1]) {
1227 if(*p == '%') *p = '\0';
1228 else if(*p == ',' && i) {
1229 *p = '\0'; /* reset it so get_timevar(str) works nicely later */
1230 th->pl = (unsigned char)strtoul(p+1, NULL, 0);
1231 break;
1232 }
1233 i = 1;
1234 p--;
1235 }
1236 th->rta = get_timevar(str);
1238 if(!th->rta) return -1;
1240 if(th->rta > MAXTTL * 1000000) th->rta = MAXTTL * 1000000;
1241 if(th->pl > 100) th->pl = 100;
1243 return 0;
1244 }
1246 unsigned short
1247 icmp_checksum(unsigned short *p, int n)
1248 {
1249 register unsigned short cksum;
1250 register long sum = 0;
1252 while(n > 1) {
1253 sum += *p++;
1254 n -= 2;
1255 }
1257 /* mop up the occasional odd byte */
1258 if(n == 1) sum += (unsigned char)*p;
1260 sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
1261 sum += (sum >> 16); /* add carry */
1262 cksum = ~sum; /* ones-complement, trunc to 16 bits */
1264 return cksum;
1265 }
1267 void
1268 print_help(void)
1269 {
1271 /*print_revision (progname);*/ /* FIXME: Why? */
1273 printf ("Copyright (c) 2005 Andreas Ericsson <ae@op5.se>\n");
1274 printf (COPYRIGHT, copyright, email);
1276 printf ("\n\n");
1278 print_usage ();
1280 printf (_(UT_HELP_VRSN));
1281 printf (_(UT_EXTRA_OPTS));
1283 printf (" %s\n", "-H");
1284 printf (" %s\n", _("specify a target"));
1285 printf (" %s\n", "-w");
1286 printf (" %s", _("warning threshold (currently "));
1287 printf ("%0.3fms,%u%%)\n", (float)warn.rta / 1000 , warn.pl / 1000);
1288 printf (" %s\n", "-c");
1289 printf (" %s", _("critical threshold (currently "));
1290 printf ("%0.3fms,%u%%)\n", (float)crit.rta, crit.pl);
1291 printf (" %s\n", "-s");
1292 printf (" %s\n", _("specify a source IP address or device name"));
1293 printf (" %s\n", "-n");
1294 printf (" %s", _("number of packets to send (currently "));
1295 printf ("%u)\n",packets);
1296 printf (" %s\n", "-i");
1297 printf (" %s", _("max packet interval (currently "));
1298 printf ("%0.3fms)\n",(float)pkt_interval / 1000);
1299 printf (" %s\n", "-I");
1300 printf (" %s", _("max target interval (currently "));
1301 printf ("%0.3fms)\n", (float)target_interval / 1000);
1302 printf (" %s\n", "-m");
1303 printf (" %s",_("number of alive hosts required for success"));
1304 printf ("\n");
1305 printf (" %s\n", "-l");
1306 printf (" %s", _("TTL on outgoing packets (currently "));
1307 printf ("%u)\n", ttl);
1308 printf (" %s\n", "-t");
1309 printf (" %s",_("timeout value (seconds, currently "));
1310 printf ("%u)\n", timeout);
1311 printf (" %s\n", "-b");
1312 printf (" %s\n", _("Number of icmp data bytes to send"));
1313 printf (" %s %u + %d)\n", _("Packet size will be data bytes + icmp header (currently"),icmp_data_size, ICMP_MINLEN);
1314 printf (" %s\n", "-v");
1315 printf (" %s\n", _("verbose"));
1317 printf ("\n");
1318 printf ("%s\n", _("Notes:"));
1319 printf (" %s\n", _("The -H switch is optional. Naming a host (or several) to check is not."));
1320 printf ("\n");
1321 printf (" %s\n", _("Threshold format for -w and -c is 200.25,60% for 200.25 msec RTA and 60%"));
1322 printf (" %s\n", _("packet loss. The default values should work well for most users."));
1323 printf (" %s\n", _("You can specify different RTA factors using the standardized abbreviations"));
1324 printf (" %s\n", _("us (microseconds), ms (milliseconds, default) or just plain s for seconds."));
1325 /* -d not yet implemented */
1326 /* printf ("%s\n", _("Threshold format for -d is warn,crit. 12,14 means WARNING if >= 12 hops"));
1327 printf ("%s\n", _("are spent and CRITICAL if >= 14 hops are spent."));
1328 printf ("%s\n\n", _("NOTE: Some systems decrease TTL when forming ICMP_ECHOREPLY, others do not."));*/
1329 printf ("\n");
1330 printf (" %s\n", _("The -v switch can be specified several times for increased verbosity."));
1331 /* printf ("%s\n", _("Long options are currently unsupported."));
1332 printf ("%s\n", _("Options marked with * require an argument"));
1333 */
1334 #ifdef NP_EXTRA_OPTS
1335 printf ("\n");
1336 printf (_(UT_EXTRA_OPTS_NOTES));
1337 #endif
1339 printf (_(UT_SUPPORT));
1340 }
1344 void
1345 print_usage (void)
1346 {
1347 printf (_("Usage:"));
1348 printf(" %s [options] [-H] host1 host2 hostN\n", progname);
1349 }