#include "drwebdc-demo.h"

/*--------------------------------------------------------------------------
 Dr. Web daemon client demo (show loaded virus bases information)
                                       ID Antivirus Lab http://www.drweb.ru  
                                             http://www.drweb.ru/unix/forum
                                                   http://www.drweb.ru/unix
--------------------------------------------------------------------------*/
static int
showBases( void )
{
   if( createSocket() < 0 )
   {
       return DRWEBD_SOCKET_ERR;
   }

   if( writeInt( DRWEBD_BASEINFO_CMD ) )
   {
       int bnum = 0;
       if( !readOutput( sizeof(bnum), &bnum ) )
       {
           int i;
	   bnum = ntohl( bnum );
           for( i = 0; i < bnum; i++ )
           {
                int nlen = 0;
                if( !readOutput( sizeof(nlen), &nlen ) )
                {
                    char bfile[ 1024 ];
	            nlen = ntohl( nlen );
                    if( !readOutput( nlen > sizeof(bfile) ? sizeof(bfile) : nlen, bfile ) )
                    {
                        int vir = 0;
                        if( !readOutput( sizeof(vir), &vir ) )
                        {
                            printf( "\nVirus base: %s (%u records)", bfile, ntohl(vir) );
                        }
                    }
                }
           }
       }
   }

   return 0;
}

//--------------------------------------------------------------------------
int
main( int argc, char ** argv )
{
   int retcode = 0;

   retcode = showBases();

   cleanup();

   return retcode;
}

//--------------------------------------------------------------------------

