home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUPC / TEST / UPC12ES1.ZIP / LIB / hostrset.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-11  |  6.0 KB  |  149 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    h o s t r s e t . c                                             */
  3. /*                                                                    */
  4. /*    Clear host status information for UUPC/extended                 */
  5. /*                                                                    */
  6. /*    Copyright (c) 1992, Mitch Mitchell                              */
  7. /*--------------------------------------------------------------------*/
  8.  
  9. /*--------------------------------------------------------------------*/
  10. /*    Changes Copyright (c) 1990-1993 by Kendra Electronic            */
  11. /*    Wonderworks.                                                    */
  12. /*                                                                    */
  13. /*    All rights reserved except those explicitly granted by the      */
  14. /*    UUPC/extended license agreement.                                */
  15. /*--------------------------------------------------------------------*/
  16.  
  17. /*--------------------------------------------------------------------*/
  18. /*                          RCS Information                           */
  19. /*--------------------------------------------------------------------*/
  20.  
  21. /*
  22.  *    $Id: hostrset.c 1.5 1993/10/12 00:47:57 ahd Exp $
  23.  *
  24.  *    Revision history:
  25.  *    $Log: hostrset.c $
  26.  *     Revision 1.5  1993/10/12  00:47:57  ahd
  27.  *     Normalize comments
  28.  *
  29.  *     Revision 1.4  1993/10/09  15:47:51  rhg
  30.  *     ANSIify the source
  31.  *
  32.  *     Revision 1.3  1993/05/03  02:41:57  ahd
  33.  *     Use correct directory for new status file
  34.  *
  35.  */
  36.  
  37. /*--------------------------------------------------------------------*/
  38. /*                        System include files                        */
  39. /*--------------------------------------------------------------------*/
  40.  
  41. #include <stdio.h>
  42. #include <string.h>
  43. #include <time.h>
  44.  
  45. /*--------------------------------------------------------------------*/
  46. /*                    UUPC/extended include files                     */
  47. /*--------------------------------------------------------------------*/
  48.  
  49. #include "lib.h"
  50. #include "hlib.h"
  51. #include "hostable.h"
  52. #include "hostatus.h"
  53. #include "hostrset.h"
  54. #include "security.h"
  55. #include "timestmp.h"
  56.  
  57. /*--------------------------------------------------------------------*/
  58. /*        Define current file name for panic() and printerr()         */
  59. /*--------------------------------------------------------------------*/
  60.  
  61. currentfile();
  62.  
  63. /*--------------------------------------------------------------------*/
  64. /*       H o s t R e s e t                                            */
  65. /*                                                                    */
  66. /*       Reset status information for one or more hosts               */
  67. /*--------------------------------------------------------------------*/
  68.  
  69. void HostReset( const char *name )
  70. {
  71.    boolean firsthost = TRUE;
  72.    struct HostTable *host;
  73.    char fname[FILENAME_MAX];
  74.    FILE *stream;
  75.    unsigned short len1 = (unsigned short) strlen(compilep );
  76.    unsigned short len2 = (unsigned short) strlen(compilev );
  77.  
  78. /*--------------------------------------------------------------------*/
  79. /*         Get the file name for the status file and open it          */
  80. /*--------------------------------------------------------------------*/
  81.  
  82.    mkfilename( fname, E_confdir, DCSTATUS );
  83.  
  84.    if ((stream  = FOPEN(fname , "w", BINARY_MODE)) == NULL)
  85.    {
  86.       printmsg(1,"HostReset: Unable to open host status file");
  87.       printerr( fname );
  88.       panic();                /* Critical error if unable to write    */
  89.       return;
  90.    } /* if */
  91.  
  92. /*--------------------------------------------------------------------*/
  93. /*                 Write header information for file                  */
  94. /*--------------------------------------------------------------------*/
  95.  
  96.    fwrite( &len1, sizeof len1, 1, stream );
  97.    fwrite( &len2, sizeof len2, 1, stream );
  98.    fwrite( compilep , 1, len1, stream);
  99.    fwrite( compilev , 1, len2, stream);
  100.    fwrite( &start_stats , sizeof start_stats , 1,  stream);
  101.  
  102. /*--------------------------------------------------------------------*/
  103. /*     Now spin through the hosts and write out their information     */
  104. /*--------------------------------------------------------------------*/
  105.  
  106.    while  ((host = nexthost( firsthost )) != BADHOST)
  107.    {
  108.       len1 = (unsigned short) strlen( host->hostname );
  109.       len2 = sizeof *(host->hstats);
  110.  
  111.       firsthost = FALSE;
  112.  
  113.       fwrite( &len1, sizeof len1, 1, stream );
  114.       fwrite( &len2, sizeof len2, 1, stream );
  115.       fwrite( host->hostname , sizeof host->hostname[0], len1, stream);
  116.  
  117. /*--------------------------------------------------------------------*/
  118. /*                    Clear this host if requested                    */
  119. /*--------------------------------------------------------------------*/
  120.  
  121.       if ( (name == NULL) || equal(name,host->hostname) )
  122.       {
  123.           host->hstats->calls     = 0l;  /* Total number of calls to host */
  124.           host->hstats->connect   = 0l;  /* Total length of connections to host */
  125.           host->hstats->fsent     = 0l;  /* Total files sent to this host */
  126.           host->hstats->freceived = 0l;  /* Total files received from this host */
  127.           host->hstats->bsent     = 0l;  /* Total bytes sent to this host */
  128.           host->hstats->breceived = 0l;  /* Total bytes received from this host */
  129.           host->hstats->errors    = 0l;  /* Total transmission errors noted */
  130.           host->hstats->packets   = 0l;  /* Total packets exchanged   */
  131.       }
  132.  
  133.       host->hstats->save_hstatus = host->hstatus;
  134.       fwrite( host->hstats , len2, 1,  stream);
  135.    }
  136.  
  137. /*--------------------------------------------------------------------*/
  138. /*         Make we sure got end of file and not an I/O error          */
  139. /*--------------------------------------------------------------------*/
  140.  
  141.    if (ferror( stream ))
  142.    {
  143.       printerr( fname );
  144.       clearerr( stream );
  145.    }
  146.    fclose( stream );
  147.  
  148. } /* HostReset */
  149.