check_icmp.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376
  1. /*
  2. * $Id$
  3. *
  4. * This is a hack of fping2 made to work with nagios.
  5. * It's fast and removes the necessity of parsing another programs output.
  6. *
  7. * VIEWING NOTES:
  8. * This file was formatted with tab indents at a tab stop of 4.
  9. *
  10. * It is highly recommended that your editor is set to this
  11. * tab stop setting for viewing and editing.
  12. *
  13. * COPYLEFT;
  14. * This programs copyright status is currently undetermined. Much of
  15. * the code in it comes from the fping2 program which used to be licensed
  16. * under the Stanford General Software License (available at
  17. * http://graphics.stanford.edu/software/license.html). It is presently
  18. * unclear what license (if any) applies to the original code at the
  19. * moment.
  20. *
  21. * The fping website can be found at http://www.fping.com
  22. */
  23. #include <stdio.h>
  24. #include <errno.h>
  25. #include <time.h>
  26. #include <signal.h>
  27. #include <unistd.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <stddef.h>
  31. #include <sys/types.h>
  32. #include <sys/time.h>
  33. #include <sys/socket.h>
  34. #include <sys/file.h>
  35. #include <netinet/in_systm.h>
  36. #include <netinet/in.h>
  37. #include <netinet/ip.h>
  38. #include <netinet/ip_icmp.h>
  39. #include <arpa/inet.h>
  40. #include <netdb.h>
  41. /* RS6000 has sys/select.h */
  42. #ifdef HAVE_SYS_SELECT_H
  43. #include <sys/select.h>
  44. #endif /* HAVE_SYS_SELECT_H */
  45. /* rta threshold values can't be larger than MAXTTL seconds */
  46. #ifndef MAXTTL
  47. # define MAXTTL 255
  48. #endif
  49. #ifndef IPDEFTTL
  50. # define IPDEFTTL 64
  51. #endif
  52. /*** externals ***/
  53. extern char *optarg;
  54. extern int optind, opterr;
  55. /*** Constants ***/
  56. #define EMAIL "ae@op5.se"
  57. #define VERSION "0.8.1"
  58. #ifndef INADDR_NONE
  59. # define INADDR_NONE 0xffffffU
  60. #endif
  61. /*** Ping packet defines ***/
  62. /* data added after ICMP header for our nefarious purposes */
  63. typedef struct ping_data {
  64. unsigned int ping_count; /* counts up to -[n|p] count or 1 */
  65. struct timeval ping_ts; /* time sent */
  66. } PING_DATA;
  67. #define MIN_PING_DATA sizeof(PING_DATA)
  68. #define MAX_IP_PACKET 65536 /* (theoretical) max IP packet size */
  69. #define SIZE_IP_HDR 20
  70. #define SIZE_ICMP_HDR ICMP_MINLEN /* from ip_icmp.h */
  71. #define MAX_PING_DATA (MAX_IP_PACKET - SIZE_IP_HDR - SIZE_ICMP_HDR)
  72. /*
  73. * Interval is the minimum amount of time between sending a ping packet to
  74. * any host.
  75. *
  76. * Perhost_interval is the minimum amount of time between sending a ping
  77. * packet to a particular responding host
  78. *
  79. * Timeout is the initial amount of time between sending a ping packet to
  80. * a particular non-responding host.
  81. *
  82. * Retry is the number of ping packets to send to a non-responding host
  83. * before giving up (in is-it-alive mode).
  84. *
  85. * Backoff factor is how much longer to wait on successive retries.
  86. */
  87. #ifndef DEFAULT_INTERVAL
  88. #define DEFAULT_INTERVAL 25 /* default time between packets (msec) */
  89. #endif
  90. #ifndef DEFAULT_RETRY
  91. #define DEFAULT_RETRY 1 /* number of times to retry a host */
  92. #endif
  93. #ifndef DEFAULT_TIMEOUT
  94. # define DEFAULT_TIMEOUT 1000
  95. #endif
  96. #ifndef DEFAULT_BACKOFF_FACTOR
  97. #define DEFAULT_BACKOFF_FACTOR 1.5 /* exponential timeout factor */
  98. #endif
  99. #define MIN_BACKOFF_FACTOR 1.0 /* exponential timeout factor */
  100. #define MAX_BACKOFF_FACTOR 5.0 /* exponential timeout factor */
  101. #ifndef DNS_TIMEOUT
  102. #define DNS_TIMEOUT 1000 /* time in usec for dns retry */
  103. #endif
  104. #ifndef MAX_RTA_THRESHOLD_VALUE
  105. # define MAX_RTA_THRESHOLD_VALUE 120*1000000 /* 2 minutes should be enough */
  106. #endif
  107. #ifndef MIN_RTA_THRESHOLD_VALUE
  108. # define MIN_RTA_THRESHOLD_VALUE 10000 /* minimum RTA threshold value */
  109. #endif
  110. /* sized so as to be like traditional ping */
  111. #define DEFAULT_PING_DATA_SIZE (MIN_PING_DATA + 44)
  112. /* maxima and minima */
  113. #define MAX_COUNT 50 /* max count even if we're root */
  114. #define MAX_RETRY 5
  115. #define MIN_INTERVAL 25 /* msecs */
  116. #define MIN_TIMEOUT 50 /* msecs */
  117. /* response time array flags */
  118. #define RESP_WAITING -1
  119. #define RESP_UNUSED -2
  120. #define ICMP_UNREACH_MAXTYPE 15
  121. /* entry used to keep track of each host we are pinging */
  122. struct host_entry {
  123. int i; /* index into array */
  124. char *name; /* name as given by user */
  125. char *host; /* text description of host */
  126. struct sockaddr_in saddr; /* internet address */
  127. unsigned short **pr; /* TCP port range to check for connectivity */
  128. struct timeval last_send_time; /* time of last packet sent */
  129. unsigned int num_sent; /* number of ping packets sent */
  130. unsigned int num_recv; /* number of pings received */
  131. unsigned int total_time; /* sum of response times */
  132. unsigned int status; /* this hosts status */
  133. unsigned int running; /* unset when through sending */
  134. unsigned int waiting; /* waiting for response */
  135. int *resp_times; /* individual response times */
  136. struct host_entry *prev, *next; /* doubly linked list */
  137. };
  138. typedef struct host_entry HOST_ENTRY;
  139. struct host_name_list {
  140. char *entry;
  141. struct host_name_list *next;
  142. };
  143. /* threshold structure */
  144. struct threshold {
  145. unsigned int pl; /* packet loss */
  146. unsigned int rta; /* roundtrip time average */
  147. };
  148. typedef struct threshold threshold;
  149. /*****************************************************************************
  150. * Global Variables *
  151. *****************************************************************************/
  152. HOST_ENTRY *rrlist = NULL; /* linked list of hosts be pinged */
  153. HOST_ENTRY **table = NULL; /* array of pointers to items in the list */
  154. HOST_ENTRY *cursor;
  155. char *prog; /* our name */
  156. int ident; /* our pid, for marking icmp packets */
  157. int sock; /* socket */
  158. u_int debug = 0;
  159. /* threshold value defaults;
  160. * WARNING; 60% packetloss or 200 msecs round trip average
  161. * CRITICAL; 80% packetloss or 500 msecs round trip average */
  162. threshold warn = {60, 200 * 1000};
  163. threshold crit = {80, 500 * 1000};
  164. /* times get *100 because all times are calculated in 10 usec units, not ms */
  165. unsigned int retry = DEFAULT_RETRY;
  166. u_int timeout = DEFAULT_TIMEOUT * 100;
  167. u_int interval = DEFAULT_INTERVAL * 100;
  168. float backoff = DEFAULT_BACKOFF_FACTOR;
  169. u_int select_time; /* calculated using maximum threshold rta value */
  170. u_int ping_data_size = DEFAULT_PING_DATA_SIZE;
  171. u_int ping_pkt_size;
  172. unsigned int count = 5;
  173. unsigned int trials = 1;
  174. /* global stats */
  175. int total_replies = 0;
  176. int num_jobs = 0; /* number of hosts still to do */
  177. int num_hosts = 0; /* total number of hosts */
  178. int num_alive = 0; /* total number alive */
  179. int num_unreachable = 0; /* total number unreachable */
  180. int num_noaddress = 0; /* total number of addresses not found */
  181. int num_timeout = 0; /* number of timed out packets */
  182. int num_pingsent = 0; /* total pings sent */
  183. int num_pingreceived = 0; /* total pings received */
  184. int num_othericmprcvd = 0; /* total non-echo-reply ICMP received */
  185. struct timeval current_time; /* current time (pseudo) */
  186. struct timeval start_time;
  187. struct timeval end_time;
  188. struct timeval last_send_time; /* time last ping was sent */
  189. struct timezone tz;
  190. /* switches */
  191. int generate_flag = 0; /* flag for IP list generation */
  192. int stats_flag, unreachable_flag, alive_flag;
  193. int elapsed_flag, version_flag, count_flag;
  194. int name_flag, addr_flag, backoff_flag;
  195. int multif_flag;
  196. /*** prototypes ***/
  197. void add_name(char *);
  198. void add_addr(char *, char *, struct in_addr);
  199. char *na_cat(char *, struct in_addr);
  200. char *cpystr(char *);
  201. void crash(char *);
  202. char *get_host_by_address(struct in_addr);
  203. int in_cksum(u_short *, int);
  204. void u_sleep(int);
  205. int recvfrom_wto(int, char *, int, struct sockaddr *, int);
  206. void remove_job(HOST_ENTRY *);
  207. void send_ping(int, HOST_ENTRY *);
  208. long timeval_diff(struct timeval *, struct timeval *);
  209. void usage(void);
  210. int wait_for_reply(int);
  211. void finish(void);
  212. int handle_random_icmp(struct icmp *, struct sockaddr_in *);
  213. char *sprint_tm(int);
  214. int get_threshold(char *, threshold *);
  215. /*** the various exit-states */
  216. enum {
  217. STATE_OK = 0,
  218. STATE_WARNING,
  219. STATE_CRITICAL,
  220. STATE_UNKNOWN,
  221. STATE_DEPENDANT,
  222. STATE_OOB
  223. };
  224. /* the strings that correspond to them */
  225. char *status_string[STATE_OOB] = {
  226. "OK",
  227. "WARNING",
  228. "CRITICAL",
  229. "UNKNOWN",
  230. "DEPENDANT"
  231. };
  232. int status = STATE_OK;
  233. int fin_stat = STATE_OK;
  234. /*****************************************************************************
  235. * Code block start *
  236. *****************************************************************************/
  237. int main(int argc, char **argv)
  238. {
  239. int c;
  240. u_int lt, ht;
  241. int advance;
  242. struct protoent *proto;
  243. uid_t uid;
  244. struct host_name_list *host_ptr, *host_base_ptr;
  245. if(strchr(argv[0], '/')) prog = strrchr(argv[0], '/') + 1;
  246. else prog = argv[0];
  247. /* check if we are root */
  248. if(geteuid()) {
  249. printf("Root access needed (for raw sockets)\n");
  250. exit(STATE_UNKNOWN);
  251. }
  252. /* confirm that ICMP is available on this machine */
  253. if((proto = getprotobyname("icmp")) == NULL)
  254. crash("icmp: unknown protocol");
  255. /* create raw socket for ICMP calls (ping) */
  256. sock = socket(AF_INET, SOCK_RAW, proto->p_proto);
  257. if(sock < 0)
  258. crash("can't create raw socket");
  259. /* drop privileges now that we have the socket */
  260. if((uid = getuid())) {
  261. seteuid(uid);
  262. }
  263. if(argc < 2) usage();
  264. ident = getpid() & 0xFFFF;
  265. if(!(host_base_ptr = malloc(sizeof(struct host_name_list)))) {
  266. crash("Unable to allocate memory for host name list\n");
  267. }
  268. host_ptr = host_base_ptr;
  269. backoff_flag = 0;
  270. opterr = 1;
  271. /* get command line options
  272. * -H denotes a host (actually ignored and picked up later)
  273. * -h for help
  274. * -V or -v for version
  275. * -d to display hostnames rather than addresses
  276. * -t sets timeout for packets and tcp connects
  277. * -r defines retries (persistence)
  278. * -p or -n sets packet count (5)
  279. * -b sets packet size (56)
  280. * -w sets warning threshhold (200,40%)
  281. * -c sets critical threshhold (500,80%)
  282. * -i sets interval for both packet transmissions and connect attempts
  283. */
  284. #define OPT_STR "amH:hvVDdAp:n:b:r:t:i:w:c:"
  285. while((c = getopt(argc, argv, OPT_STR)) != EOF) {
  286. switch (c) {
  287. case 'H':
  288. if(!(host_ptr->entry = malloc(strlen(optarg) + 1))) {
  289. crash("Failed to allocate memory for hostname");
  290. }
  291. memset(host_ptr->entry, 0, strlen(optarg) + 1);
  292. host_ptr->entry = memcpy(host_ptr->entry, optarg, strlen(optarg));
  293. if(!(host_ptr->next = malloc(sizeof(struct host_name_list))))
  294. crash("Failed to allocate memory for hostname");
  295. host_ptr = host_ptr->next;
  296. host_ptr->next = NULL;
  297. // add_name(optarg);
  298. break;
  299. /* this is recognized, but silently ignored.
  300. * host(s) are added later on */
  301. break;
  302. case 'w':
  303. if(get_threshold(optarg, &warn)) {
  304. printf("Illegal threshold pair specified for -%c", c);
  305. usage();
  306. }
  307. break;
  308. case 'c':
  309. if(get_threshold(optarg, &crit)) {
  310. printf("Illegal threshold pair specified for -%c", c);
  311. usage();
  312. }
  313. break;
  314. case 't':
  315. if(!(timeout = (u_int) strtoul(optarg, NULL, 0) * 100)) {
  316. printf("option -%c requires integer argument\n", c);
  317. usage();
  318. }
  319. break;
  320. case 'r':
  321. if(!(retry = (u_int) strtoul(optarg, NULL, 0))) {
  322. printf("option -%c requires integer argument\n", c);
  323. usage();
  324. }
  325. break;
  326. case 'i':
  327. if(!(interval = (u_int) strtoul(optarg, NULL, 0) * 100)) {
  328. printf("option -%c requires positive non-zero integer argument\n", c);
  329. usage();
  330. }
  331. break;
  332. case 'p':
  333. case 'n':
  334. if(!(count = (u_int) strtoul(optarg, NULL, 0))) {
  335. printf("option -%c requires positive non-zero integer argument\n", c);
  336. usage();
  337. }
  338. break;
  339. case 'b':
  340. if(!(ping_data_size = (u_int) strtoul(optarg, NULL, 0))) {
  341. printf("option -%c requires integer argument\n", c);
  342. usage();
  343. }
  344. break;
  345. case 'h':
  346. usage();
  347. break;
  348. case 'e':
  349. elapsed_flag = 1;
  350. break;
  351. case 'm':
  352. multif_flag = 1;
  353. break;
  354. case 'd':
  355. name_flag = 1;
  356. break;
  357. case 'A':
  358. addr_flag = 1;
  359. break;
  360. case 's':
  361. stats_flag = 1;
  362. break;
  363. case 'u':
  364. unreachable_flag = 1;
  365. break;
  366. case 'a':
  367. alive_flag = 1;
  368. break;
  369. case 'v':
  370. printf("%s: Version %s $Date$\n", prog, VERSION);
  371. printf("%s: comments to %s\n", prog, EMAIL);
  372. exit(STATE_OK);
  373. case 'g':
  374. /* use IP list generation */
  375. /* mutex with file input or command line targets */
  376. generate_flag = 1;
  377. break;
  378. default:
  379. printf("option flag -%c specified, but not recognized\n", c);
  380. usage();
  381. break;
  382. }
  383. }
  384. /* arguments are parsed, so now we validate them */
  385. if(count > 1) count_flag = 1;
  386. /* set threshold values to 10usec units (inherited from fping.c) */
  387. crit.rta = crit.rta / 10;
  388. warn.rta = warn.rta / 10;
  389. select_time = crit.rta;
  390. /* this isn't critical, but will most likely not be what the user expects
  391. * so we tell him/her about it, but keep running anyways */
  392. if(warn.pl > crit.pl || warn.rta > crit.rta) {
  393. select_time = warn.rta;
  394. printf("(WARNING threshold > CRITICAL threshold) :: ");
  395. fflush(stdout);
  396. }
  397. /* A timeout smaller than maximum rta threshold makes no sense */
  398. if(timeout < crit.rta) timeout = crit.rta;
  399. else if(timeout < warn.rta) timeout = warn.rta;
  400. if((interval < MIN_INTERVAL * 100 || retry > MAX_RETRY) && getuid()) {
  401. printf("%s: these options are too risky for mere mortals.\n", prog);
  402. printf("%s: You need i >= %u and r < %u\n",
  403. prog, MIN_INTERVAL, MAX_RETRY);
  404. printf("Current settings; i = %d, r = %d\n",
  405. interval / 100, retry);
  406. usage();
  407. }
  408. if((ping_data_size > MAX_PING_DATA) || (ping_data_size < MIN_PING_DATA)) {
  409. printf("%s: data size %u not valid, must be between %u and %u\n",
  410. prog, ping_data_size, MIN_PING_DATA, MAX_PING_DATA);
  411. usage();
  412. }
  413. if((backoff > MAX_BACKOFF_FACTOR) || (backoff < MIN_BACKOFF_FACTOR)) {
  414. printf("%s: backoff factor %.1f not valid, must be between %.1f and %.1f\n",
  415. prog, backoff, MIN_BACKOFF_FACTOR, MAX_BACKOFF_FACTOR);
  416. usage();
  417. }
  418. if(count > MAX_COUNT) {
  419. printf("%s: count %u not valid, must be less than %u\n",
  420. prog, count, MAX_COUNT);
  421. usage();
  422. }
  423. if(count_flag) {
  424. alive_flag = unreachable_flag = 0;
  425. }
  426. trials = (count > retry + 1) ? count : retry + 1;
  427. /* handle host names supplied on command line or in a file */
  428. /* if the generate_flag is on, then generate the IP list */
  429. argv = &argv[optind];
  430. /* cover allowable conditions */
  431. /* generate requires command line parameters beyond the switches */
  432. if(generate_flag && !*argv) {
  433. printf("generate flag requires command line parameters beyond switches\n");
  434. usage();
  435. }
  436. if(*argv && !generate_flag) {
  437. while(*argv) {
  438. if(!(host_ptr->entry = malloc(strlen(*argv) + 1))) {
  439. crash("Failed to allocate memory for hostname");
  440. }
  441. memset(host_ptr->entry, 0, strlen(*argv) + 1);
  442. host_ptr->entry = memcpy(host_ptr->entry, *argv, strlen(*argv));
  443. if(!(host_ptr->next = malloc(sizeof(struct host_name_list))))
  444. crash("Failed to allocate memory for hostname");
  445. host_ptr = host_ptr->next;
  446. host_ptr->next = NULL;
  447. // add_name(*argv);
  448. argv++;
  449. }
  450. }
  451. // now add all the hosts
  452. host_ptr = host_base_ptr;
  453. while(host_ptr->next) {
  454. add_name(host_ptr->entry);
  455. host_ptr = host_ptr->next;
  456. }
  457. if(!num_hosts) {
  458. printf("No hosts to work with!\n\n");
  459. usage();
  460. }
  461. /* allocate array to hold outstanding ping requests */
  462. table = (HOST_ENTRY **) malloc(sizeof(HOST_ENTRY *) * num_hosts);
  463. if(!table) crash("Can't malloc array of hosts");
  464. cursor = rrlist;
  465. for(num_jobs = 0; num_jobs < num_hosts; num_jobs++) {
  466. table[num_jobs] = cursor;
  467. cursor->i = num_jobs;
  468. cursor = cursor->next;
  469. } /* FOR */
  470. ping_pkt_size = ping_data_size + SIZE_ICMP_HDR;
  471. signal(SIGINT, (void *)finish);
  472. gettimeofday(&start_time, &tz);
  473. current_time = start_time;
  474. last_send_time.tv_sec = current_time.tv_sec - 10000;
  475. cursor = rrlist;
  476. advance = 0;
  477. /* main loop */
  478. while(num_jobs) {
  479. /* fetch all packets that receive within time boundaries */
  480. while(num_pingsent &&
  481. cursor &&
  482. cursor->num_sent > cursor->num_recv &&
  483. wait_for_reply(sock)) ;
  484. if(cursor && advance) {
  485. cursor = cursor->next;
  486. }
  487. gettimeofday(&current_time, &tz);
  488. lt = timeval_diff(&current_time, &last_send_time);
  489. ht = timeval_diff(&current_time, &cursor->last_send_time);
  490. advance = 1;
  491. /* if it's OK to send while counting or looping or starting */
  492. if(lt > interval) {
  493. /* send if starting or looping */
  494. if((cursor->num_sent == 0)) {
  495. send_ping(sock, cursor);
  496. continue;
  497. } /* IF */
  498. /* send if counting and count not exceeded */
  499. if(count_flag) {
  500. if(cursor->num_sent < count) {
  501. send_ping(sock, cursor);
  502. continue;
  503. } /* IF */
  504. } /* IF */
  505. } /* IF */
  506. /* is-it-alive mode, and timeout exceeded while waiting for a reply */
  507. /* and we haven't exceeded our retries */
  508. if((lt > interval) && !count_flag && !cursor->num_recv &&
  509. (ht > timeout) && (cursor->waiting < retry + 1)) {
  510. num_timeout++;
  511. /* try again */
  512. send_ping(sock, cursor);
  513. continue;
  514. } /* IF */
  515. /* didn't send, can we remove? */
  516. /* remove if counting and count exceeded */
  517. if(count_flag) {
  518. if((cursor->num_sent >= count)) {
  519. remove_job(cursor);
  520. continue;
  521. } /* IF */
  522. } /* IF */
  523. else {
  524. /* normal mode, and we got one */
  525. if(cursor->num_recv) {
  526. remove_job(cursor);
  527. continue;
  528. } /* IF */
  529. /* normal mode, and timeout exceeded while waiting for a reply */
  530. /* and we've run out of retries, so node is unreachable */
  531. if((ht > timeout) && (cursor->waiting >= retry + 1)) {
  532. num_timeout++;
  533. remove_job(cursor);
  534. continue;
  535. } /* IF */
  536. } /* ELSE */
  537. /* could send to this host, so keep considering it */
  538. if(ht > interval) {
  539. advance = 0;
  540. }
  541. } /* WHILE */
  542. finish();
  543. return 0;
  544. } /* main() */
  545. /************************************************************
  546. * Description:
  547. *
  548. * Main program clean up and exit point
  549. ************************************************************/
  550. void finish()
  551. {
  552. int i;
  553. HOST_ENTRY *h;
  554. gettimeofday(&end_time, &tz);
  555. /* tot up unreachables */
  556. for(i=0; i<num_hosts; i++) {
  557. h = table[i];
  558. if(!h->num_recv) {
  559. num_unreachable++;
  560. status = fin_stat = STATE_CRITICAL;
  561. if(num_hosts == 1) {
  562. printf("CRITICAL - %s is down (lost 100%%)|"
  563. "rta=;%d;%d;; pl=100%%;%d;%d;;\n",
  564. h->host,
  565. warn.rta / 100, crit.rta / 100,
  566. warn.pl, crit.pl);
  567. }
  568. else {
  569. printf("%s is down (lost 100%%)", h->host);
  570. }
  571. }
  572. else {
  573. /* reset the status */
  574. status = STATE_OK;
  575. /* check for warning before critical, for debugging purposes */
  576. if(warn.rta <= h->total_time / h->num_recv) {
  577. /* printf("warn.rta exceeded\n");
  578. */ status = STATE_WARNING;
  579. }
  580. if(warn.pl <= ((h->num_sent - h->num_recv) * 100) / h->num_sent) {
  581. /* printf("warn.pl exceeded (pl=%d)\n",
  582. ((h->num_sent - h->num_recv) * 100) / h->num_sent);
  583. */ status = STATE_WARNING;
  584. }
  585. if(crit.rta <= h->total_time / h->num_recv) {
  586. /* printf("crit.rta exceeded\n");
  587. */ status = STATE_CRITICAL;
  588. }
  589. if(crit.pl <= ((h->num_sent - h->num_recv) * 100) / h->num_sent) {
  590. /* printf("crit.pl exceeded (pl=%d)\n",
  591. ((h->num_sent - h->num_recv) * 100) / h->num_sent);
  592. */ status = STATE_CRITICAL;
  593. }
  594. if(num_hosts == 1 || status != STATE_OK) {
  595. printf("%s - %s: rta %s ms, lost %d%%",
  596. status_string[status], h->host,
  597. sprint_tm(h->total_time / h->num_recv),
  598. h->num_sent > 0 ? ((h->num_sent - h->num_recv) * 100) / h->num_sent : 0
  599. );
  600. /* perfdata only available for single-host stuff */
  601. if(num_hosts == 1) {
  602. printf("|rta=%sms;%d;%d;; pl=%d%%;%d;%d;;\n",
  603. sprint_tm(h->total_time / h->num_recv), warn.rta / 100, crit.rta / 100,
  604. h->num_sent > 0 ? ((h->num_sent - h->num_recv) * 100) / h->num_sent : 0, warn.pl, crit.pl
  605. );
  606. }
  607. else printf(" :: ");
  608. }
  609. /* fin_stat should always hold the WORST state */
  610. if(fin_stat != STATE_CRITICAL && status != STATE_OK) {
  611. fin_stat = status;
  612. }
  613. }
  614. }
  615. if(num_noaddress) {
  616. printf("No hostaddress specified.\n");
  617. usage();
  618. }
  619. else if(num_alive != num_hosts) {
  620. /* for future multi-check support */
  621. /*printf("num_alive != num_hosts (%d : %d)\n", num_alive, num_hosts);*/
  622. fin_stat = STATE_CRITICAL;
  623. }
  624. if(num_hosts > 1) {
  625. if(num_alive == num_hosts) {
  626. printf("OK - All %d hosts are alive\n", num_hosts);
  627. }
  628. else {
  629. printf("CRITICAL - %d of %d hosts are alive\n", num_alive, num_hosts);
  630. }
  631. }
  632. exit(fin_stat);
  633. }
  634. void send_ping(int lsock, HOST_ENTRY *h)
  635. {
  636. char *buffer;
  637. struct icmp *icp;
  638. PING_DATA *pdp;
  639. int n;
  640. buffer = (char *)malloc((size_t) ping_pkt_size);
  641. if(!buffer)
  642. crash("can't malloc ping packet");
  643. memset(buffer, 0, ping_pkt_size * sizeof(char));
  644. icp = (struct icmp *)buffer;
  645. gettimeofday(&h->last_send_time, &tz);
  646. icp->icmp_type = ICMP_ECHO;
  647. icp->icmp_code = 0;
  648. icp->icmp_cksum = 0;
  649. icp->icmp_seq = h->i;
  650. icp->icmp_id = ident;
  651. pdp = (PING_DATA *) (buffer + SIZE_ICMP_HDR);
  652. pdp->ping_ts = h->last_send_time;
  653. pdp->ping_count = h->num_sent;
  654. icp->icmp_cksum = in_cksum((u_short *) icp, ping_pkt_size);
  655. n = sendto(lsock, buffer, ping_pkt_size, 0,
  656. (struct sockaddr *)&h->saddr, sizeof(struct sockaddr_in));
  657. if(n < 0 || (unsigned int)n != ping_pkt_size) {
  658. if(unreachable_flag) {
  659. printf("%s error while sending ping: %s\n",
  660. h->host, strerror(errno));
  661. } /* IF */
  662. num_unreachable++;
  663. remove_job(h);
  664. } /* IF */
  665. else {
  666. /* mark this trial as outstanding */
  667. h->resp_times[h->num_sent] = RESP_WAITING;
  668. h->num_sent++;
  669. h->waiting++;
  670. num_pingsent++;
  671. last_send_time = h->last_send_time;
  672. } /* ELSE */
  673. free(buffer);
  674. } /* send_ping() */
  675. int wait_for_reply(int lsock)
  676. {
  677. int result;
  678. static char buffer[4096];
  679. struct sockaddr_in response_addr;
  680. struct ip *ip;
  681. int hlen;
  682. struct icmp *icp;
  683. int n;
  684. HOST_ENTRY *h = NULL;
  685. long this_reply;
  686. int this_count;
  687. struct timeval sent_time;
  688. result = recvfrom_wto(lsock, buffer, sizeof(buffer),
  689. (struct sockaddr *)&response_addr, select_time);
  690. if(result < 0) return 0; /* timeout */
  691. ip = (struct ip *)buffer;
  692. #if defined( __alpha__ ) && __STDC__ && !defined( __GLIBC__ )
  693. /* The alpha headers are decidedly broken.
  694. * Using an ANSI compiler, it provides ip_vhl instead of ip_hl and
  695. * ip_v. So, to get ip_hl, we mask off the bottom four bits.
  696. */
  697. hlen = (ip->ip_vhl & 0x0F) << 2;
  698. #else
  699. hlen = ip->ip_hl << 2;
  700. #endif /* defined(__alpha__) && __STDC__ */
  701. if(result < hlen + ICMP_MINLEN) {
  702. printf("received packet too short for ICMP (%d bytes from %s)\n", result,
  703. inet_ntoa(response_addr.sin_addr));
  704. return (1); /* too short */
  705. } /* IF */
  706. icp = (struct icmp *)(buffer + hlen);
  707. if(icp->icmp_type != ICMP_ECHOREPLY) {
  708. /* handle some problem */
  709. if(handle_random_icmp(icp, &response_addr))
  710. num_othericmprcvd++;
  711. return 1;
  712. } /* IF */
  713. if(icp->icmp_id != ident)
  714. return 1; /* packet received, but not the one we are looking for! */
  715. num_pingreceived++;
  716. if(icp->icmp_seq >= (n_short) num_hosts)
  717. return(1); /* packet received, don't worry about it anymore */
  718. n = icp->icmp_seq;
  719. h = table[n];
  720. /* received ping is cool, so process it */
  721. gettimeofday(&current_time, &tz);
  722. h->waiting = 0;
  723. h->num_recv++;
  724. memcpy(&sent_time, icp->icmp_data + offsetof(PING_DATA, ping_ts),
  725. sizeof(sent_time));
  726. memcpy(&this_count, icp->icmp_data, sizeof(this_count));
  727. this_reply = timeval_diff(&current_time, &sent_time);
  728. h->total_time += this_reply;
  729. total_replies++;
  730. /* note reply time in array, probably */
  731. if((this_count >= 0) && ((unsigned int)this_count < trials)) {
  732. if(h->resp_times[this_count] != RESP_WAITING) {
  733. printf("%s : duplicate for [%d], %d bytes, %s ms",
  734. h->host, this_count, result, sprint_tm(this_reply));
  735. if(response_addr.sin_addr.s_addr != h->saddr.sin_addr.s_addr)
  736. printf(" [<- %s]\n", inet_ntoa(response_addr.sin_addr));
  737. } /* IF */
  738. else h->resp_times[this_count] = this_reply;
  739. } /* IF */
  740. else {
  741. /* count is out of bounds?? */
  742. printf("%s : duplicate for [%d], %d bytes, %s ms\n",
  743. h->host, this_count, result, sprint_tm(this_reply));
  744. } /* ELSE */
  745. if(h->num_recv == 1) {
  746. num_alive++;
  747. } /* IF */
  748. return num_jobs;
  749. } /* wait_for_reply() */
  750. int handle_random_icmp(struct icmp *p, struct sockaddr_in *addr)
  751. {
  752. struct icmp *sent_icmp;
  753. u_char *c;
  754. HOST_ENTRY *h;
  755. c = (u_char *) p;
  756. switch (p->icmp_type) {
  757. case ICMP_UNREACH:
  758. sent_icmp = (struct icmp *)(c + 28);
  759. if((sent_icmp->icmp_type == ICMP_ECHO) &&
  760. (sent_icmp->icmp_id == ident) &&
  761. (sent_icmp->icmp_seq < (n_short) num_hosts)) {
  762. /* this is a response to a ping we sent */
  763. h = table[sent_icmp->icmp_seq];
  764. if(p->icmp_code > ICMP_UNREACH_MAXTYPE) {
  765. printf("ICMP Unreachable (Invalid Code) from %s for ICMP Echo sent to %s",
  766. inet_ntoa(addr->sin_addr), h->host);
  767. } /* IF */
  768. else {
  769. printf("ICMP Unreachable from %s for ICMP Echo sent to %s",
  770. inet_ntoa(addr->sin_addr), h->host);
  771. } /* ELSE */
  772. if(inet_addr(h->host) == INADDR_NONE)
  773. printf(" (%s)", inet_ntoa(h->saddr.sin_addr));
  774. printf("\n");
  775. } /* IF */
  776. return 1;
  777. case ICMP_SOURCEQUENCH:
  778. case ICMP_REDIRECT:
  779. case ICMP_TIMXCEED:
  780. case ICMP_PARAMPROB:
  781. sent_icmp = (struct icmp *)(c + 28);
  782. if((sent_icmp->icmp_type = ICMP_ECHO) &&
  783. (sent_icmp->icmp_id = ident) &&
  784. (sent_icmp->icmp_seq < (n_short) num_hosts)) {
  785. /* this is a response to a ping we sent */
  786. h = table[sent_icmp->icmp_seq];
  787. printf("ICMP Unreachable from %s for ICMP Echo sent to %s",
  788. inet_ntoa(addr->sin_addr), h->host);
  789. if(inet_addr(h->host) == INADDR_NONE)
  790. printf(" (%s)", inet_ntoa(h->saddr.sin_addr));
  791. printf("\n");
  792. } /* IF */
  793. return 2;
  794. /* no way to tell whether any of these are sent due to our ping */
  795. /* or not (shouldn't be, of course), so just discard */
  796. case ICMP_TSTAMP:
  797. case ICMP_TSTAMPREPLY:
  798. case ICMP_IREQ:
  799. case ICMP_IREQREPLY:
  800. case ICMP_MASKREQ:
  801. case ICMP_MASKREPLY:
  802. default:
  803. return 0;
  804. } /* SWITCH */
  805. } /* handle_random_icmp() */
  806. int in_cksum(u_short * p, int n)
  807. {
  808. register u_short answer;
  809. register long sum = 0;
  810. u_short odd_byte = 0;
  811. while(n > 1) {
  812. sum += *p++;
  813. n -= 2;
  814. } /* WHILE */
  815. /* mop up an odd byte, if necessary */
  816. if(n == 1) {
  817. *(u_char *) (&odd_byte) = *(u_char *) p;
  818. sum += odd_byte;
  819. } /* IF */
  820. sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
  821. sum += (sum >> 16); /* add carry */
  822. answer = ~sum; /* ones-complement, truncate */
  823. return (answer);
  824. } /* in_cksum() */
  825. void add_name(char *name)
  826. {
  827. struct hostent *host_ent;
  828. int ipaddress;
  829. struct in_addr *ipa = (struct in_addr *)&ipaddress;
  830. struct in_addr *host_add;
  831. char *nm;
  832. int i = 0;
  833. if((ipaddress = inet_addr(name)) != -1) {
  834. /* input name is an IP addr, go with it */
  835. if(name_flag) {
  836. if(addr_flag)
  837. add_addr(name, na_cat(get_host_by_address(*ipa), *ipa), *ipa);
  838. else {
  839. nm = cpystr(get_host_by_address(*ipa));
  840. add_addr(name, nm, *ipa);
  841. } /* ELSE */
  842. } /* IF */
  843. else add_addr(name, name, *ipa);
  844. return;
  845. } /* IF */
  846. /* input name is not an IP addr, maybe it's a host name */
  847. host_ent = gethostbyname(name);
  848. if(host_ent == NULL) {
  849. if(h_errno == TRY_AGAIN) {
  850. u_sleep(DNS_TIMEOUT);
  851. host_ent = gethostbyname(name);
  852. } /* IF */
  853. if(host_ent == NULL) {
  854. printf("%s address not found\n", name);
  855. num_noaddress++;
  856. return;
  857. } /* IF */
  858. } /* IF */
  859. host_add = (struct in_addr *)*(host_ent->h_addr_list);
  860. if(host_add == NULL) {
  861. printf("%s has no address data\n", name);
  862. num_noaddress++;
  863. return;
  864. } /* IF */
  865. else {
  866. /* it is indeed a hostname with a real address */
  867. while(host_add) {
  868. if(name_flag && addr_flag)
  869. add_addr(name, na_cat(name, *host_add), *host_add);
  870. else if(addr_flag) {
  871. nm = cpystr(inet_ntoa(*host_add));
  872. add_addr(name, nm, *host_add);
  873. } /* ELSE IF */
  874. else {
  875. add_addr(name, name, *host_add);
  876. }
  877. if(!multif_flag) break;
  878. host_add = (struct in_addr *)(host_ent->h_addr_list[++i]);
  879. } /* WHILE */
  880. } /* ELSE */
  881. } /* add_name() */
  882. char *na_cat(char *name, struct in_addr ipaddr)
  883. {
  884. char *nm, *as;
  885. as = inet_ntoa(ipaddr);
  886. nm = (char *)malloc(strlen(name) + strlen(as) + 4);
  887. if(!nm)
  888. crash("can't allocate some space for a string");
  889. strcpy(nm, name);
  890. strcat(nm, " (");
  891. strcat(nm, as);
  892. strcat(nm, ")");
  893. return (nm);
  894. } /* na_cat() */
  895. void add_addr(char *name, char *host, struct in_addr ipaddr)
  896. {
  897. HOST_ENTRY *p;
  898. unsigned int n;
  899. int *i;
  900. if(!(p = (HOST_ENTRY *) malloc(sizeof(HOST_ENTRY)))) {
  901. crash("can't allocate HOST_ENTRY");
  902. }
  903. memset((char *)p, 0, sizeof(HOST_ENTRY));
  904. p->name = name;
  905. p->host = host;
  906. p->saddr.sin_family = AF_INET;
  907. p->saddr.sin_addr = ipaddr;
  908. p->running = 1;
  909. /* array for response time results */
  910. if(!(i = (int *)malloc(trials * sizeof(int)))) {
  911. crash("can't allocate resp_times array");
  912. }
  913. for(n = 1; n < trials; n++)
  914. i[n] = RESP_UNUSED;
  915. p->resp_times = i;
  916. if(!rrlist) {
  917. rrlist = p;
  918. p->next = p;
  919. p->prev = p;
  920. } /* IF */
  921. else {
  922. p->next = rrlist;
  923. p->prev = rrlist->prev;
  924. p->prev->next = p;
  925. p->next->prev = p;
  926. } /* ELSE */
  927. num_hosts++;
  928. } /* add_addr() */
  929. void remove_job(HOST_ENTRY * h)
  930. {
  931. h->running = 0;
  932. h->waiting = 0;
  933. num_jobs--;
  934. if(num_jobs) {
  935. /* remove us from list of active jobs */
  936. h->prev->next = h->next;
  937. h->next->prev = h->prev;
  938. if(h == cursor) cursor = h->next;
  939. } /* IF */
  940. else {
  941. cursor = NULL;
  942. rrlist = NULL;
  943. } /* ELSE */
  944. } /* remove_job() */
  945. char *get_host_by_address(struct in_addr in)
  946. {
  947. struct hostent *h;
  948. h = gethostbyaddr((char *)&in, sizeof(struct in_addr), AF_INET);
  949. if(h == NULL || h->h_name == NULL)
  950. return inet_ntoa(in);
  951. else
  952. return (char *)h->h_name;
  953. } /* get_host_by_address() */
  954. char *cpystr(char *string)
  955. {
  956. char *dst;
  957. if(string) {
  958. dst = (char *)malloc(1 + strlen(string));
  959. if(!dst) crash("malloc() failed!");
  960. strcpy(dst, string);
  961. return dst;
  962. } /* IF */
  963. else return NULL;
  964. } /* cpystr() */
  965. void crash(char *msg)
  966. {
  967. if(errno || h_errno) {
  968. if(errno)
  969. printf("%s: %s : %s\n", prog, msg, strerror(errno));
  970. if(h_errno)
  971. printf("%s: %s : A network error occurred\n", prog, msg);
  972. }
  973. else printf("%s: %s\n", prog, msg);
  974. exit(STATE_UNKNOWN);
  975. } /* crash() */
  976. long timeval_diff(struct timeval *a, struct timeval *b)
  977. {
  978. double temp;
  979. temp = (((a->tv_sec * 1000000) + a->tv_usec) -
  980. ((b->tv_sec * 1000000) + b->tv_usec)) / 10;
  981. return (long)temp;
  982. } /* timeval_diff() */
  983. char *sprint_tm(int t)
  984. {
  985. static char buf[10];
  986. /* <= 0.99 ms */
  987. if(t < 100) {
  988. sprintf(buf, "0.%02d", t);
  989. return (buf);
  990. } /* IF */
  991. /* 1.00 - 9.99 ms */
  992. if(t < 1000) {
  993. sprintf(buf, "%d.%02d", t / 100, t % 100);
  994. return (buf);
  995. } /* IF */
  996. /* 10.0 - 99.9 ms */
  997. if(t < 10000) {
  998. sprintf(buf, "%d.%d", t / 100, (t % 100) / 10);
  999. return (buf);
  1000. } /* IF */
  1001. /* >= 100 ms */
  1002. sprintf(buf, "%d", t / 100);
  1003. return (buf);
  1004. } /* sprint_tm() */
  1005. /*
  1006. * select() is posix, so we expect it to be around
  1007. */
  1008. void u_sleep(int u_sec)
  1009. {
  1010. int nfound;
  1011. struct timeval to;
  1012. fd_set readset, writeset;
  1013. to.tv_sec = u_sec / 1000000;
  1014. to.tv_usec = u_sec - (to.tv_sec * 1000000);
  1015. /* printf("u_sleep :: to.tv_sec: %d, to_tv_usec: %d\n",
  1016. (int)to.tv_sec, (int)to.tv_usec);
  1017. */
  1018. FD_ZERO(&writeset);
  1019. FD_ZERO(&readset);
  1020. nfound = select(0, &readset, &writeset, NULL, &to);
  1021. if(nfound < 0)
  1022. crash("select() in u_sleep:");
  1023. return;
  1024. } /* u_sleep() */
  1025. /************************************************************
  1026. * Description:
  1027. *
  1028. * receive with timeout
  1029. * returns length of data read or -1 if timeout
  1030. * crash on any other errrors
  1031. ************************************************************/
  1032. /* TODO: add MSG_DONTWAIT to recvfrom flags (currently 0) */
  1033. int recvfrom_wto(int lsock, char *buf, int len, struct sockaddr *saddr, int timo)
  1034. {
  1035. int nfound = 0, slen, n;
  1036. struct timeval to;
  1037. fd_set readset, writeset;
  1038. to.tv_sec = timo / 1000000;
  1039. to.tv_usec = (timo - (to.tv_sec * 1000000)) * 10;
  1040. /* printf("to.tv_sec: %d, to.tv_usec: %d\n", (int)to.tv_sec, (int)to.tv_usec);
  1041. */
  1042. FD_ZERO(&readset);
  1043. FD_ZERO(&writeset);
  1044. FD_SET(lsock, &readset);
  1045. nfound = select(lsock + 1, &readset, &writeset, NULL, &to);
  1046. if(nfound < 0) crash("select() in recvfrom_wto");
  1047. if(nfound == 0) return -1; /* timeout */
  1048. if(nfound) {
  1049. slen = sizeof(struct sockaddr);
  1050. n = recvfrom(sock, buf, len, 0, saddr, &slen);
  1051. if(n < 0) crash("recvfrom");
  1052. return(n);
  1053. }
  1054. return(0); /* 0 bytes read, so return it */
  1055. } /* recvfrom_wto() */
  1056. /*
  1057. * u = micro
  1058. * m = milli
  1059. * s = seconds
  1060. */
  1061. int get_threshold(char *str, threshold *th)
  1062. {
  1063. unsigned int i, factor = 0;
  1064. char *p = NULL;
  1065. if(!str || !strlen(str) || !th) return -1;
  1066. for(i=0; i<strlen(str); i++) {
  1067. /* we happily accept decimal points in round trip time thresholds,
  1068. * but we ignore them quite blandly. The new way of specifying higher
  1069. * precision is to specify 'u' (for microseconds),
  1070. * 'm' (for millisecs - default) or 's' for seconds. */
  1071. if(!p && !factor) {
  1072. if(str[i] == 's') factor = 1000000; /* seconds */
  1073. else if(str[i] == 'm') factor = 1000; /* milliseconds */
  1074. else if(str[i] == 'u') factor = 1; /* microseconds */
  1075. }
  1076. if(str[i] == '%') str[i] = '\0';
  1077. else if(str[i] == ',' && !p && i != (strlen(str) - 1)) {
  1078. p = &str[i+1];
  1079. str[i] = '\0';
  1080. }
  1081. }
  1082. /* default to milliseconds */
  1083. if(!factor) factor = 1000;
  1084. if(!p || !strlen(p)) return -1;
  1085. th->rta = (unsigned int)strtoul(str, NULL, 0) * factor;
  1086. th->pl = (unsigned int)strtoul(p, NULL, 0);
  1087. return 0;
  1088. }
  1089. /* make a blahblah */
  1090. void usage(void)
  1091. {
  1092. printf("\nUsage: %s [options] [targets]\n", prog);
  1093. printf(" -H host target host\n");
  1094. printf(" -b n ping packet size in bytes (default %d)\n", ping_data_size);
  1095. printf(" -n|p n number of pings to send to each target (default %d)\n", count);
  1096. printf(" -r n number of retries (default %d)\n", retry);
  1097. printf(" -t n timeout value (in msec) (default %d)\n", timeout / 100);
  1098. printf(" -i n packet interval (in msec) (default %d)\n", DEFAULT_INTERVAL);
  1099. /* XXX - possibly on todo-list
  1100. printf(" -m ping multiple interfaces on target host\n");
  1101. printf(" -a show targets that are alive\n");
  1102. printf(" -d show dead targets\n");
  1103. */ printf(" -v show version\n");
  1104. printf(" -D increase debug output level\n");
  1105. printf(" -w warning threshold pair, given as RTA[ums],PL[%%]\n");
  1106. printf(" -c critical threshold pair, given as RTA[ums],PL[%%]\n");
  1107. printf("\n");
  1108. printf("Note:\n");
  1109. printf("* This program requires root privileges to run properly.\n");
  1110. printf(" If it is run as setuid root it will halt with an error if;\n");
  1111. printf(" interval < 25 || retries > 5\n\n");
  1112. printf("* Threshold pairs are given as such;\n");
  1113. printf(" 100,40%%\n");
  1114. printf(" to set a threshold value pair of 100 milliseconds and 40%% packetloss\n");
  1115. printf(" The '%%' sign is optional, and if rta value is suffixed by;\n");
  1116. printf(" s, rta time is set in seconds\n");
  1117. printf(" m, rta time will be set in milliseconds (this is default)\n");
  1118. printf(" u, rta time will be set in microseconds\n");
  1119. printf(" Decimal points are silently ignored for sideways compatibility.\n");
  1120. printf("\n");
  1121. exit(3);
  1122. } /* usage() */