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