10 int main(int argc,char **argv);
13 static int bytes_received=0;
14 static char title[100];
17 static void usage(s) char *s;{
18 printf("usage: %s host\n",s);
23 static int host_time( host )
28 int sock = sock_open( SOCK_STREAM, "tcp", host, "time", 0, AS_CLIENT );
30 size=sock_cli_recv(sock,&time,sizeof(int));
33 if( size == sizeof(int) ) return ntohl(time);
38 int main(argc,argv) int argc; char** argv; {
42 if( argc != 2 ) usage(argv[0]);
51 struct timeval delta,olddelta;
52 struct timeval time_before,time_after;
58 if( gettimeofday(&time_before,NULL) ){
59 perror("gettimeofday:");
60 if( uid!=0 ) return 1;
64 local = host_time( "localhost" );
65 remote= host_time( host );
67 if( gettimeofday(&time_after ,NULL) ){
68 perror("gettimeofday:");
69 if( uid!=0 ) return 1;
73 diff = (time_after.tv_sec - time_before.tv_sec)*1000;
74 diff -= time_before.tv_usec/1000;
75 diff += time_after .tv_usec/1000;
76 if( diff >=0 && diff < 300 ) break;
81 printf("transaction too long ( %dms ) or errors in time\n",diff);
89 printf("error in connect to %s\n",host);
92 if( uid!=0 ) return 1;
96 printf("error in connect to %s\n","localhost");
99 if( uid!=0 ) return 1;
103 delta.tv_sec=remote-local;
106 if( delta.tv_sec!=0 ){
107 if( delta.tv_sec > 1 ) delta.tv_sec = 1;
109 if( delta.tv_sec < -1 ) delta.tv_sec = -1;
111 if( delta.tv_sec == 1 ) delta.tv_usec = 500000;
112 else delta.tv_usec = -500000;
116 if( adjtime(&delta,&olddelta)<0 ) perror("adjtime error:");
120 extern char *ctime();
121 extern time_t time();
124 if( c[strlen(c)-1]=='\n' ) c[strlen(c)-1]='\0';
126 printf("at %s(%dms) time on %s is %u s forward\n",
127 c,diff,host,remote-local);
129 printf("at %s(%dms) time on %s is %u s late\n",
130 c,diff,host,local-remote);
131 if( uid != 0 && remote == local )
132 printf("at %s(%dms) time on %s is equal\n",c,diff,host);
138 if( uid!=0 ) return 0;