home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / ASKTIME.ZIP / UASKTIME.C < prev   
Text File  |  1989-11-07  |  2KB  |  87 lines

  1. /**-----------------------------------------------------------**
  2. *                                *
  3. *        Bill Nolde 10-89                *
  4. **------------------------------------------------------------**/
  5. #include    "NETCONS.H"
  6. #include    "DOSCALLS.H"
  7. #include    "REMUTIL.H"
  8. #include    "TIME.H"
  9.  
  10. #ifdef _DOS_
  11. #include "dos.h"
  12. #endif
  13.  
  14. /**------------------------------------------------------**/
  15. main( int argc , char *argv[] )
  16. {
  17. unsigned short    retcode , phandle , bytesread ;
  18. char     servername[22]  ;
  19. struct time_of_day_info ti;
  20. struct DateTime     dt;
  21.  
  22.  
  23.     if ( argc < 2 ) { 
  24.         printf ( "\nTime Server Name Must be Specified\n" );  
  25.         exit (1);
  26.     }
  27.     if ( argv[1][0] != '\\' ) {
  28.         strcpy ( servername , "\\\\" );
  29.         strcat ( servername , argv[1] );
  30.     }
  31.     else    strcpy ( servername , argv[1] );
  32.  
  33.     strupr ( servername );
  34.  
  35.     printf ( "\nCalling %s\n" , servername );
  36.  
  37.     retcode = NetRemoteTOD ( servername , ( char *) &ti , 
  38.             sizeof ( struct time_of_day_info ) );
  39.  
  40.     if ( retcode == 0 ) {
  41.         dt.hour    = ti.tod_hours;
  42.         dt.minutes = ti.tod_mins;
  43.         dt.seconds = ti.tod_secs;
  44.         dt.day       = ti.tod_day;
  45.         dt.month   = ti.tod_month;
  46.         dt.year    = ti.tod_year;
  47.         retcode = DoSetTime ( &dt );
  48.         if ( retcode == 0 ) printf ( "\nTime Set\n" );
  49.         else printf ( "\nTime And Date Not Set , error %d\n" ,retcode);
  50.     }
  51.     else printf ( "\nError %d Trying to get the Time from %s\n",
  52.             retcode , servername );
  53. }
  54. /**---------------------------------------------------------**/
  55. DoSetTime (  struct DateTime *dt )
  56. {
  57. int    retcode;
  58. #ifdef _OS2_
  59.     return ( DOSSETDATETIME (  dt ) );
  60. #endif
  61.  
  62. #ifdef _DOS_
  63. union REGS inregs , outregs ;
  64.  
  65.  
  66.     inregs.h.ah = 0x2d;        /* Set Time */
  67.     inregs.h.ch = dt->hour;
  68.     inregs.h.cl = dt->minutes ;
  69.     inregs.h.dh = dt->seconds ;
  70.     inregs.h.dl = 0 ;
  71.  
  72.     int86 ( 0x21 , &inregs , &outregs );
  73.     if ( outregs.h.al ) return ( 1 );
  74.     
  75.     inregs.h.ah = 0x2b;        /* Set Date */
  76.     inregs.x.cx = dt->year ;
  77.     inregs.h.dh = dt->month ;
  78.     inregs.h.dl = dt->day ;
  79.     int86 ( 0x21 , &inregs , &outregs );
  80.     if ( outregs.h.al )     return ( retcode );
  81.     
  82.     return ( 0 );
  83. #endif
  84. }
  85. /**---------------------------------------------------------**/
  86.  
  87.