/* setclock.c Provides a clock setting for NCSA 2.3. Reference: RFC 868 By James Nau, College of Engineering, University of Nebraska--Lincoln */ #define TIME_PORT 37 #define REALTIME #include #include #include #include #include #include #include #include #ifdef __TURBOC__ #include "turboc.h" #endif #ifdef MEMORY_DEBUG #include "memdebug.h" #endif #include "netevent.h" #include "hostform.h" #include "whatami.h" #include "externs.h" #include "netutils.h" #include "version.h" int debug = 0; /* enable with -D option */ int ftpok=0,twperm=0; /* Unresolved useless (here anyway) externals */ unsigned char path_name[_MAX_DRIVE+_MAX_DIR], /* character storage for the path name */ temp_str[20],buf[_MAX_DIR],temp_data[30]; /* Function Prototypes */ int main(int argc, char *argv[]); #ifndef __TURBOC__ static void randomize(void ); #endif void usage(void); void setclock(char *host); /* setclock [-h filename] hostname -h filename is alternative CONFIG.TEL file hostname the NAME (or Number?) of the host to use for time */ int main(int argc, char *argv[]) { int i; int switchcount=1; /* how many args are present */ int gothost=0; /* if 1, we've found the host */ char *ptr=0; /* pointer to CONFIG.TEL file */ char remote_host[256]; /* address of remote host */ #ifdef __TURBOC__ fnsplit(argv[0],path_name,buf,temp_str,temp_data); /* split path up */ #else _splitpath(argv[0],path_name,buf,temp_str,temp_data); /* split path up */ #endif strcat(path_name,buf); /* append the path name */ strcat(path_name,temp_str); /* append filename */ /* get the command line arguments */ for (i=1; itm_mday); dosdate->day = (unsigned char)(ltime->tm_mday); (ltime->tm_mon)++; /* localtime range 0-11, but _dos_settime range 1-12 */ dosdate->month = (unsigned char)(ltime->tm_mon); dosdate->year = (unsigned int)ltime->tm_year + 1900; (ltime->tm_wday); dosdate->dayofweek = (unsigned char)(ltime->tm_wday); dostime->hour = (unsigned char)ltime->tm_hour; dostime->minute = (unsigned char)ltime->tm_min; dostime->second = (unsigned char)ltime->tm_sec; dostime->hsecond = 0; if (tz != NULL || yn[0] == 'y' || yn[0] =='Y') { if (_dos_setdate(dosdate)) { printf("Error setting date\n"); printf("day : %d\n", dosdate->day); printf("month: %d\n", dosdate->month); printf("year : %d\n", dosdate->year); printf("dayow: %d\n", dosdate->dayofweek); } if (_dos_settime(dostime)) { printf("Error setting time\n"); printf("hour : %d\n",dostime->hour); printf("minute: %d\n",dostime->minute); printf("second: %d\n",dostime->second); } #ifdef OLD_WAY /* rmg 931100 */ printf("Time set to %s", asctime(ltime)); #else time(&diff); #endif printf("Time set to %s", ctime(&diff)); } else { /* answered 'n' to time zone question */ printf("\nTime was not set. You must enter the environment variable TZ\n"); printf("in your environment. This should be a a three-letter time zone\n"); printf("code (such as CMT for Central/Mountain), followed by an optionally\n"); printf("signed number giving the difference (in hours) between local time\n"); printf("and Greenwich Mean Time. (6 for Central/Mountain) This is followed\n"); printf("by a three-letter Daylight Savings Time Zone, such as CDT.\n"); }; if (debug) printf("Closing Connection\n"); netclose(conn_id); } #ifdef MSC #ifndef __TURBOC__ /****************************************************************** * * randomize() * * replicates the randomize function of Turbo C * MSC 5.1 does not contain it so we have to write it ourselves. * */ static void randomize(void ) { srand((unsigned)time(NULL)); } #endif #endif void usage() { printf("%s\n",SCLK_VERSION); printf("Usage: %s [-h filename] hostname\n\n", path_name); printf(" -h filename is alternative CONFIG.TEL file\n"); printf(" hostname the NAME of the host to sync clock to\n"); printf(" Depends on environmental variable TZ.\n"); printf(" Example: set TZ=CST6CDT\n"); exit (-1); } #ifdef __TURBOC__ int _dos_setdate(struct dosdate_t *ddate) { struct date datep; datep.da_year = ddate->year; datep.da_mon = ddate->month; datep.da_day = ddate->day; setdate(&datep); return(0); } int _dos_settime(struct dostime_t *dtime) { struct time timep; timep.ti_hour = dtime->hour; timep.ti_min = dtime->minute; timep.ti_sec = dtime->second; timep.ti_hund = dtime->hsecond; settime(&timep); return(0); } #endif