# /* netdate.c */ /* EMACS_MODES: c !fill */ /* Query the udp timeservers for the current time */ #include struct { char name[8]; char tty; char fill1; int wtime[2]; int fill2; } wtmp[2]; main (argc, argv) int argc; char **argv; { time_t now, udptime (); int wf; if (argc > 2 || (argc == 2 && strcmp (argv[1], "-s") != 0)) { printf ("usage: %s [-s]\n", argv[0]); exit (1); } if ((now = udptime ()) == 0L) { printf ("Unable to get the time\n"); exit (1); } printf ("The time is %s", ctime (&now)); if (argc == 2) { time(wtmp[0].wtime); wtmp[0].tty = '|'; if (stime(&now) != 0) { printf ("\007Couldn't set the time. SET IT MANUALLY!\n"); exit (1); } else { if ((wf = open("/adm/wtmp", 1)) >= 0) { time(wtmp[1].wtime); wtmp[1].tty = '}'; seek(wf, 0, 2); write(wf, wtmp, 32); close(wf); } } } }