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>
73 #include <float.h>
76 /** sometimes undefined system macros (quite a few, actually) **/
77 #ifndef MAXTTL
78 # define MAXTTL 255
79 #endif
80 #ifndef INADDR_NONE
81 # define INADDR_NONE (in_addr_t)(-1)
82 #endif
84 #ifndef SOL_IP
85 #define SOL_IP 0
86 #endif
88 /* we bundle these in one #ifndef, since they're all from BSD
89 * Put individual #ifndef's around those that bother you */
90 #ifndef ICMP_UNREACH_NET_UNKNOWN
91 # define ICMP_UNREACH_NET_UNKNOWN 6
92 # define ICMP_UNREACH_HOST_UNKNOWN 7
93 # define ICMP_UNREACH_ISOLATED 8
94 # define ICMP_UNREACH_NET_PROHIB 9
95 # define ICMP_UNREACH_HOST_PROHIB 10
96 # define ICMP_UNREACH_TOSNET 11
97 # define ICMP_UNREACH_TOSHOST 12
98 #endif
99 /* tru64 has the ones above, but not these */
100 #ifndef ICMP_UNREACH_FILTER_PROHIB
101 # define ICMP_UNREACH_FILTER_PROHIB 13
102 # define ICMP_UNREACH_HOST_PRECEDENCE 14
103 # define ICMP_UNREACH_PRECEDENCE_CUTOFF 15
104 #endif
106 #ifndef DBL_MAX
107 # define DBL_MAX 9.9999999999e999
108 #endif
110 typedef unsigned short range_t; /* type for get_range() -- unimplemented */
112 typedef struct rta_host {
113 unsigned short id; /* id in **table, and icmp pkts */
114 char *name; /* arg used for adding this host */
115 char *msg; /* icmp error message, if any */
116 struct sockaddr_in saddr_in; /* the address of this host */
117 struct in_addr error_addr; /* stores address of error replies */
118 unsigned long long time_waited; /* total time waited, in usecs */
119 unsigned int icmp_sent, icmp_recv, icmp_lost; /* counters */
120 unsigned char icmp_type, icmp_code; /* type and code from errors */
121 unsigned short flags; /* control/status flags */
122 double rta; /* measured RTA */
123 double rtmax; /* max rtt */
124 double rtmin; /* min rtt */
125 unsigned char pl; /* measured packet loss */
126 struct rta_host *next; /* linked list */
127 } rta_host;
129 #define FLAG_LOST_CAUSE 0x01 /* decidedly dead target. */
131 /* threshold structure. all values are maximum allowed, exclusive */
132 typedef struct threshold {
133 unsigned char pl; /* max allowed packet loss in percent */
134 unsigned int rta; /* roundtrip time average, microseconds */
135 } threshold;
137 /* the data structure */
138 typedef struct icmp_ping_data {
139 struct timeval stime; /* timestamp (saved in protocol struct as well) */
140 unsigned short ping_id;
141 } icmp_ping_data;
143 /* the different modes of this program are as follows:
144 * MODE_RTA: send all packets no matter what (mimic check_icmp and check_ping)
145 * MODE_HOSTCHECK: Return immediately upon any sign of life
146 * In addition, sends packets to ALL addresses assigned
147 * to this host (as returned by gethostbyname() or
148 * gethostbyaddr() and expects one host only to be checked at
149 * a time. Therefore, any packet response what so ever will
150 * count as a sign of life, even when received outside
151 * crit.rta limit. Do not misspell any additional IP's.
152 * MODE_ALL: Requires packets from ALL requested IP to return OK (default).
153 * MODE_ICMP: implement something similar to check_icmp (MODE_RTA without
154 * tcp and udp args does this)
155 */
156 #define MODE_RTA 0
157 #define MODE_HOSTCHECK 1
158 #define MODE_ALL 2
159 #define MODE_ICMP 3
161 /* the different ping types we can do
162 * TODO: investigate ARP ping as well */
163 #define HAVE_ICMP 1
164 #define HAVE_UDP 2
165 #define HAVE_TCP 4
166 #define HAVE_ARP 8
168 #define MIN_PING_DATA_SIZE sizeof(struct icmp_ping_data)
169 #define MAX_IP_PKT_SIZE 65536 /* (theoretical) max IP packet size */
170 #define IP_HDR_SIZE 20
171 #define MAX_PING_DATA (MAX_IP_PKT_SIZE - IP_HDR_SIZE - ICMP_MINLEN)
172 #define DEFAULT_PING_DATA_SIZE (MIN_PING_DATA_SIZE + 44)
174 /* various target states */
175 #define TSTATE_INACTIVE 0x01 /* don't ping this host anymore */
176 #define TSTATE_WAITING 0x02 /* unanswered packets on the wire */
177 #define TSTATE_ALIVE 0x04 /* target is alive (has answered something) */
178 #define TSTATE_UNREACH 0x08
180 /** prototypes **/
181 void print_help (void);
182 void print_usage (void);
183 static u_int get_timevar(const char *);
184 static u_int get_timevaldiff(struct timeval *, struct timeval *);
185 static in_addr_t get_ip_address(const char *);
186 static int wait_for_reply(int, u_int);
187 static int recvfrom_wto(int, void *, unsigned int, struct sockaddr *, u_int *);
188 static int send_icmp_ping(int, struct rta_host *);
189 static int get_threshold(char *str, threshold *th);
190 static void run_checks(void);
191 static void set_source_ip(char *);
192 static int add_target(char *);
193 static int add_target_ip(char *, struct in_addr *);
194 static int handle_random_icmp(unsigned char *, struct sockaddr_in *);
195 static unsigned short icmp_checksum(unsigned short *, int);
196 static void finish(int);
197 static void crash(const char *, ...);
199 /** external **/
200 extern int optind, opterr, optopt;
201 extern char *optarg;
202 extern char **environ;
204 /** global variables **/
205 static struct rta_host **table, *cursor, *list;
206 static threshold crit = {80, 500000}, warn = {40, 200000};
207 static int mode, protocols, sockets, debug = 0, timeout = 10;
208 static unsigned short icmp_data_size = DEFAULT_PING_DATA_SIZE;
209 static unsigned short icmp_pkt_size = DEFAULT_PING_DATA_SIZE + ICMP_MINLEN;
211 static unsigned int icmp_sent = 0, icmp_recv = 0, icmp_lost = 0;
212 #define icmp_pkts_en_route (icmp_sent - (icmp_recv + icmp_lost))
213 static unsigned short targets_down = 0, targets = 0, packets = 0;
214 #define targets_alive (targets - targets_down)
215 static unsigned int retry_interval, pkt_interval, target_interval;
216 static int icmp_sock, tcp_sock, udp_sock, status = STATE_OK;
217 static pid_t pid;
218 static struct timezone tz;
219 static struct timeval prog_start;
220 static unsigned long long max_completion_time = 0;
221 static unsigned char ttl = 0; /* outgoing ttl */
222 static unsigned int warn_down = 1, crit_down = 1; /* host down threshold values */
223 static int min_hosts_alive = -1;
224 float pkt_backoff_factor = 1.5;
225 float target_backoff_factor = 1.5;
227 /** code start **/
228 static void
229 crash(const char *fmt, ...)
230 {
231 va_list ap;
233 printf("%s: ", progname);
235 va_start(ap, fmt);
236 vprintf(fmt, ap);
237 va_end(ap);
239 if(errno) printf(": %s", strerror(errno));
240 puts("");
242 exit(3);
243 }
246 static const char *
247 get_icmp_error_msg(unsigned char icmp_type, unsigned char icmp_code)
248 {
249 const char *msg = "unreachable";
251 if(debug > 1) printf("get_icmp_error_msg(%u, %u)\n", icmp_type, icmp_code);
252 switch(icmp_type) {
253 case ICMP_UNREACH:
254 switch(icmp_code) {
255 case ICMP_UNREACH_NET: msg = "Net unreachable"; break;
256 case ICMP_UNREACH_HOST: msg = "Host unreachable"; break;
257 case ICMP_UNREACH_PROTOCOL: msg = "Protocol unreachable (firewall?)"; break;
258 case ICMP_UNREACH_PORT: msg = "Port unreachable (firewall?)"; break;
259 case ICMP_UNREACH_NEEDFRAG: msg = "Fragmentation needed"; break;
260 case ICMP_UNREACH_SRCFAIL: msg = "Source route failed"; break;
261 case ICMP_UNREACH_ISOLATED: msg = "Source host isolated"; break;
262 case ICMP_UNREACH_NET_UNKNOWN: msg = "Unknown network"; break;
263 case ICMP_UNREACH_HOST_UNKNOWN: msg = "Unknown host"; break;
264 case ICMP_UNREACH_NET_PROHIB: msg = "Network denied (firewall?)"; break;
265 case ICMP_UNREACH_HOST_PROHIB: msg = "Host denied (firewall?)"; break;
266 case ICMP_UNREACH_TOSNET: msg = "Bad TOS for network (firewall?)"; break;
267 case ICMP_UNREACH_TOSHOST: msg = "Bad TOS for host (firewall?)"; break;
268 case ICMP_UNREACH_FILTER_PROHIB: msg = "Prohibited by filter (firewall)"; break;
269 case ICMP_UNREACH_HOST_PRECEDENCE: msg = "Host precedence violation"; break;
270 case ICMP_UNREACH_PRECEDENCE_CUTOFF: msg = "Precedence cutoff"; break;
271 default: msg = "Invalid code"; break;
272 }
273 break;
275 case ICMP_TIMXCEED:
276 /* really 'out of reach', or non-existant host behind a router serving
277 * two different subnets */
278 switch(icmp_code) {
279 case ICMP_TIMXCEED_INTRANS: msg = "Time to live exceeded in transit"; break;
280 case ICMP_TIMXCEED_REASS: msg = "Fragment reassembly time exceeded"; break;
281 default: msg = "Invalid code"; break;
282 }
283 break;
285 case ICMP_SOURCEQUENCH: msg = "Transmitting too fast"; break;
286 case ICMP_REDIRECT: msg = "Redirect (change route)"; break;
287 case ICMP_PARAMPROB: msg = "Bad IP header (required option absent)"; break;
289 /* the following aren't error messages, so ignore */
290 case ICMP_TSTAMP:
291 case ICMP_TSTAMPREPLY:
292 case ICMP_IREQ:
293 case ICMP_IREQREPLY:
294 case ICMP_MASKREQ:
295 case ICMP_MASKREPLY:
296 default: msg = ""; break;
297 }
299 return msg;
300 }
302 static int
303 handle_random_icmp(unsigned char *packet, struct sockaddr_in *addr)
304 {
305 struct icmp p, sent_icmp;
306 struct rta_host *host = NULL;
308 memcpy(&p, packet, sizeof(p));
309 if(p.icmp_type == ICMP_ECHO && ntohs(p.icmp_id) == pid) {
310 /* echo request from us to us (pinging localhost) */
311 return 0;
312 }
314 if(debug) printf("handle_random_icmp(%p, %p)\n", (void *)&p, (void *)addr);
316 /* only handle a few types, since others can't possibly be replies to
317 * us in a sane network (if it is anyway, it will be counted as lost
318 * at summary time, but not as quickly as a proper response */
319 /* TIMXCEED can be an unreach from a router with multiple IP's which
320 * serves two different subnets on the same interface and a dead host
321 * on one net is pinged from the other. The router will respond to
322 * itself and thus set TTL=0 so as to not loop forever. Even when
323 * TIMXCEED actually sends a proper icmp response we will have passed
324 * too many hops to have a hope of reaching it later, in which case it
325 * indicates overconfidence in the network, poor routing or both. */
326 if(p.icmp_type != ICMP_UNREACH && p.icmp_type != ICMP_TIMXCEED &&
327 p.icmp_type != ICMP_SOURCEQUENCH && p.icmp_type != ICMP_PARAMPROB)
328 {
329 return 0;
330 }
332 /* might be for us. At least it holds the original package (according
333 * to RFC 792). If it isn't, just ignore it */
334 memcpy(&sent_icmp, packet + 28, sizeof(sent_icmp));
335 if(sent_icmp.icmp_type != ICMP_ECHO || ntohs(sent_icmp.icmp_id) != pid ||
336 ntohs(sent_icmp.icmp_seq) >= targets*packets)
337 {
338 if(debug) printf("Packet is no response to a packet we sent\n");
339 return 0;
340 }
342 /* it is indeed a response for us */
343 host = table[ntohs(sent_icmp.icmp_seq)/packets];
344 if(debug) {
345 printf("Received \"%s\" from %s for ICMP ECHO sent to %s.\n",
346 get_icmp_error_msg(p.icmp_type, p.icmp_code),
347 inet_ntoa(addr->sin_addr), host->name);
348 }
350 icmp_lost++;
351 host->icmp_lost++;
352 /* don't spend time on lost hosts any more */
353 if(host->flags & FLAG_LOST_CAUSE) return 0;
355 /* source quench means we're sending too fast, so increase the
356 * interval and mark this packet lost */
357 if(p.icmp_type == ICMP_SOURCEQUENCH) {
358 pkt_interval *= pkt_backoff_factor;
359 target_interval *= target_backoff_factor;
360 }
361 else {
362 targets_down++;
363 host->flags |= FLAG_LOST_CAUSE;
364 }
365 host->icmp_type = p.icmp_type;
366 host->icmp_code = p.icmp_code;
367 host->error_addr.s_addr = addr->sin_addr.s_addr;
369 return 0;
370 }
372 int
373 main(int argc, char **argv)
374 {
375 int i;
376 char *ptr;
377 long int arg;
378 int icmp_sockerrno, udp_sockerrno, tcp_sockerrno;
379 int result;
380 struct rta_host *host;
382 setlocale (LC_ALL, "");
383 bindtextdomain (PACKAGE, LOCALEDIR);
384 textdomain (PACKAGE);
386 /* print a helpful error message if geteuid != 0 */
387 np_warn_if_not_root();
389 /* we only need to be setsuid when we get the sockets, so do
390 * that before pointer magic (esp. on network data) */
391 icmp_sockerrno = udp_sockerrno = tcp_sockerrno = sockets = 0;
393 if((icmp_sock = socket(PF_INET, SOCK_RAW, IPPROTO_ICMP)) != -1)
394 sockets |= HAVE_ICMP;
395 else icmp_sockerrno = errno;
397 /* if((udp_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) != -1) */
398 /* sockets |= HAVE_UDP; */
399 /* else udp_sockerrno = errno; */
401 /* if((tcp_sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) != -1) */
402 /* sockets |= HAVE_TCP; */
403 /* else tcp_sockerrno = errno; */
405 /* now drop privileges (no effect if not setsuid or geteuid() == 0) */
406 setuid(getuid());
408 /* POSIXLY_CORRECT might break things, so unset it (the portable way) */
409 environ = NULL;
411 /* use the pid to mark packets as ours */
412 /* Some systems have 32-bit pid_t so mask off only 16 bits */
413 pid = getpid() & 0xffff;
414 /* printf("pid = %u\n", pid); */
416 /* get calling name the old-fashioned way for portability instead
417 * of relying on the glibc-ism __progname */
418 ptr = strrchr(argv[0], '/');
419 if(ptr) progname = &ptr[1];
420 else progname = argv[0];
422 /* now set defaults. Use progname to set them initially (allows for
423 * superfast check_host program when target host is up */
424 cursor = list = NULL;
425 table = NULL;
427 mode = MODE_RTA;
428 crit.rta = 500000;
429 crit.pl = 80;
430 warn.rta = 200000;
431 warn.pl = 40;
432 protocols = HAVE_ICMP | HAVE_UDP | HAVE_TCP;
433 pkt_interval = 80000; /* 80 msec packet interval by default */
434 packets = 5;
436 if(!strcmp(progname, "check_icmp") || !strcmp(progname, "check_ping")) {
437 mode = MODE_ICMP;
438 protocols = HAVE_ICMP;
439 }
440 else if(!strcmp(progname, "check_host")) {
441 mode = MODE_HOSTCHECK;
442 pkt_interval = 1000000;
443 packets = 5;
444 crit.rta = warn.rta = 1000000;
445 crit.pl = warn.pl = 100;
446 }
447 else if(!strcmp(progname, "check_rta_multi")) {
448 mode = MODE_ALL;
449 target_interval = 0;
450 pkt_interval = 50000;
451 packets = 5;
452 }
454 /* Parse extra opts if any */
455 argv=np_extra_opts(&argc, argv, progname);
457 /* parse the arguments */
458 for(i = 1; i < argc; i++) {
459 while((arg = getopt(argc, argv, "vhVw:c:n:p:t:H:s:i:b:I:l:m:")) != EOF) {
460 long size;
461 switch(arg) {
462 case 'v':
463 debug++;
464 break;
465 case 'b':
466 size = strtol(optarg,NULL,0);
467 if (size >= (sizeof(struct icmp) + sizeof(struct icmp_ping_data)) &&
468 size < MAX_PING_DATA) {
469 icmp_data_size = size;
470 icmp_pkt_size = size + ICMP_MINLEN;
471 } else
472 usage_va("ICMP data length must be between: %d and %d",
473 sizeof(struct icmp) + sizeof(struct icmp_ping_data),
474 MAX_PING_DATA - 1);
476 break;
477 case 'i':
478 pkt_interval = get_timevar(optarg);
479 break;
480 case 'I':
481 target_interval = get_timevar(optarg);
482 break;
483 case 'w':
484 get_threshold(optarg, &warn);
485 break;
486 case 'c':
487 get_threshold(optarg, &crit);
488 break;
489 case 'n':
490 case 'p':
491 packets = strtoul(optarg, NULL, 0);
492 break;
493 case 't':
494 timeout = strtoul(optarg, NULL, 0);
495 if(!timeout) timeout = 10;
496 break;
497 case 'H':
498 add_target(optarg);
499 break;
500 case 'l':
501 ttl = (unsigned char)strtoul(optarg, NULL, 0);
502 break;
503 case 'm':
504 min_hosts_alive = (int)strtoul(optarg, NULL, 0);
505 break;
506 case 'd': /* implement later, for cluster checks */
507 warn_down = (unsigned char)strtoul(optarg, &ptr, 0);
508 if(ptr) {
509 crit_down = (unsigned char)strtoul(ptr + 1, NULL, 0);
510 }
511 break;
512 case 's': /* specify source IP address */
513 set_source_ip(optarg);
514 break;
515 case 'V': /* version */
516 print_revision (progname, NP_VERSION);
517 exit (STATE_OK);
518 case 'h': /* help */
519 print_help ();
520 exit (STATE_OK);
521 }
522 }
523 }
525 argv = &argv[optind];
526 while(*argv) {
527 add_target(*argv);
528 argv++;
529 }
530 if(!targets) {
531 errno = 0;
532 crash("No hosts to check");
533 exit(3);
534 }
536 if(!sockets) {
537 if(icmp_sock == -1) {
538 errno = icmp_sockerrno;
539 crash("Failed to obtain ICMP socket");
540 return -1;
541 }
542 /* if(udp_sock == -1) { */
543 /* errno = icmp_sockerrno; */
544 /* crash("Failed to obtain UDP socket"); */
545 /* return -1; */
546 /* } */
547 /* if(tcp_sock == -1) { */
548 /* errno = icmp_sockerrno; */
549 /* crash("Failed to obtain TCP socker"); */
550 /* return -1; */
551 /* } */
552 }
553 if(!ttl) ttl = 64;
555 if(icmp_sock) {
556 result = setsockopt(icmp_sock, SOL_IP, IP_TTL, &ttl, sizeof(ttl));
557 if(debug) {
558 if(result == -1) printf("setsockopt failed\n");
559 else printf("ttl set to %u\n", ttl);
560 }
561 }
563 /* stupid users should be able to give whatever thresholds they want
564 * (nothing will break if they do), but some anal plugin maintainer
565 * will probably add some printf() thing here later, so it might be
566 * best to at least show them where to do it. ;) */
567 if(warn.pl > crit.pl) warn.pl = crit.pl;
568 if(warn.rta > crit.rta) warn.rta = crit.rta;
569 if(warn_down > crit_down) crit_down = warn_down;
571 signal(SIGINT, finish);
572 signal(SIGHUP, finish);
573 signal(SIGTERM, finish);
574 signal(SIGALRM, finish);
575 if(debug) printf("Setting alarm timeout to %u seconds\n", timeout);
576 alarm(timeout);
578 /* make sure we don't wait any longer than necessary */
579 gettimeofday(&prog_start, &tz);
580 max_completion_time =
581 ((targets * packets * pkt_interval) + (targets * target_interval)) +
582 (targets * packets * crit.rta) + crit.rta;
584 if(debug) {
585 printf("packets: %u, targets: %u\n"
586 "target_interval: %0.3f, pkt_interval %0.3f\n"
587 "crit.rta: %0.3f\n"
588 "max_completion_time: %0.3f\n",
589 packets, targets,
590 (float)target_interval / 1000, (float)pkt_interval / 1000,
591 (float)crit.rta / 1000,
592 (float)max_completion_time / 1000);
593 }
595 if(debug) {
596 if(max_completion_time > (u_int)timeout * 1000000) {
597 printf("max_completion_time: %llu timeout: %u\n",
598 max_completion_time, timeout);
599 printf("Timout must be at lest %llu\n",
600 max_completion_time / 1000000 + 1);
601 }
602 }
604 if(debug) {
605 printf("crit = {%u, %u%%}, warn = {%u, %u%%}\n",
606 crit.rta, crit.pl, warn.rta, warn.pl);
607 printf("pkt_interval: %u target_interval: %u retry_interval: %u\n",
608 pkt_interval, target_interval, retry_interval);
609 printf("icmp_pkt_size: %u timeout: %u\n",
610 icmp_pkt_size, timeout);
611 }
613 if(packets > 20) {
614 errno = 0;
615 crash("packets is > 20 (%d)", packets);
616 }
618 if(min_hosts_alive < -1) {
619 errno = 0;
620 crash("minimum alive hosts is negative (%i)", min_hosts_alive);
621 }
623 host = list;
624 table = malloc(sizeof(struct rta_host **) * (argc - 1));
625 i = 0;
626 while(host) {
627 host->id = i*packets;
628 table[i] = host;
629 host = host->next;
630 i++;
631 }
633 run_checks();
635 errno = 0;
636 finish(0);
638 return(0);
639 }
641 static void
642 run_checks()
643 {
644 u_int i, t, result;
645 u_int final_wait, time_passed;
647 /* this loop might actually violate the pkt_interval or target_interval
648 * settings, but only if there aren't any packets on the wire which
649 * indicates that the target can handle an increased packet rate */
650 for(i = 0; i < packets; i++) {
651 for(t = 0; t < targets; t++) {
652 /* don't send useless packets */
653 if(!targets_alive) finish(0);
654 if(table[t]->flags & FLAG_LOST_CAUSE) {
655 if(debug) printf("%s is a lost cause. not sending any more\n",
656 table[t]->name);
657 continue;
658 }
660 /* we're still in the game, so send next packet */
661 (void)send_icmp_ping(icmp_sock, table[t]);
662 result = wait_for_reply(icmp_sock, target_interval);
663 }
664 result = wait_for_reply(icmp_sock, pkt_interval * targets);
665 }
667 if(icmp_pkts_en_route && targets_alive) {
668 time_passed = get_timevaldiff(NULL, NULL);
669 final_wait = max_completion_time - time_passed;
671 if(debug) {
672 printf("time_passed: %u final_wait: %u max_completion_time: %llu\n",
673 time_passed, final_wait, max_completion_time);
674 }
675 if(time_passed > max_completion_time) {
676 if(debug) printf("Time passed. Finishing up\n");
677 finish(0);
678 }
680 /* catch the packets that might come in within the timeframe, but
681 * haven't yet */
682 if(debug) printf("Waiting for %u micro-seconds (%0.3f msecs)\n",
683 final_wait, (float)final_wait / 1000);
684 result = wait_for_reply(icmp_sock, final_wait);
685 }
686 }
688 /* response structure:
689 * ip header : 20 bytes
690 * icmp header : 28 bytes
691 * icmp echo reply : the rest
692 */
693 static int
694 wait_for_reply(int sock, u_int t)
695 {
696 int n, hlen;
697 static unsigned char buf[4096];
698 struct sockaddr_in resp_addr;
699 struct ip *ip;
700 struct icmp icp;
701 struct rta_host *host;
702 struct icmp_ping_data data;
703 struct timeval wait_start, now;
704 u_int tdiff, i, per_pkt_wait;
706 /* if we can't listen or don't have anything to listen to, just return */
707 if(!t || !icmp_pkts_en_route) return 0;
709 gettimeofday(&wait_start, &tz);
711 i = t;
712 per_pkt_wait = t / icmp_pkts_en_route;
713 while(icmp_pkts_en_route && get_timevaldiff(&wait_start, NULL) < i) {
714 t = per_pkt_wait;
716 /* wrap up if all targets are declared dead */
717 if(!targets_alive ||
718 get_timevaldiff(&prog_start, NULL) >= max_completion_time ||
719 (mode == MODE_HOSTCHECK && targets_down))
720 {
721 finish(0);
722 }
724 /* reap responses until we hit a timeout */
725 n = recvfrom_wto(sock, buf, sizeof(buf),
726 (struct sockaddr *)&resp_addr, &t);
727 if(!n) {
728 if(debug > 1) {
729 printf("recvfrom_wto() timed out during a %u usecs wait\n",
730 per_pkt_wait);
731 }
732 continue; /* timeout for this one, so keep trying */
733 }
734 if(n < 0) {
735 if(debug) printf("recvfrom_wto() returned errors\n");
736 return n;
737 }
739 ip = (struct ip *)buf;
740 if(debug > 1) printf("received %u bytes from %s\n",
741 ntohs(ip->ip_len), inet_ntoa(resp_addr.sin_addr));
743 /* obsolete. alpha on tru64 provides the necessary defines, but isn't broken */
744 /* #if defined( __alpha__ ) && __STDC__ && !defined( __GLIBC__ ) */
745 /* alpha headers are decidedly broken. Using an ansi compiler,
746 * they provide ip_vhl instead of ip_hl and ip_v, so we mask
747 * off the bottom 4 bits */
748 /* hlen = (ip->ip_vhl & 0x0f) << 2; */
749 /* #else */
750 hlen = ip->ip_hl << 2;
751 /* #endif */
753 if(n < (hlen + ICMP_MINLEN)) {
754 crash("received packet too short for ICMP (%d bytes, expected %d) from %s\n",
755 n, hlen + icmp_pkt_size, inet_ntoa(resp_addr.sin_addr));
756 }
757 /* else if(debug) { */
758 /* printf("ip header size: %u, packet size: %u (expected %u, %u)\n", */
759 /* hlen, ntohs(ip->ip_len) - hlen, */
760 /* sizeof(struct ip), icmp_pkt_size); */
761 /* } */
763 /* check the response */
764 memcpy(&icp, buf + hlen, sizeof(icp));
766 if(ntohs(icp.icmp_id) != pid || icp.icmp_type != ICMP_ECHOREPLY ||
767 ntohs(icp.icmp_seq) >= targets*packets) {
768 if(debug > 2) printf("not a proper ICMP_ECHOREPLY\n");
769 handle_random_icmp(buf + hlen, &resp_addr);
770 continue;
771 }
773 /* this is indeed a valid response */
774 memcpy(&data, icp.icmp_data, sizeof(data));
775 if (debug > 2)
776 printf("ICMP echo-reply of len %u, id %u, seq %u, cksum 0x%X\n",
777 sizeof(data), ntohs(icp.icmp_id), ntohs(icp.icmp_seq), icp.icmp_cksum);
779 host = table[ntohs(icp.icmp_seq)/packets];
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 void *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 = htons(pid);
850 packet.icp->icmp_seq = htons(host->id++);
851 packet.icp->icmp_cksum = icmp_checksum(packet.cksum_in, icmp_pkt_size);
853 if (debug > 2)
854 printf("Sending ICMP echo-request of len %u, id %u, seq %u, cksum 0x%X to host %s\n",
855 sizeof(data), ntohs(packet.icp->icmp_id), ntohs(packet.icp->icmp_seq), packet.icp->icmp_cksum, host->name);
857 len = sendto(sock, packet.buf, icmp_pkt_size, 0, (struct sockaddr *)addr,
858 sizeof(struct sockaddr));
860 if(len < 0 || (unsigned int)len != icmp_pkt_size) {
861 if(debug) printf("Failed to send ping to %s\n",
862 inet_ntoa(host->saddr_in.sin_addr));
863 return -1;
864 }
866 icmp_sent++;
867 host->icmp_sent++;
869 return 0;
870 }
872 static int
873 recvfrom_wto(int sock, void *buf, unsigned int len, struct sockaddr *saddr,
874 u_int *timo)
875 {
876 u_int slen;
877 int n;
878 struct timeval to, then, now;
879 fd_set rd, wr;
881 if(!*timo) {
882 if(debug) printf("*timo is not\n");
883 return 0;
884 }
886 to.tv_sec = *timo / 1000000;
887 to.tv_usec = (*timo - (to.tv_sec * 1000000));
889 FD_ZERO(&rd);
890 FD_ZERO(&wr);
891 FD_SET(sock, &rd);
892 errno = 0;
893 gettimeofday(&then, &tz);
894 n = select(sock + 1, &rd, &wr, NULL, &to);
895 if(n < 0) crash("select() in recvfrom_wto");
896 gettimeofday(&now, &tz);
897 *timo = get_timevaldiff(&then, &now);
899 if(!n) return 0; /* timeout */
901 slen = sizeof(struct sockaddr);
903 return recvfrom(sock, buf, len, 0, saddr, &slen);
904 }
906 static void
907 finish(int sig)
908 {
909 u_int i = 0;
910 unsigned char pl;
911 double rta;
912 struct rta_host *host;
913 const char *status_string[] =
914 {"OK", "WARNING", "CRITICAL", "UNKNOWN", "DEPENDENT"};
915 int hosts_ok = 0;
916 int hosts_warn = 0;
918 alarm(0);
919 if(debug > 1) printf("finish(%d) called\n", sig);
921 if(icmp_sock != -1) close(icmp_sock);
922 if(udp_sock != -1) close(udp_sock);
923 if(tcp_sock != -1) close(tcp_sock);
925 if(debug) {
926 printf("icmp_sent: %u icmp_recv: %u icmp_lost: %u\n",
927 icmp_sent, icmp_recv, icmp_lost);
928 printf("targets: %u targets_alive: %u\n", targets, targets_alive);
929 }
931 /* iterate thrice to calculate values, give output, and print perfparse */
932 host = list;
933 while(host) {
934 if(!host->icmp_recv) {
935 /* rta 0 is ofcourse not entirely correct, but will still show up
936 * conspicuosly as missing entries in perfparse and cacti */
937 pl = 100;
938 rta = 0;
939 status = STATE_CRITICAL;
940 /* up the down counter if not already counted */
941 if(!(host->flags & FLAG_LOST_CAUSE) && targets_alive) targets_down++;
942 }
943 else {
944 pl = ((host->icmp_sent - host->icmp_recv) * 100) / host->icmp_sent;
945 rta = (double)host->time_waited / host->icmp_recv;
946 }
947 host->pl = pl;
948 host->rta = rta;
949 if(pl >= crit.pl || rta >= crit.rta) {
950 status = STATE_CRITICAL;
951 }
952 else if(!status && (pl >= warn.pl || rta >= warn.rta)) {
953 status = STATE_WARNING;
954 hosts_warn++;
955 }
956 else {
957 hosts_ok++;
958 }
960 host = host->next;
961 }
962 /* this is inevitable */
963 if(!targets_alive) status = STATE_CRITICAL;
964 if(min_hosts_alive > -1) {
965 if(hosts_ok >= min_hosts_alive) status = STATE_OK;
966 else if((hosts_ok + hosts_warn) >= min_hosts_alive) status = STATE_WARNING;
967 }
968 printf("%s - ", status_string[status]);
970 host = list;
971 while(host) {
972 if(debug) puts("");
973 if(i) {
974 if(i < targets) printf(" :: ");
975 else printf("\n");
976 }
977 i++;
978 if(!host->icmp_recv) {
979 status = STATE_CRITICAL;
980 if(host->flags & FLAG_LOST_CAUSE) {
981 printf("%s: %s @ %s. rta nan, lost %d%%",
982 host->name,
983 get_icmp_error_msg(host->icmp_type, host->icmp_code),
984 inet_ntoa(host->error_addr),
985 100);
986 }
987 else { /* not marked as lost cause, so we have no flags for it */
988 printf("%s: rta nan, lost 100%%", host->name);
989 }
990 }
991 else { /* !icmp_recv */
992 printf("%s: rta %0.3fms, lost %u%%",
993 host->name, host->rta / 1000, host->pl);
994 }
996 host = host->next;
997 }
999 /* iterate once more for pretty perfparse output */
1000 printf("|");
1001 i = 0;
1002 host = list;
1003 while(host) {
1004 if(debug) puts("");
1005 printf("%srta=%0.3fms;%0.3f;%0.3f;0; %spl=%u%%;%u;%u;; %srtmax=%0.3fms;;;; %srtmin=%0.3fms;;;; ",
1006 (targets > 1) ? host->name : "",
1007 host->rta / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000,
1008 (targets > 1) ? host->name : "", host->pl, warn.pl, crit.pl,
1009 (targets > 1) ? host->name : "", (float)host->rtmax / 1000,
1010 (targets > 1) ? host->name : "", (host->rtmin < DBL_MAX) ? (float)host->rtmin / 1000 : (float)0);
1012 host = host->next;
1013 }
1015 if(min_hosts_alive > -1) {
1016 if(hosts_ok >= min_hosts_alive) status = STATE_OK;
1017 else if((hosts_ok + hosts_warn) >= min_hosts_alive) status = STATE_WARNING;
1018 }
1020 /* finish with an empty line */
1021 puts("");
1022 if(debug) printf("targets: %u, targets_alive: %u, hosts_ok: %u, hosts_warn: %u, min_hosts_alive: %i\n",
1023 targets, targets_alive, hosts_ok, hosts_warn, min_hosts_alive);
1025 exit(status);
1026 }
1028 static u_int
1029 get_timevaldiff(struct timeval *early, struct timeval *later)
1030 {
1031 u_int ret;
1032 struct timeval now;
1034 if(!later) {
1035 gettimeofday(&now, &tz);
1036 later = &now;
1037 }
1038 if(!early) early = &prog_start;
1040 /* if early > later we return 0 so as to indicate a timeout */
1041 if(early->tv_sec > later->tv_sec ||
1042 (early->tv_sec == later->tv_sec && early->tv_usec > later->tv_usec))
1043 {
1044 return 0;
1045 }
1047 ret = (later->tv_sec - early->tv_sec) * 1000000;
1048 ret += later->tv_usec - early->tv_usec;
1050 return ret;
1051 }
1053 static int
1054 add_target_ip(char *arg, struct in_addr *in)
1055 {
1056 struct rta_host *host;
1058 /* disregard obviously stupid addresses */
1059 if(in->s_addr == INADDR_NONE || in->s_addr == INADDR_ANY)
1060 return -1;
1062 /* no point in adding two identical IP's, so don't. ;) */
1063 host = list;
1064 while(host) {
1065 if(host->saddr_in.sin_addr.s_addr == in->s_addr) {
1066 if(debug) printf("Identical IP already exists. Not adding %s\n", arg);
1067 return -1;
1068 }
1069 host = host->next;
1070 }
1072 /* add the fresh ip */
1073 host = malloc(sizeof(struct rta_host));
1074 if(!host) {
1075 crash("add_target_ip(%s, %s): malloc(%d) failed",
1076 arg, inet_ntoa(*in), sizeof(struct rta_host));
1077 }
1078 memset(host, 0, sizeof(struct rta_host));
1080 /* set the values. use calling name for output */
1081 host->name = strdup(arg);
1083 /* fill out the sockaddr_in struct */
1084 host->saddr_in.sin_family = AF_INET;
1085 host->saddr_in.sin_addr.s_addr = in->s_addr;
1087 host->rtmin = DBL_MAX;
1089 if(!list) list = cursor = host;
1090 else cursor->next = host;
1092 cursor = host;
1093 targets++;
1095 return 0;
1096 }
1098 /* wrapper for add_target_ip */
1099 static int
1100 add_target(char *arg)
1101 {
1102 int i;
1103 struct hostent *he;
1104 struct in_addr *in, ip;
1106 /* don't resolve if we don't have to */
1107 if((ip.s_addr = inet_addr(arg)) != INADDR_NONE) {
1108 /* don't add all ip's if we were given a specific one */
1109 return add_target_ip(arg, &ip);
1110 /* he = gethostbyaddr((char *)in, sizeof(struct in_addr), AF_INET); */
1111 /* if(!he) return add_target_ip(arg, in); */
1112 }
1113 else {
1114 errno = 0;
1115 he = gethostbyname(arg);
1116 if(!he) {
1117 errno = 0;
1118 crash("Failed to resolve %s", arg);
1119 return -1;
1120 }
1121 }
1123 /* possibly add all the IP's as targets */
1124 for(i = 0; he->h_addr_list[i]; i++) {
1125 in = (struct in_addr *)he->h_addr_list[i];
1126 add_target_ip(arg, in);
1128 /* this is silly, but it works */
1129 if(mode == MODE_HOSTCHECK || mode == MODE_ALL) {
1130 if(debug > 2) printf("mode: %d\n", mode);
1131 continue;
1132 }
1133 break;
1134 }
1136 return 0;
1137 }
1139 static void
1140 set_source_ip(char *arg)
1141 {
1142 struct sockaddr_in src;
1144 memset(&src, 0, sizeof(src));
1145 src.sin_family = AF_INET;
1146 if((src.sin_addr.s_addr = inet_addr(arg)) == INADDR_NONE)
1147 src.sin_addr.s_addr = get_ip_address(arg);
1148 if(bind(icmp_sock, (struct sockaddr *)&src, sizeof(src)) == -1)
1149 crash("Cannot bind to IP address %s", arg);
1150 }
1152 /* TODO: Move this to netutils.c and also change check_dhcp to use that. */
1153 static in_addr_t
1154 get_ip_address(const char *ifname)
1155 {
1156 #if defined(SIOCGIFADDR)
1157 struct ifreq ifr;
1158 struct sockaddr_in ip;
1160 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
1161 ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
1162 if(ioctl(icmp_sock, SIOCGIFADDR, &ifr) == -1)
1163 crash("Cannot determine IP address of interface %s", ifname);
1164 memcpy(&ip, &ifr.ifr_addr, sizeof(ip));
1165 return ip.sin_addr.s_addr;
1166 #else
1167 errno = 0;
1168 crash("Cannot get interface IP address on this platform.");
1169 #endif
1170 }
1172 /*
1173 * u = micro
1174 * m = milli
1175 * s = seconds
1176 * return value is in microseconds
1177 */
1178 static u_int
1179 get_timevar(const char *str)
1180 {
1181 char p, u, *ptr;
1182 unsigned int len;
1183 u_int i, d; /* integer and decimal, respectively */
1184 u_int factor = 1000; /* default to milliseconds */
1186 if(!str) return 0;
1187 len = strlen(str);
1188 if(!len) return 0;
1190 /* unit might be given as ms|m (millisec),
1191 * us|u (microsec) or just plain s, for seconds */
1192 u = p = '\0';
1193 u = str[len - 1];
1194 if(len >= 2 && !isdigit((int)str[len - 2])) p = str[len - 2];
1195 if(p && u == 's') u = p;
1196 else if(!p) p = u;
1197 if(debug > 2) printf("evaluating %s, u: %c, p: %c\n", str, u, p);
1199 if(u == 'u') factor = 1; /* microseconds */
1200 else if(u == 'm') factor = 1000; /* milliseconds */
1201 else if(u == 's') factor = 1000000; /* seconds */
1202 if(debug > 2) printf("factor is %u\n", factor);
1204 i = strtoul(str, &ptr, 0);
1205 if(!ptr || *ptr != '.' || strlen(ptr) < 2 || factor == 1)
1206 return i * factor;
1208 /* time specified in usecs can't have decimal points, so ignore them */
1209 if(factor == 1) return i;
1211 d = strtoul(ptr + 1, NULL, 0);
1213 /* d is decimal, so get rid of excess digits */
1214 while(d >= factor) d /= 10;
1216 /* the last parenthesis avoids floating point exceptions. */
1217 return ((i * factor) + (d * (factor / 10)));
1218 }
1220 /* not too good at checking errors, but it'll do (main() should barfe on -1) */
1221 static int
1222 get_threshold(char *str, threshold *th)
1223 {
1224 char *p = NULL, i = 0;
1226 if(!str || !strlen(str) || !th) return -1;
1228 /* pointer magic slims code by 10 lines. i is bof-stop on stupid libc's */
1229 p = &str[strlen(str) - 1];
1230 while(p != &str[1]) {
1231 if(*p == '%') *p = '\0';
1232 else if(*p == ',' && i) {
1233 *p = '\0'; /* reset it so get_timevar(str) works nicely later */
1234 th->pl = (unsigned char)strtoul(p+1, NULL, 0);
1235 break;
1236 }
1237 i = 1;
1238 p--;
1239 }
1240 th->rta = get_timevar(str);
1242 if(!th->rta) return -1;
1244 if(th->rta > MAXTTL * 1000000) th->rta = MAXTTL * 1000000;
1245 if(th->pl > 100) th->pl = 100;
1247 return 0;
1248 }
1250 unsigned short
1251 icmp_checksum(unsigned short *p, int n)
1252 {
1253 register unsigned short cksum;
1254 register long sum = 0;
1256 while(n > 1) {
1257 sum += *p++;
1258 n -= 2;
1259 }
1261 /* mop up the occasional odd byte */
1262 if(n == 1) sum += (unsigned char)*p;
1264 sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
1265 sum += (sum >> 16); /* add carry */
1266 cksum = ~sum; /* ones-complement, trunc to 16 bits */
1268 return cksum;
1269 }
1271 void
1272 print_help(void)
1273 {
1275 /*print_revision (progname);*/ /* FIXME: Why? */
1277 printf ("Copyright (c) 2005 Andreas Ericsson <ae@op5.se>\n");
1278 printf (COPYRIGHT, copyright, email);
1280 printf ("\n\n");
1282 print_usage ();
1284 printf (UT_HELP_VRSN);
1285 printf (UT_EXTRA_OPTS);
1287 printf (" %s\n", "-H");
1288 printf (" %s\n", _("specify a target"));
1289 printf (" %s\n", "-w");
1290 printf (" %s", _("warning threshold (currently "));
1291 printf ("%0.3fms,%u%%)\n", (float)warn.rta / 1000, warn.pl);
1292 printf (" %s\n", "-c");
1293 printf (" %s", _("critical threshold (currently "));
1294 printf ("%0.3fms,%u%%)\n", (float)crit.rta / 1000, crit.pl);
1295 printf (" %s\n", "-s");
1296 printf (" %s\n", _("specify a source IP address or device name"));
1297 printf (" %s\n", "-n");
1298 printf (" %s", _("number of packets to send (currently "));
1299 printf ("%u)\n",packets);
1300 printf (" %s\n", "-i");
1301 printf (" %s", _("max packet interval (currently "));
1302 printf ("%0.3fms)\n",(float)pkt_interval / 1000);
1303 printf (" %s\n", "-I");
1304 printf (" %s", _("max target interval (currently "));
1305 printf ("%0.3fms)\n", (float)target_interval / 1000);
1306 printf (" %s\n", "-m");
1307 printf (" %s",_("number of alive hosts required for success"));
1308 printf ("\n");
1309 printf (" %s\n", "-l");
1310 printf (" %s", _("TTL on outgoing packets (currently "));
1311 printf ("%u)\n", ttl);
1312 printf (" %s\n", "-t");
1313 printf (" %s",_("timeout value (seconds, currently "));
1314 printf ("%u)\n", timeout);
1315 printf (" %s\n", "-b");
1316 printf (" %s\n", _("Number of icmp data bytes to send"));
1317 printf (" %s %u + %d)\n", _("Packet size will be data bytes + icmp header (currently"),icmp_data_size, ICMP_MINLEN);
1318 printf (" %s\n", "-v");
1319 printf (" %s\n", _("verbose"));
1321 printf ("\n");
1322 printf ("%s\n", _("Notes:"));
1323 printf (" %s\n", _("The -H switch is optional. Naming a host (or several) to check is not."));
1324 printf ("\n");
1325 printf (" %s\n", _("Threshold format for -w and -c is 200.25,60% for 200.25 msec RTA and 60%"));
1326 printf (" %s\n", _("packet loss. The default values should work well for most users."));
1327 printf (" %s\n", _("You can specify different RTA factors using the standardized abbreviations"));
1328 printf (" %s\n", _("us (microseconds), ms (milliseconds, default) or just plain s for seconds."));
1329 /* -d not yet implemented */
1330 /* printf ("%s\n", _("Threshold format for -d is warn,crit. 12,14 means WARNING if >= 12 hops"));
1331 printf ("%s\n", _("are spent and CRITICAL if >= 14 hops are spent."));
1332 printf ("%s\n\n", _("NOTE: Some systems decrease TTL when forming ICMP_ECHOREPLY, others do not."));*/
1333 printf ("\n");
1334 printf (" %s\n", _("The -v switch can be specified several times for increased verbosity."));
1335 /* printf ("%s\n", _("Long options are currently unsupported."));
1336 printf ("%s\n", _("Options marked with * require an argument"));
1337 */
1339 printf (UT_SUPPORT);
1340 }
1344 void
1345 print_usage (void)
1346 {
1347 printf ("%s\n", _("Usage:"));
1348 printf(" %s [options] [-H] host1 host2 hostN\n", progname);
1349 }