/* * $Revision: 1.3 $ */ /*+ radiusmon * RADIUS monitor for NOCOL. * * Method : * Create a radius packet and send to server. * * Originally posted by Claranet Ltd., UK rewritten to avoid copyright * issues. Some portions of the code from the Livingston public domain * software. * * Copyright 1998 Netplex Technologies Inc., info@netplex-tech.com * */ /* * $Log: main.c,v $ * Revision 1.3 1999/11/15 06:42:40 vikas * Print's up/down in debug mode depending on 'status'- sent by * milton@isomedia.com * * Revision 1.2 1999/10/19 03:49:11 vikas * *** empty log message *** * * Revision 1.1 1998/07/31 18:54:08 vikas * Initial revision * * */ #include #include #include "nocol.h" #include "radiusmon.h" char *prognm; static char *configfile, *datafile, *sender; /* We keep a linked list of all the sites that we poll and store the * various thresholds in this linked list. */ struct site_info *site_info_list = NULL; void free_site_list(); static char *Strdup(); /* replacement for strdup() */ static time_t pollinterval ; /* Time between polls */ int debug = 0; int main(argc, argv) int argc; char **argv; { int fdout = 0; time_t starttm, polltime ; extern char *optarg; extern int optind; register int c ; prognm = argv[0]; #ifdef SENDER sender = SENDER ; #else /* delete the directory name */ if ((sender = (char *)strrchr (prognm , '/')) == NULL) sender = prognm ; /* no path in program name */ else sender++ ; /* skip leading '/' */ #endif while ((c = getopt(argc, argv, "do:")) != EOF) switch (c) { case 'd': debug++ ; break ; case 'o': /* output datafile */ datafile = (char *)Strdup(optarg); break ; case '?': default: help() ; goto Cleanup ; } switch (argc - optind) { case 0: /* default input file */ break ; case 1: configfile = (char *)Strdup(argv[optind]); break ; default: fprintf (stderr, "%s Error: Too many 'hosts' files\n\n", prognm); help() ; goto Cleanup; } nocol_startup(&configfile, &datafile); if (fdout != 0) /* Say, recovering from longjmp */ close(fdout); if ( (fdout = open(datafile, O_RDWR|O_CREAT|O_TRUNC, DATAFILE_MODE)) < 0) { fprintf(stderr, "(%s) ERROR in open datafile ", prognm); perror (datafile); goto Cleanup ; } openeventlog() ; /* Event logging */ if (init_sites(fdout, configfile) == -1 ) goto Cleanup ; if (!pollinterval) pollinterval = POLLINTERVAL ; /* default value */ /* poll_sites makes one complete pass over the list of nodes */ while (1) /* forever */ { starttm = time((time_t *)NULL) ; /* time started this cycle */ if (poll_sites(fdout) == -1) /* Polling error */ break ; if ( (polltime = time((time_t *)NULL) - starttm) < pollinterval) { if(debug) fprintf(stderr, "(debug)%s: Sleeping for %u seconds.ZZZ...\n", prognm, (unsigned)(pollinterval - polltime)); sleep ((unsigned)(pollinterval - polltime)); } } /* HERE ONLY IF ERROR */ Cleanup: nocol_done(); } /* end main() */ /* * Read the config file.Returns 1 on success, 0 on error. * Do other initializtions. * Format : * POLLINTERVAL