check_icmp.c 35 KB

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