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, char *, 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(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(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 && 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 || sent_icmp.icmp_id != pid ||
336 sent_icmp.icmp_seq >= targets)
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[sent_icmp.icmp_seq];
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;
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 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(icp.icmp_id != pid) {
767 handle_random_icmp(buf + hlen, &resp_addr);
768 continue;
769 }
771 if(icp.icmp_type != ICMP_ECHOREPLY || icp.icmp_seq >= targets) {
772 if(debug > 2) printf("not a proper ICMP_ECHOREPLY\n");
773 handle_random_icmp(buf + hlen, &resp_addr);
774 continue;
775 }
777 /* this is indeed a valid response */
778 memcpy(&data, icp.icmp_data, sizeof(data));
780 host = table[icp.icmp_seq];
781 gettimeofday(&now, &tz);
782 tdiff = get_timevaldiff(&data.stime, &now);
784 host->time_waited += tdiff;
785 host->icmp_recv++;
786 icmp_recv++;
787 if (tdiff > host->rtmax)
788 host->rtmax = tdiff;
789 if (tdiff < host->rtmin)
790 host->rtmin = tdiff;
792 if(debug) {
793 printf("%0.3f ms rtt from %s, outgoing ttl: %u, incoming ttl: %u, max: %0.3f, min: %0.3f\n",
794 (float)tdiff / 1000, inet_ntoa(resp_addr.sin_addr),
795 ttl, ip->ip_ttl, (float)host->rtmax / 1000, (float)host->rtmin / 1000);
796 }
798 /* if we're in hostcheck mode, exit with limited printouts */
799 if(mode == MODE_HOSTCHECK) {
800 printf("OK - %s responds to ICMP. Packet %u, rta %0.3fms|"
801 "pkt=%u;;0;%u rta=%0.3f;%0.3f;%0.3f;;\n",
802 host->name, icmp_recv, (float)tdiff / 1000,
803 icmp_recv, packets, (float)tdiff / 1000,
804 (float)warn.rta / 1000, (float)crit.rta / 1000);
805 exit(STATE_OK);
806 }
807 }
809 return 0;
810 }
812 /* the ping functions */
813 static int
814 send_icmp_ping(int sock, struct rta_host *host)
815 {
816 static union {
817 char *buf; /* re-use so we prevent leaks */
818 struct icmp *icp;
819 u_short *cksum_in;
820 } packet = { NULL };
821 long int len;
822 struct icmp_ping_data data;
823 struct timeval tv;
824 struct sockaddr *addr;
826 if(sock == -1) {
827 errno = 0;
828 crash("Attempt to send on bogus socket");
829 return -1;
830 }
831 addr = (struct sockaddr *)&host->saddr_in;
833 if(!packet.buf) {
834 if (!(packet.buf = malloc(icmp_pkt_size))) {
835 crash("send_icmp_ping(): failed to malloc %d bytes for send buffer",
836 icmp_pkt_size);
837 return -1; /* might be reached if we're in debug mode */
838 }
839 }
840 memset(packet.buf, 0, icmp_pkt_size);
842 if((gettimeofday(&tv, &tz)) == -1) return -1;
844 data.ping_id = 10; /* host->icmp.icmp_sent; */
845 memcpy(&data.stime, &tv, sizeof(tv));
846 memcpy(&packet.icp->icmp_data, &data, sizeof(data));
847 packet.icp->icmp_type = ICMP_ECHO;
848 packet.icp->icmp_code = 0;
849 packet.icp->icmp_cksum = 0;
850 packet.icp->icmp_id = pid;
851 packet.icp->icmp_seq = host->id;
852 packet.icp->icmp_cksum = icmp_checksum(packet.cksum_in, icmp_pkt_size);
854 len = sendto(sock, packet.buf, icmp_pkt_size, 0, (struct sockaddr *)addr,
855 sizeof(struct sockaddr));
857 if(len < 0 || (unsigned int)len != icmp_pkt_size) {
858 if(debug) printf("Failed to send ping to %s\n",
859 inet_ntoa(host->saddr_in.sin_addr));
860 return -1;
861 }
863 icmp_sent++;
864 host->icmp_sent++;
866 return 0;
867 }
869 static int
870 recvfrom_wto(int sock, char *buf, unsigned int len, struct sockaddr *saddr,
871 u_int *timo)
872 {
873 u_int slen;
874 int n;
875 struct timeval to, then, now;
876 fd_set rd, wr;
878 if(!*timo) {
879 if(debug) printf("*timo is not\n");
880 return 0;
881 }
883 to.tv_sec = *timo / 1000000;
884 to.tv_usec = (*timo - (to.tv_sec * 1000000));
886 FD_ZERO(&rd);
887 FD_ZERO(&wr);
888 FD_SET(sock, &rd);
889 errno = 0;
890 gettimeofday(&then, &tz);
891 n = select(sock + 1, &rd, &wr, NULL, &to);
892 if(n < 0) crash("select() in recvfrom_wto");
893 gettimeofday(&now, &tz);
894 *timo = get_timevaldiff(&then, &now);
896 if(!n) return 0; /* timeout */
898 slen = sizeof(struct sockaddr);
900 return recvfrom(sock, buf, len, 0, saddr, &slen);
901 }
903 static void
904 finish(int sig)
905 {
906 u_int i = 0;
907 unsigned char pl;
908 double rta;
909 struct rta_host *host;
910 const char *status_string[] =
911 {"OK", "WARNING", "CRITICAL", "UNKNOWN", "DEPENDENT"};
912 int hosts_ok = 0;
913 int hosts_warn = 0;
915 alarm(0);
916 if(debug > 1) printf("finish(%d) called\n", sig);
918 if(icmp_sock != -1) close(icmp_sock);
919 if(udp_sock != -1) close(udp_sock);
920 if(tcp_sock != -1) close(tcp_sock);
922 if(debug) {
923 printf("icmp_sent: %u icmp_recv: %u icmp_lost: %u\n",
924 icmp_sent, icmp_recv, icmp_lost);
925 printf("targets: %u targets_alive: %u\n", targets, targets_alive);
926 }
928 /* iterate thrice to calculate values, give output, and print perfparse */
929 host = list;
930 while(host) {
931 if(!host->icmp_recv) {
932 /* rta 0 is ofcourse not entirely correct, but will still show up
933 * conspicuosly as missing entries in perfparse and cacti */
934 pl = 100;
935 rta = 0;
936 status = STATE_CRITICAL;
937 /* up the down counter if not already counted */
938 if(!(host->flags & FLAG_LOST_CAUSE) && targets_alive) targets_down++;
939 }
940 else {
941 pl = ((host->icmp_sent - host->icmp_recv) * 100) / host->icmp_sent;
942 rta = (double)host->time_waited / host->icmp_recv;
943 }
944 host->pl = pl;
945 host->rta = rta;
946 if(pl >= crit.pl || rta >= crit.rta) {
947 status = STATE_CRITICAL;
948 }
949 else if(!status && (pl >= warn.pl || rta >= warn.rta)) {
950 status = STATE_WARNING;
951 hosts_warn++;
952 }
953 else {
954 hosts_ok++;
955 }
957 host = host->next;
958 }
959 /* this is inevitable */
960 if(!targets_alive) status = STATE_CRITICAL;
961 if(min_hosts_alive > -1) {
962 if(hosts_ok >= min_hosts_alive) status = STATE_OK;
963 else if((hosts_ok + hosts_warn) >= min_hosts_alive) status = STATE_WARNING;
964 }
965 printf("%s - ", status_string[status]);
967 host = list;
968 while(host) {
969 if(debug) puts("");
970 if(i) {
971 if(i < targets) printf(" :: ");
972 else printf("\n");
973 }
974 i++;
975 if(!host->icmp_recv) {
976 status = STATE_CRITICAL;
977 if(host->flags & FLAG_LOST_CAUSE) {
978 printf("%s: %s @ %s. rta nan, lost %d%%",
979 host->name,
980 get_icmp_error_msg(host->icmp_type, host->icmp_code),
981 inet_ntoa(host->error_addr),
982 100);
983 }
984 else { /* not marked as lost cause, so we have no flags for it */
985 printf("%s: rta nan, lost 100%%", host->name);
986 }
987 }
988 else { /* !icmp_recv */
989 printf("%s: rta %0.3fms, lost %u%%",
990 host->name, host->rta / 1000, host->pl);
991 }
993 host = host->next;
994 }
996 /* iterate once more for pretty perfparse output */
997 printf("|");
998 i = 0;
999 host = list;
1000 while(host) {
1001 if(debug) puts("");
1002 printf("%srta=%0.3fms;%0.3f;%0.3f;0; %spl=%u%%;%u;%u;; %srtmax=%0.3fms;;;; %srtmin=%0.3fms;;;; ",
1003 (targets > 1) ? host->name : "",
1004 host->rta / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000,
1005 (targets > 1) ? host->name : "", host->pl, warn.pl, crit.pl,
1006 (targets > 1) ? host->name : "", (float)host->rtmax / 1000,
1007 (targets > 1) ? host->name : "", (host->rtmin < DBL_MAX) ? (float)host->rtmin / 1000 : (float)0);
1009 host = host->next;
1010 }
1012 if(min_hosts_alive > -1) {
1013 if(hosts_ok >= min_hosts_alive) status = STATE_OK;
1014 else if((hosts_ok + hosts_warn) >= min_hosts_alive) status = STATE_WARNING;
1015 }
1017 /* finish with an empty line */
1018 puts("");
1019 if(debug) printf("targets: %u, targets_alive: %u, hosts_ok: %u, hosts_warn: %u, min_hosts_alive: %i\n",
1020 targets, targets_alive, hosts_ok, hosts_warn, min_hosts_alive);
1022 exit(status);
1023 }
1025 static u_int
1026 get_timevaldiff(struct timeval *early, struct timeval *later)
1027 {
1028 u_int ret;
1029 struct timeval now;
1031 if(!later) {
1032 gettimeofday(&now, &tz);
1033 later = &now;
1034 }
1035 if(!early) early = &prog_start;
1037 /* if early > later we return 0 so as to indicate a timeout */
1038 if(early->tv_sec > early->tv_sec ||
1039 (early->tv_sec == later->tv_sec && early->tv_usec > later->tv_usec))
1040 {
1041 return 0;
1042 }
1044 ret = (later->tv_sec - early->tv_sec) * 1000000;
1045 ret += later->tv_usec - early->tv_usec;
1047 return ret;
1048 }
1050 static int
1051 add_target_ip(char *arg, struct in_addr *in)
1052 {
1053 struct rta_host *host;
1055 /* disregard obviously stupid addresses */
1056 if(in->s_addr == INADDR_NONE || in->s_addr == INADDR_ANY)
1057 return -1;
1059 /* no point in adding two identical IP's, so don't. ;) */
1060 host = list;
1061 while(host) {
1062 if(host->saddr_in.sin_addr.s_addr == in->s_addr) {
1063 if(debug) printf("Identical IP already exists. Not adding %s\n", arg);
1064 return -1;
1065 }
1066 host = host->next;
1067 }
1069 /* add the fresh ip */
1070 host = malloc(sizeof(struct rta_host));
1071 if(!host) {
1072 crash("add_target_ip(%s, %s): malloc(%d) failed",
1073 arg, inet_ntoa(*in), sizeof(struct rta_host));
1074 }
1075 memset(host, 0, sizeof(struct rta_host));
1077 /* set the values. use calling name for output */
1078 host->name = strdup(arg);
1080 /* fill out the sockaddr_in struct */
1081 host->saddr_in.sin_family = AF_INET;
1082 host->saddr_in.sin_addr.s_addr = in->s_addr;
1084 host->rtmin = DBL_MAX;
1086 if(!list) list = cursor = host;
1087 else cursor->next = host;
1089 cursor = host;
1090 targets++;
1092 return 0;
1093 }
1095 /* wrapper for add_target_ip */
1096 static int
1097 add_target(char *arg)
1098 {
1099 int i;
1100 struct hostent *he;
1101 struct in_addr *in, ip;
1103 /* don't resolve if we don't have to */
1104 if((ip.s_addr = inet_addr(arg)) != INADDR_NONE) {
1105 /* don't add all ip's if we were given a specific one */
1106 return add_target_ip(arg, &ip);
1107 /* he = gethostbyaddr((char *)in, sizeof(struct in_addr), AF_INET); */
1108 /* if(!he) return add_target_ip(arg, in); */
1109 }
1110 else {
1111 errno = 0;
1112 he = gethostbyname(arg);
1113 if(!he) {
1114 errno = 0;
1115 crash("Failed to resolve %s", arg);
1116 return -1;
1117 }
1118 }
1120 /* possibly add all the IP's as targets */
1121 for(i = 0; he->h_addr_list[i]; i++) {
1122 in = (struct in_addr *)he->h_addr_list[i];
1123 add_target_ip(arg, in);
1125 /* this is silly, but it works */
1126 if(mode == MODE_HOSTCHECK || mode == MODE_ALL) {
1127 if(debug > 2) printf("mode: %d\n", mode);
1128 continue;
1129 }
1130 break;
1131 }
1133 return 0;
1134 }
1136 static void
1137 set_source_ip(char *arg)
1138 {
1139 struct sockaddr_in src;
1141 memset(&src, 0, sizeof(src));
1142 src.sin_family = AF_INET;
1143 if((src.sin_addr.s_addr = inet_addr(arg)) == INADDR_NONE)
1144 src.sin_addr.s_addr = get_ip_address(arg);
1145 if(bind(icmp_sock, (struct sockaddr *)&src, sizeof(src)) == -1)
1146 crash("Cannot bind to IP address %s", arg);
1147 }
1149 /* TODO: Move this to netutils.c and also change check_dhcp to use that. */
1150 static in_addr_t
1151 get_ip_address(const char *ifname)
1152 {
1153 #if defined(SIOCGIFADDR)
1154 struct ifreq ifr;
1155 struct sockaddr_in ip;
1157 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
1158 ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
1159 if(ioctl(icmp_sock, SIOCGIFADDR, &ifr) == -1)
1160 crash("Cannot determine IP address of interface %s", ifname);
1161 memcpy(&ip, &ifr.ifr_addr, sizeof(ip));
1162 return ip.sin_addr.s_addr;
1163 #else
1164 errno = 0;
1165 crash("Cannot get interface IP address on this platform.");
1166 #endif
1167 }
1169 /*
1170 * u = micro
1171 * m = milli
1172 * s = seconds
1173 * return value is in microseconds
1174 */
1175 static u_int
1176 get_timevar(const char *str)
1177 {
1178 char p, u, *ptr;
1179 unsigned int len;
1180 u_int i, d; /* integer and decimal, respectively */
1181 u_int factor = 1000; /* default to milliseconds */
1183 if(!str) return 0;
1184 len = strlen(str);
1185 if(!len) return 0;
1187 /* unit might be given as ms|m (millisec),
1188 * us|u (microsec) or just plain s, for seconds */
1189 u = p = '\0';
1190 u = str[len - 1];
1191 if(len >= 2 && !isdigit((int)str[len - 2])) p = str[len - 2];
1192 if(p && u == 's') u = p;
1193 else if(!p) p = u;
1194 if(debug > 2) printf("evaluating %s, u: %c, p: %c\n", str, u, p);
1196 if(u == 'u') factor = 1; /* microseconds */
1197 else if(u == 'm') factor = 1000; /* milliseconds */
1198 else if(u == 's') factor = 1000000; /* seconds */
1199 if(debug > 2) printf("factor is %u\n", factor);
1201 i = strtoul(str, &ptr, 0);
1202 if(!ptr || *ptr != '.' || strlen(ptr) < 2 || factor == 1)
1203 return i * factor;
1205 /* time specified in usecs can't have decimal points, so ignore them */
1206 if(factor == 1) return i;
1208 d = strtoul(ptr + 1, NULL, 0);
1210 /* d is decimal, so get rid of excess digits */
1211 while(d >= factor) d /= 10;
1213 /* the last parenthesis avoids floating point exceptions. */
1214 return ((i * factor) + (d * (factor / 10)));
1215 }
1217 /* not too good at checking errors, but it'll do (main() should barfe on -1) */
1218 static int
1219 get_threshold(char *str, threshold *th)
1220 {
1221 char *p = NULL, i = 0;
1223 if(!str || !strlen(str) || !th) return -1;
1225 /* pointer magic slims code by 10 lines. i is bof-stop on stupid libc's */
1226 p = &str[strlen(str) - 1];
1227 while(p != &str[1]) {
1228 if(*p == '%') *p = '\0';
1229 else if(*p == ',' && i) {
1230 *p = '\0'; /* reset it so get_timevar(str) works nicely later */
1231 th->pl = (unsigned char)strtoul(p+1, NULL, 0);
1232 break;
1233 }
1234 i = 1;
1235 p--;
1236 }
1237 th->rta = get_timevar(str);
1239 if(!th->rta) return -1;
1241 if(th->rta > MAXTTL * 1000000) th->rta = MAXTTL * 1000000;
1242 if(th->pl > 100) th->pl = 100;
1244 return 0;
1245 }
1247 unsigned short
1248 icmp_checksum(unsigned short *p, int n)
1249 {
1250 register unsigned short cksum;
1251 register long sum = 0;
1253 while(n > 1) {
1254 sum += *p++;
1255 n -= 2;
1256 }
1258 /* mop up the occasional odd byte */
1259 if(n == 1) sum += (unsigned char)*p;
1261 sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
1262 sum += (sum >> 16); /* add carry */
1263 cksum = ~sum; /* ones-complement, trunc to 16 bits */
1265 return cksum;
1266 }
1268 void
1269 print_help(void)
1270 {
1272 /*print_revision (progname);*/ /* FIXME: Why? */
1274 printf ("Copyright (c) 2005 Andreas Ericsson <ae@op5.se>\n");
1275 printf (COPYRIGHT, copyright, email);
1277 printf ("\n\n");
1279 print_usage ();
1281 printf (_(UT_HELP_VRSN));
1282 printf (_(UT_EXTRA_OPTS));
1284 printf (" %s\n", "-H");
1285 printf (" %s\n", _("specify a target"));
1286 printf (" %s\n", "-w");
1287 printf (" %s", _("warning threshold (currently "));
1288 printf ("%0.3fms,%u%%)\n", (float)warn.rta / 1000, warn.pl);
1289 printf (" %s\n", "-c");
1290 printf (" %s", _("critical threshold (currently "));
1291 printf ("%0.3fms,%u%%)\n", (float)crit.rta / 1000, crit.pl);
1292 printf (" %s\n", "-s");
1293 printf (" %s\n", _("specify a source IP address or device name"));
1294 printf (" %s\n", "-n");
1295 printf (" %s", _("number of packets to send (currently "));
1296 printf ("%u)\n",packets);
1297 printf (" %s\n", "-i");
1298 printf (" %s", _("max packet interval (currently "));
1299 printf ("%0.3fms)\n",(float)pkt_interval / 1000);
1300 printf (" %s\n", "-I");
1301 printf (" %s", _("max target interval (currently "));
1302 printf ("%0.3fms)\n", (float)target_interval / 1000);
1303 printf (" %s\n", "-m");
1304 printf (" %s",_("number of alive hosts required for success"));
1305 printf ("\n");
1306 printf (" %s\n", "-l");
1307 printf (" %s", _("TTL on outgoing packets (currently "));
1308 printf ("%u)\n", ttl);
1309 printf (" %s\n", "-t");
1310 printf (" %s",_("timeout value (seconds, currently "));
1311 printf ("%u)\n", timeout);
1312 printf (" %s\n", "-b");
1313 printf (" %s\n", _("Number of icmp data bytes to send"));
1314 printf (" %s %u + %d)\n", _("Packet size will be data bytes + icmp header (currently"),icmp_data_size, ICMP_MINLEN);
1315 printf (" %s\n", "-v");
1316 printf (" %s\n", _("verbose"));
1318 printf ("\n");
1319 printf ("%s\n", _("Notes:"));
1320 printf (" %s\n", _("The -H switch is optional. Naming a host (or several) to check is not."));
1321 printf ("\n");
1322 printf (" %s\n", _("Threshold format for -w and -c is 200.25,60% for 200.25 msec RTA and 60%"));
1323 printf (" %s\n", _("packet loss. The default values should work well for most users."));
1324 printf (" %s\n", _("You can specify different RTA factors using the standardized abbreviations"));
1325 printf (" %s\n", _("us (microseconds), ms (milliseconds, default) or just plain s for seconds."));
1326 /* -d not yet implemented */
1327 /* printf ("%s\n", _("Threshold format for -d is warn,crit. 12,14 means WARNING if >= 12 hops"));
1328 printf ("%s\n", _("are spent and CRITICAL if >= 14 hops are spent."));
1329 printf ("%s\n\n", _("NOTE: Some systems decrease TTL when forming ICMP_ECHOREPLY, others do not."));*/
1330 printf ("\n");
1331 printf (" %s\n", _("The -v switch can be specified several times for increased verbosity."));
1332 /* printf ("%s\n", _("Long options are currently unsupported."));
1333 printf ("%s\n", _("Options marked with * require an argument"));
1334 */
1335 #ifdef NP_EXTRA_OPTS
1336 printf ("\n");
1337 printf (_(UT_EXTRA_OPTS_NOTES));
1338 #endif
1340 printf (_(UT_SUPPORT));
1341 }
1345 void
1346 print_usage (void)
1347 {
1348 printf (_("Usage:"));
1349 printf(" %s [options] [-H] host1 host2 hostN\n", progname);
1350 }