- unsigned int sentpackets ;
- unsigned int recvdpackets;
-
- /* linked list */
- struct monitor_host *next;
-} monitor_host_t;
-
-/* protos */
-static void logopen(void);
-static void logclose(void);
-static void log(int type, char *format, ...);
-static int gethostaddr(const char *name);
-static void read_hosts(const char *cfg_file_name);
-static void init_hosts(void);
-static void get_response(void);
-static void pinger(int);
-static int in_cksum(u_short *addr, int len);
-static void read_icmp_data(monitor_host_t *p);
-static void tvsub(struct timeval *out, struct timeval *in);
-static void done(int code);
-static void start_daemon(void);
-static int gcd(int x, int y);
-
-/* globals */
-
-static monitor_host_t **hosts = nil;
-static int isDaemon = 0;
-static int isVerbose = 0;
-static int keepBanging = 0;
-static unsigned short ident;
-static int send_delay = 1;
-
-int main(int ac, char **av)
-{
- extern char* optarg;
- extern int optind;
- char *cfgfile=nil;
- int param;
-
- logopen();
- log(LOG_INFO, VERSION " is starting.");
-
- while((param = getopt(ac, av, "rvdf:")) != -1)
- switch(param)
- {
- case 'v':
- isVerbose = 1;
- break;
- case 'd':
- isDaemon = 1;
- break;
- case 'r':
- keepBanging = 1;
- break;
- case 'f':
- cfgfile=strdup(optarg);
- break;
- default:
- fprintf(stderr,"Usage: icmpmonitor [-d] [-v] [-r] [-f cfgfile]\n");
- done(RET_BAD_OPT);
- }
-
- if(!cfgfile)
- {
- log(LOG_WARNING,"No cfg file specified. Assuming 'icmpmonitor.cfg'");
- cfgfile="icmpmonitor.cfg";
- }
-
- read_hosts(cfgfile); /* we do this before becoming daemon,
- to be able process relative path */
-
- if(isDaemon)
- start_daemon();
-
- init_hosts();
-
- ident=getpid() & 0xFFFF;
-
- (void)signal(SIGALRM, pinger);
- alarm(send_delay);
-
- get_response();
-
- done(RET_OK);
-}